database caller responsiveness

This commit is contained in:
Neythen Treloar 2022-02-28 20:16:31 +00:00
parent 7ec1cef1b9
commit e929435fd9
2 changed files with 35 additions and 8 deletions

View File

@ -1 +1 @@
{"update_available": false, "first_boot": false} {"update_available": true, "first_boot": false}

View File

@ -18,6 +18,7 @@ from pycoingecko import CoinGeckoAPI
from newsapi import NewsApiClient from newsapi import NewsApiClient
import traceback import traceback
from geopy import geocoders from geopy import geocoders
from multiprocessing import Process
def getInput(Block=False): def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
@ -592,6 +593,9 @@ if __name__ == '__main__':
try: try:
weather_key = api_keys[1].strip() weather_key = api_keys[1].strip()
except Exception as e: except Exception as e:
@ -613,7 +617,7 @@ if __name__ == '__main__':
last_updates = {"stocks": "27/06/2021 07:05:39", "crypto": "27/06/2021 07:05:39", "news": "27/06/2021 07:05:39", "weather": "27/06/2021 07:05:39", "forex": "27/06/2021 07:05:39", "sports": "27/06/2021 07:05:39"} last_updates = {"stocks": "27/06/2021 07:05:39", "crypto": "27/06/2021 07:05:39", "news": "27/06/2021 07:05:39", "weather": "27/06/2021 07:05:39", "forex": "27/06/2021 07:05:39", "sports": "27/06/2021 07:05:39"}
t = time.time() t = time.time()
update_processes = []
try: try:
while True: while True:
@ -630,7 +634,10 @@ if __name__ == '__main__':
if checkStocks(stock_time, stock_frequency) or msg == 's': if checkStocks(stock_time, stock_frequency) or msg == 's':
stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['stocks'] = stock_time last_updates['stocks'] = stock_time
updateStocks(api_key) #updateStocks(api_key)
update_process = Process(target = updateStocks, args = (api_key,))
update_process.start()
update_processes.append(update_process)
# crypto # crypto
crypto_time = datetime.strptime(last_updates['crypto'], "%d/%m/%Y %H:%M:%S") crypto_time = datetime.strptime(last_updates['crypto'], "%d/%m/%Y %H:%M:%S")
@ -640,8 +647,11 @@ if __name__ == '__main__':
diff = (NY_time - crypto_time).total_seconds()/60 #minutes diff = (NY_time - crypto_time).total_seconds()/60 #minutes
if diff >= update_frequencies['crypto'] or msg == 'c': if 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) #updateCrypto(api_key)
last_updates['crypto'] = crypto_time last_updates['crypto'] = crypto_time
update_process = Process(target = updateCrypto, args = (api_key,))
update_process.start()
update_processes.append(update_process)
# weather # weather
@ -652,8 +662,12 @@ if __name__ == '__main__':
diff = (NY_time - weather_time).total_seconds()/60 #minutes diff = (NY_time - weather_time).total_seconds()/60 #minutes
if diff >= update_frequencies['weather'] or msg == 'w': if diff >= update_frequencies['weather'] or msg == 'w':
weather_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") weather_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateWeather(weather_key)
#updateWeather(weather_key)
last_updates['weather'] = weather_time last_updates['weather'] = weather_time
update_process = Process(target = updateWeather, args = (weather_key,))
update_process.start()
update_processes.append(update_process)
# news # news
@ -664,8 +678,11 @@ if __name__ == '__main__':
diff = (NY_time - news_time).total_seconds()/60 #minutes diff = (NY_time - news_time).total_seconds()/60 #minutes
if diff >= update_frequencies['news'] or msg == 'n': if diff >= update_frequencies['news'] or msg == 'n':
news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateNews(api_key) #updateNews(api_key)
last_updates['news'] = news_time last_updates['news'] = news_time
update_process = Process(target = updateNews, args = (api_key,))
update_process.start()
update_processes.append(update_process)
# sports # sports
sports_time = datetime.strptime(last_updates['sports'], "%d/%m/%Y %H:%M:%S") sports_time = datetime.strptime(last_updates['sports'], "%d/%m/%Y %H:%M:%S")
@ -673,8 +690,11 @@ if __name__ == '__main__':
diff = (NY_time - sports_time).total_seconds()/60 #minutes diff = (NY_time - sports_time).total_seconds()/60 #minutes
if diff >= update_frequencies['sports'] or msg == 'S': if diff >= update_frequencies['sports'] or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S") sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateSports(api_key) #updateSports(api_key)
last_updates['sports'] = sports_time last_updates['sports'] = sports_time
update_process = Process(target = updateSports, args = (api_key,))
update_process.start()
update_processes.append(update_process)
#forex updates once every 24hours at 1700 CET #forex updates once every 24hours at 1700 CET
@ -692,10 +712,17 @@ if __name__ == '__main__':
if forex_time < yday_update or msg == 'f' or (diff >= update_frequencies['forex'] and forex_open): if forex_time < yday_update or msg == 'f' or (diff >= update_frequencies['forex'] and forex_open):
forex_time = CET_time.strftime("%d/%m/%Y %H:%M:%S") forex_time = CET_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['forex'] = forex_time last_updates['forex'] = forex_time
updateForex(api_key) #updateForex(api_key)
update_process = Process(target = updateForex, args = (api_key,))
update_process.start()
update_processes.append(update_process)
json.dump(last_updates, open('csv/last_updates.json', 'w+')) json.dump(last_updates, open('csv/last_updates.json', 'w+'))
for process in update_processes:
if not process.is_alive():
process.join()
process.terminate()
except Exception as e: except Exception as e: