Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit 8971c76

Browse files
committed
Use my ST oauth token for all automated requests
1 parent 0ddcb64 commit 8971c76

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

application.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ def auth_redirect_uri():
5151
return redirect(request.url_root) # go back home after successful auth
5252

5353

54-
# Using auth token boosts request limit to 400
55-
@app.before_request
56-
def check_session():
57-
if '/auth_redirect_uri/' != request.path:
58-
if 'user_id' not in session or 'access_token' not in session:
59-
auth_code_url = authwrapper.get_auth_code_url(request.url_root)
60-
return redirect(auth_code_url)
61-
62-
return None
54+
# i've hardcoded my token for all automated requests. comment this out while developing on localhost.
55+
# TODO: break this out for visitors to the site and automated requests
56+
# @app.before_request
57+
# def check_session():
58+
# if '/auth_redirect_uri/' != request.path:
59+
# if 'user_id' not in session or 'access_token' not in session:
60+
# auth_code_url = authwrapper.get_auth_code_url(request.url_root)
61+
# return redirect(auth_code_url)
62+
#
63+
# return None
6364

6465

6566
@app.errorhandler(404)

stocktwits_wrapper.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime
33
import html
44
import logging
5+
import os
56
import re
67
import time
78

@@ -17,6 +18,8 @@ class StockTwitsWrapper:
1718

1819
mysql_conn = MysqlWrapper.get_connection()
1920

21+
oauth_token = os.environ.get('ST_OAUTH_TOKEN')
22+
2023
bot_blacklist = [727510]
2124

2225
@classmethod
@@ -55,9 +58,13 @@ def get_ticker(self, ticker):
5558
get_ticker_url = 'https://api.stocktwits.com/api/2/streams/symbol/'
5659
url_postfix = '.json?'
5760
pagination_since = self.__get_last_message(ticker)
61+
# TODO: use visitors token for watchlist, etc.
5862
# only time we don't have access_token is on localhost so kind of an unnecessary check
59-
if 'access_token' in session:
60-
url_postfix = '%s&access_token=%s' % (url_postfix, session['access_token'])
63+
# if 'access_token' in session:
64+
# url_postfix = '%s&access_token=%s' % (url_postfix, session['access_token'])
65+
66+
# use my token for all automated calls
67+
url_postfix = '%s&access_token=%s' % (url_postfix, self.oauth_token)
6168

6269
# TODO: only messages 'since' show up.
6370
# TODO: store last 30 messages in DB or always fetch last 30 and do fake pagination here?

0 commit comments

Comments
 (0)