-
-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker revamp #19
base: master
Are you sure you want to change the base?
Docker revamp #19
Changes from 1 commit
b292b6d
4aef0a3
8ee20b8
9dca234
74e6b36
53408c9
d5393e7
4dc0238
b7cda28
a8bf22a
aea6a59
64ddc35
004c17c
3cd6de0
fde9181
92a9447
4205c8c
ff5a8cf
e310886
10502c8
7675154
c2a7010
cb42d10
fd9fe56
3a3b452
f3c1895
e6c9f1b
3fc49a6
e86efe7
5f1d87f
3e862ec
84c6324
4cd6af4
622eae1
baa9d5f
040887b
56901dc
abbc740
a6002ac
c6cf17b
bda22a4
b7226d4
5cde9c9
c3431c4
d086bc6
f84a379
60e06fc
0d7c7a4
fb6bea1
097c774
efc7387
175dd61
a178733
9c55d3d
6f38025
5d17a6c
646b0d9
b985410
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ tweepy | |
beautifulsoup4 | ||
textblob | ||
vaderSentiment | ||
pytz |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,15 +200,18 @@ def on_timeout(self): | |
|
||
|
||
class NewsHeadlineListener: | ||
def __init__(self, url=None, frequency=3600): | ||
def __init__(self, url=None, frequency=sentiment_frequency): | ||
self.url = url | ||
self.headlines = [] | ||
self.followedlinks = [] | ||
self.frequency = frequency | ||
self.max_cache = 1000; | ||
|
||
while True: | ||
new_headlines = self.get_news_headlines(self.url) | ||
|
||
self.cleanup() | ||
|
||
# add any new headlines | ||
for htext, htext_url in new_headlines: | ||
if htext not in self.headlines: | ||
|
@@ -265,6 +268,21 @@ def __init__(self, url=None, frequency=3600): | |
|
||
logger.info("Will get news headlines again in %s sec..." % self.frequency) | ||
time.sleep(self.frequency) | ||
def cleanup(self): | ||
new_headline = [] | ||
new_followlink = [] | ||
if len(self.headlines) > self.max_cache: | ||
for i in range(self.max_cache / 2, len(self.headlines) - 1): | ||
new_headline.append(self.headlines[i]) | ||
|
||
self.headlines = new_headline | ||
|
||
if len(self.followedlinks) > self.max_cache: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the loop be replaced with a array slice like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is not applicable in the latest commit. |
||
for i in range(self.max_cache / 2, len(self.followedlinks) - 1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also looks like this can be replaced with an array slice. Consider using descriptive variable for lower bound. |
||
new_followlink.append(self.followedlinks[i]) | ||
|
||
self.followedlinks = new_followlink | ||
|
||
|
||
def get_news_headlines(self, url): | ||
|
||
|
@@ -494,8 +512,8 @@ def get_twitter_users_from_file(file): | |
help="Use twitter user ids from file") | ||
parser.add_argument("-n", "--newsheadlines", metavar="SYMBOL", | ||
help="Get news headlines instead of Twitter using stock symbol, example: TSLA") | ||
parser.add_argument("--frequency", metavar="FREQUENCY", default=3600, type=int, | ||
help="How often in seconds to retrieve news headlines (default: 3600 sec)") | ||
parser.add_argument("--frequency", metavar="FREQUENCY", default=sentiment_frequency, type=int, | ||
help="How often in seconds to retrieve news headlines (default: %d sec)" % sentiment_frequency) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using f string instead of old school variable replacement, like so: f"How often in seconds to retrieve news headlines (default: {sentiment_frequency} sec)" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is no longer applicable in the latest commit. |
||
parser.add_argument("--followlinks", action="store_true", | ||
help="Follow links on news headlines and scrape relevant text from landing page") | ||
parser.add_argument("-v", "--verbose", action="store_true", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
import logging | ||
import sys | ||
import time | ||
|
||
import datetime | ||
import re | ||
import requests | ||
from pytz import timezone | ||
|
||
try: | ||
from elasticsearch5 import Elasticsearch | ||
|
@@ -24,7 +26,8 @@ | |
from random import randint | ||
|
||
# import elasticsearch host | ||
from config import elasticsearch_host, elasticsearch_port, elasticsearch_user, elasticsearch_password | ||
from config import elasticsearch_host, elasticsearch_port, elasticsearch_user, elasticsearch_password, \ | ||
price_frequency, weekday_start, weekday_end, hour_start, hour_end, timezone_str | ||
|
||
|
||
STOCKSIGHT_VERSION = '0.1-b.5' | ||
|
@@ -37,19 +40,31 @@ | |
es = Elasticsearch(hosts=[{'host': elasticsearch_host, 'port': elasticsearch_port}], | ||
http_auth=(elasticsearch_user, elasticsearch_password)) | ||
|
||
regex = re | ||
|
||
class GetStock: | ||
|
||
def get_price(self, url, symbol): | ||
import re | ||
|
||
eastern_timezone = timezone(timezone_str) | ||
|
||
while True: | ||
|
||
if self.isNotLive(eastern_timezone): | ||
#logger.info("Stock market is not live. Current time: %s" % datetime.datetime.now(timezone).strftime("%Y-%m-%d %H:%M")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's from an outdated commit. |
||
today = datetime.datetime.now(eastern_timezone) | ||
logger.info("Stock market is not live. Current time: %s" % today.strftime('%H')) | ||
logger.info("Will get stock data again in %s sec..." % args.frequency) | ||
time.sleep(args.frequency) | ||
continue | ||
|
||
|
||
logger.info("Grabbing stock data for symbol %s..." % symbol) | ||
|
||
try: | ||
|
||
# add stock symbol to url | ||
url = re.sub("SYMBOL", symbol, url) | ||
url = regex.sub("SYMBOL", symbol, url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice touch, improves readability. |
||
# get stock data (json) from url | ||
try: | ||
r = requests.get(url) | ||
|
@@ -113,6 +128,17 @@ def get_price(self, url, symbol): | |
logger.info("Will get stock data again in %s sec..." % args.frequency) | ||
time.sleep(args.frequency) | ||
|
||
def isNotLive(self, timezone): | ||
today = datetime.datetime.now(timezone); | ||
if today.weekday() >= weekday_start and \ | ||
today.weekday() <= weekday_end and \ | ||
today.hour() >= hour_start and \ | ||
today.hour() <= hour_end: | ||
return False; | ||
|
||
return True; | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
|
||
|
@@ -124,8 +150,8 @@ def get_price(self, url, symbol): | |
help="Delete existing Elasticsearch index first") | ||
parser.add_argument("-s", "--symbol", metavar="SYMBOL", | ||
help="Stock symbol to use, example: TSLA") | ||
parser.add_argument("-f", "--frequency", metavar="FREQUENCY", default=600, type=int, | ||
help="How often in seconds to retrieve stock data (default: 120 sec)") | ||
parser.add_argument("-f", "--frequency", metavar="FREQUENCY", default=price_frequency, type=int, | ||
help="How often in seconds to retrieve stock data (default: %d sec)" % price_frequency) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is no longer applicable in the latest commit. |
||
parser.add_argument("-v", "--verbose", action="store_true", | ||
help="Increase output verbosity") | ||
parser.add_argument("--debug", action="store_true", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when this is exposed permanently?