Update database_caller.py

This commit is contained in:
Justin 2023-03-08 15:30:17 +08:00 committed by GitHub
parent 1f1890022d
commit 3ae2e82d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -290,7 +290,58 @@ def updateMovies(api_key, logf):
f = open('csv/movie_settings.json', 'w+') f = open('csv/movie_settings.json', 'w+')
json.dump(all_settings, f) json.dump(all_settings, f)
f.close() f.close()
def updateIpo(api_key, logf):
day = datetime.now(pytz.utc).strftime("%Y-%m-%d")
dt = datetime.strptime(day, "%Y-%m-%d")
start = (dt - timedelta(days=dt.weekday()))
start_date = start.strftime("%Y-%m-%d")
end = start + timedelta(days=21)
end_date = end.strftime("%Y-%m-%d")
ipo_url = 'https://finnhub.io/api/v1/calendar/ipo?from='+start_date+'&to='+end_date+'&token='+api_key
f = open('csv/ipo_settings.json', 'r')
ipo_settings = json.load(f)
f.close()
data = requests.get(ipo_url)
all_ipo = data.json()
ipo_list = []
if len(all_ipo['ipoCalendar']) > 0:
for ipo in all_ipo['ipoCalendar']:
try:
shares = human_format(ipo['numberOfShares'])
except:
shares = 'N/A'
try:
sharesvalue = human_format(ipo['totalSharesValue'])
except:
sharesvalue = 'N/A'
ipo_list.append({
'date':ipo['date'],
'name':ipo['name'],
'shares':shares,
'price':ipo['price'],
'status':ipo['status'],
'symbol':ipo['symbol'],
'sharesvalue':sharesvalue
})
else:
ipo_list = ['No Data']
ipo_settings['symbols'] = ipo_list
f = open('csv/ipo_settings.json', 'w+')
json.dump(ipo_settings, f)
f.close()
def updateIndices(api_key, logf): def updateIndices(api_key, logf):