-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
36 lines (24 loc) · 889 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
from datetime import datetime, timedelta
from dateutil import parser
import json
TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"
INPUT_PATH = "stocks.csv"
SOURCE_NAME = "twitter"
SCRAPED_COUNT_PATH = "/scraped_count.json"
def get_ticker_symbols():
df = pd.read_csv(INPUT_PATH)
return df["ticker_symbol"].tolist()
def convert_time_to_eastern_time(timestamp):
return datetime.strptime(timestamp, TIMESTAMP_FORMAT) - timedelta(hours=12)
def get_timestamp_days_before(timestamp, n_days):
return timestamp - timedelta(days=n_days)
def write_scraped_count(data_source, count):
with open(SCRAPED_COUNT_PATH, "r") as read_file:
try:
data = json.load(read_file)
except Exception as e:
data = {}
data[data_source] = count
with open(SCRAPED_COUNT_PATH, "w") as write_file:
json.dump(data, write_file)