economic settings db caller (WIP)
This commit is contained in:
@@ -591,12 +591,8 @@ def updateIndices(api_key, logf):
|
|||||||
|
|
||||||
|
|
||||||
def updateCrypto(api_key, logf):
|
def updateCrypto(api_key, logf):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
||||||
f = open('csv/crypto_settings.json', 'r')
|
f = open('csv/crypto_settings.json', 'r')
|
||||||
all_crypto_settings = json.load(f)
|
all_crypto_settings = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
@@ -618,8 +614,6 @@ def updateCrypto(api_key, logf):
|
|||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
coin_info = {}
|
coin_info = {}
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
for sb in symbol_base:
|
for sb in symbol_base:
|
||||||
@@ -639,7 +633,6 @@ def updateCrypto(api_key, logf):
|
|||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#logf = open('log.txt', "a")
|
#logf = open('log.txt', "a")
|
||||||
#exc_type, exc_obj, exc_tb = sys.exc_info()
|
#exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
#fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
#fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
@@ -651,9 +644,7 @@ def updateCrypto(api_key, logf):
|
|||||||
#logf.close()
|
#logf.close()
|
||||||
|
|
||||||
def updateForex(api_key, logf):
|
def updateForex(api_key, logf):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open('csv/forex_settings.json', 'r')
|
f = open('csv/forex_settings.json', 'r')
|
||||||
all_forex_settings = json.load(f)
|
all_forex_settings = json.load(f)
|
||||||
@@ -670,8 +661,7 @@ def updateForex(api_key, logf):
|
|||||||
targets = ','.join(symbols)
|
targets = ','.join(symbols)
|
||||||
|
|
||||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/forex?symbols='
|
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/forex?symbols='
|
||||||
|
|
||||||
|
|
||||||
for i,s in enumerate(symbols):
|
for i,s in enumerate(symbols):
|
||||||
url += s + '-' + bases[i] + ','
|
url += s + '-' + bases[i] + ','
|
||||||
url = url[:-1] #remove last comma
|
url = url[:-1] #remove last comma
|
||||||
@@ -679,8 +669,7 @@ def updateForex(api_key, logf):
|
|||||||
|
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
|
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
|
|
||||||
c_dict = {}
|
c_dict = {}
|
||||||
@@ -689,9 +678,6 @@ def updateForex(api_key, logf):
|
|||||||
if d['uid'].replace('/',',') == sb:
|
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']}
|
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
|
all_forex_settings['symbols'] = c_dict
|
||||||
|
|
||||||
f = open( "csv/forex_settings.json", 'w+' )
|
f = open( "csv/forex_settings.json", 'w+' )
|
||||||
@@ -709,9 +695,12 @@ def updateForex(api_key, logf):
|
|||||||
#logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
#logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
#logf.close()
|
#logf.close()
|
||||||
|
|
||||||
|
|
||||||
|
def updateEconomic(api_key, logf):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def updateNews(api_key, logf):
|
def updateNews(api_key, logf):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open('csv/news_settings.json', 'r')
|
f = open('csv/news_settings.json', 'r')
|
||||||
all_settings = json.load(f)
|
all_settings = json.load(f)
|
||||||
@@ -1386,11 +1375,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
t = time.time()
|
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, 'economic': 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} #minutes
|
|
||||||
|
|
||||||
NY_zone = pytz.timezone('America/New_York')
|
NY_zone = pytz.timezone('America/New_York')
|
||||||
CET_zone = pytz.timezone('EST')
|
CET_zone = pytz.timezone('EST')
|
||||||
@@ -1417,15 +1402,15 @@ if __name__ == '__main__':
|
|||||||
weather_key = api_keys[1].strip()
|
weather_key = api_keys[1].strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
weather_key = False
|
weather_key = False
|
||||||
logf = open('log.txt', "a")
|
# logf = open('log.txt', "a")
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
# exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
logf.write(str(e))
|
# logf.write(str(e))
|
||||||
logf.write('. file: ' + fname)
|
# logf.write('. file: ' + fname)
|
||||||
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
# logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||||
logf.write('. type: ' + str(exc_type))
|
# 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.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
logf.close()
|
# logf.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
movie_key = open('movie_api_key.txt').readlines()[0]
|
movie_key = open('movie_api_key.txt').readlines()[0]
|
||||||
@@ -1457,7 +1442,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open('csv/last_updates.json', 'r')
|
f = open('csv/last_updates.json', 'r')
|
||||||
last_updates = json.load(f)
|
last_updates = json.load(f)
|
||||||
@@ -1516,8 +1500,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
#msg = getInput()
|
#msg = getInput()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
#stocks
|
#stocks
|
||||||
|
|
||||||
@@ -1568,50 +1550,58 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# crypto
|
# crypto
|
||||||
crypto_time = datetime.strptime(last_updates['crypto']['time'], "%d/%m/%Y %H:%M:%S")
|
crypto_time = datetime.strptime(last_updates['crypto']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - crypto_time).total_seconds()/60 #minutes
|
diff = (NY_time - crypto_time).total_seconds()/60 #minutes
|
||||||
|
|
||||||
|
|
||||||
if last_updates['crypto']['force'] or diff >= update_frequencies['crypto']:# or msg == 'c':
|
if last_updates['crypto']['force'] or diff >= update_frequencies['crypto']:# or msg == 'c':
|
||||||
crypto_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
crypto_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
#updateCrypto(api_key, logf)
|
#updateCrypto(api_key, logf)
|
||||||
|
|
||||||
|
|
||||||
last_updates['crypto']['time'] = crypto_time
|
last_updates['crypto']['time'] = crypto_time
|
||||||
last_updates['crypto']['force'] = False
|
last_updates['crypto']['force'] = False
|
||||||
update_process = Process(target = updateCrypto, args = (api_key,logf))
|
update_process = Process(target = updateCrypto, args = (api_key,logf))
|
||||||
update_process.start()
|
update_process.start()
|
||||||
update_processes.append(update_process)
|
update_processes.append(update_process)
|
||||||
|
|
||||||
|
|
||||||
# commodities
|
# commodities
|
||||||
commodities_time = datetime.strptime(last_updates['commodities']['time'], "%d/%m/%Y %H:%M:%S")
|
commodities_time = datetime.strptime(last_updates['commodities']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - commodities_time).total_seconds()/60 #minutes
|
diff = (NY_time - commodities_time).total_seconds()/60 #minutes
|
||||||
|
|
||||||
|
|
||||||
if last_updates['commodities']['force'] or diff >= update_frequencies['commodities']:# or msg == 'c':
|
if last_updates['commodities']['force'] or diff >= update_frequencies['commodities']:# or msg == 'c':
|
||||||
commodities_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
commodities_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
#updateCrypto(api_key, logf)
|
#updateCrypto(api_key, logf)
|
||||||
|
|
||||||
|
|
||||||
last_updates['commodities']['time'] = commodities_time
|
last_updates['commodities']['time'] = commodities_time
|
||||||
last_updates['commodities']['force'] = False
|
last_updates['commodities']['force'] = False
|
||||||
update_process = Process(target = updateCommodities, args = (api_key,logf))
|
update_process = Process(target = updateCommodities, args = (api_key,logf))
|
||||||
update_process.start()
|
update_process.start()
|
||||||
update_processes.append(update_process)
|
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
|
||||||
indices_time = datetime.strptime(last_updates['indices']['time'], "%d/%m/%Y %H:%M:%S")
|
indices_time = datetime.strptime(last_updates['indices']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - indices_time).total_seconds()/60 #minutes
|
diff = (NY_time - indices_time).total_seconds()/60 #minutes
|
||||||
|
|
||||||
|
|
||||||
if last_updates['indices']['force'] or diff >= update_frequencies['indices']:# or msg == 'c':
|
if last_updates['indices']['force'] or diff >= update_frequencies['indices']:# or msg == 'c':
|
||||||
indices_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
indices_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
@@ -1621,14 +1611,13 @@ if __name__ == '__main__':
|
|||||||
update_process.start()
|
update_process.start()
|
||||||
update_processes.append(update_process)
|
update_processes.append(update_process)
|
||||||
|
|
||||||
|
|
||||||
# movies
|
# movies
|
||||||
movies_time = datetime.strptime(last_updates['movies']['time'], "%d/%m/%Y %H:%M:%S")
|
movies_time = datetime.strptime(last_updates['movies']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - movies_time).total_seconds()/60 #minutes
|
diff = (NY_time - movies_time).total_seconds()/60 #minutes
|
||||||
|
|
||||||
|
|
||||||
if last_updates['movies']['force'] or diff >= update_frequencies['movies']:
|
if last_updates['movies']['force'] or diff >= update_frequencies['movies']:
|
||||||
movies_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
movies_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
last_updates['movies']['time'] = movies_time
|
last_updates['movies']['time'] = movies_time
|
||||||
@@ -1640,12 +1629,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# ipos
|
# ipos
|
||||||
ipo_time = datetime.strptime(last_updates['ipo']['time'], "%d/%m/%Y %H:%M:%S")
|
ipo_time = datetime.strptime(last_updates['ipo']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - ipo_time).total_seconds()/60 #minutes
|
diff = (NY_time - ipo_time).total_seconds()/60 #minutes
|
||||||
|
|
||||||
|
|
||||||
if last_updates['ipo']['force'] or diff >= update_frequencies['ipo']:
|
if last_updates['ipo']['force'] or diff >= update_frequencies['ipo']:
|
||||||
ipo_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
ipo_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||||
last_updates['ipo']['time'] = ipo_time
|
last_updates['ipo']['time'] = ipo_time
|
||||||
@@ -1657,8 +1644,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# weather
|
# weather
|
||||||
weather_time = datetime.strptime(last_updates['weather']['time'], "%d/%m/%Y %H:%M:%S")
|
weather_time = datetime.strptime(last_updates['weather']['time'], "%d/%m/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||||
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
||||||
if last_updates['weather']['force'] or diff >= update_frequencies['weather']:# or msg == 'w':
|
if last_updates['weather']['force'] or diff >= update_frequencies['weather']:# or msg == 'w':
|
||||||
|
Reference in New Issue
Block a user