economic settings db caller (WIP)

This commit is contained in:
Justin 2023-06-14 16:44:37 +08:00 committed by GitHub
parent 4fae1812a5
commit b40842e040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -592,11 +592,7 @@ def updateIndices(api_key, logf):
def updateCrypto(api_key, logf):
try:
f = open('csv/crypto_settings.json', 'r')
all_crypto_settings = json.load(f)
f.close()
@ -618,8 +614,6 @@ def updateCrypto(api_key, logf):
response = requests.get(url)
data = response.json()
coin_info = {}
if len(data) > 0:
for sb in symbol_base:
@ -639,7 +633,6 @@ def updateCrypto(api_key, logf):
except:
pass
#logf = open('log.txt', "a")
#exc_type, exc_obj, exc_tb = sys.exc_info()
#fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
@ -652,8 +645,6 @@ def updateCrypto(api_key, logf):
def updateForex(api_key, logf):
try:
f = open('csv/forex_settings.json', 'r')
all_forex_settings = json.load(f)
@ -671,7 +662,6 @@ def updateForex(api_key, logf):
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/forex?symbols='
for i,s in enumerate(symbols):
url += s + '-' + bases[i] + ','
url = url[:-1] #remove last comma
@ -680,7 +670,6 @@ def updateForex(api_key, logf):
response = requests.get(url)
data = response.json()
if len(data) > 0:
c_dict = {}
@ -689,9 +678,6 @@ def updateForex(api_key, logf):
if d['uid'].replace('/',',') == sb:
c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']}
all_forex_settings['symbols'] = c_dict
f = open( "csv/forex_settings.json", 'w+' )
@ -710,8 +696,11 @@ def updateForex(api_key, logf):
#logf.close()
def updateNews(api_key, logf):
def updateEconomic(api_key, logf):
def updateNews(api_key, logf):
try:
f = open('csv/news_settings.json', 'r')
all_settings = json.load(f)
@ -1386,11 +1375,7 @@ if __name__ == '__main__':
t = time.time()
update_frequencies = {'stocks':2, 'crypto':7, 'forex':60, 'news':120, 'weather': 120, 'sports': 1440, 'commodities': 15, 'indices': 15, 'movies': 1440, 'ipo': 1440, 'prepost': 15} #minutes
update_frequencies = {'stocks':2, 'crypto':7, 'forex':60, 'news':120, 'weather': 120, 'sports': 1440, 'commodities': 15, 'indices': 15, 'movies': 1440, 'ipo': 1440, 'prepost': 15, 'economic': 15} #minutes
NY_zone = pytz.timezone('America/New_York')
CET_zone = pytz.timezone('EST')
@ -1417,15 +1402,15 @@ if __name__ == '__main__':
weather_key = api_keys[1].strip()
except Exception as e:
weather_key = False
logf = open('log.txt', "a")
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
logf.write(str(e))
logf.write('. file: ' + fname)
logf.write('. line: ' + str(exc_tb.tb_lineno))
logf.write('. type: ' + str(exc_type))
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
logf.close()
# logf = open('log.txt', "a")
# exc_type, exc_obj, exc_tb = sys.exc_info()
# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
# logf.write(str(e))
# logf.write('. file: ' + fname)
# logf.write('. line: ' + str(exc_tb.tb_lineno))
# logf.write('. type: ' + str(exc_type))
# logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
# logf.close()
try:
movie_key = open('movie_api_key.txt').readlines()[0]
@ -1457,7 +1442,6 @@ if __name__ == '__main__':
try:
while True:
try:
f = open('csv/last_updates.json', 'r')
last_updates = json.load(f)
@ -1516,8 +1500,6 @@ if __name__ == '__main__':
#msg = getInput()
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
#stocks
@ -1569,49 +1551,57 @@ if __name__ == '__main__':
# crypto
crypto_time = datetime.strptime(last_updates['crypto']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - crypto_time).total_seconds()/60 #minutes
if last_updates['crypto']['force'] or diff >= update_frequencies['crypto']:# or msg == 'c':
crypto_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateCrypto(api_key, logf)
last_updates['crypto']['time'] = crypto_time
last_updates['crypto']['force'] = False
update_process = Process(target = updateCrypto, args = (api_key,logf))
update_process.start()
update_processes.append(update_process)
# commodities
commodities_time = datetime.strptime(last_updates['commodities']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - commodities_time).total_seconds()/60 #minutes
if last_updates['commodities']['force'] or diff >= update_frequencies['commodities']:# or msg == 'c':
commodities_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateCrypto(api_key, logf)
last_updates['commodities']['time'] = commodities_time
last_updates['commodities']['force'] = False
update_process = Process(target = updateCommodities, args = (api_key,logf))
update_process.start()
update_processes.append(update_process)
# economic calendar
economic_time = datetime.strptime(last_updates['economic']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - economic_time).total_seconds()/60 #minutes
if last_updates['economic']['force'] or diff >= update_frequencies['economic']:# or msg == 'c':
economic_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['economic']['time'] = economic_time
last_updates['economic']['force'] = False
update_process = Process(target = updateEconomic, args = (api_key,logf))
update_process.start()
update_processes.append(update_process)
# indices
indices_time = datetime.strptime(last_updates['indices']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - indices_time).total_seconds()/60 #minutes
if last_updates['indices']['force'] or diff >= update_frequencies['indices']:# or msg == 'c':
indices_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
@ -1621,14 +1611,13 @@ if __name__ == '__main__':
update_process.start()
update_processes.append(update_process)
# movies
movies_time = datetime.strptime(last_updates['movies']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - movies_time).total_seconds()/60 #minutes
if last_updates['movies']['force'] or diff >= update_frequencies['movies']:
movies_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['movies']['time'] = movies_time
@ -1641,11 +1630,9 @@ if __name__ == '__main__':
# ipos
ipo_time = datetime.strptime(last_updates['ipo']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - ipo_time).total_seconds()/60 #minutes
if last_updates['ipo']['force'] or diff >= update_frequencies['ipo']:
ipo_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['ipo']['time'] = ipo_time
@ -1658,7 +1645,6 @@ if __name__ == '__main__':
# weather
weather_time = datetime.strptime(last_updates['weather']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - weather_time).total_seconds()/60 #minutes
if last_updates['weather']['force'] or diff >= update_frequencies['weather']:# or msg == 'w':