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
import traceback
from geopy import geocoders
from multiprocessing import Process
def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
@ -591,6 +592,9 @@ if __name__ == '__main__':
api_key = api_keys[0].strip()
try:
weather_key = api_keys[1].strip()
@ -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"}
t = time.time()
update_processes = []
try:
while True:
@ -630,7 +634,10 @@ if __name__ == '__main__':
if checkStocks(stock_time, stock_frequency) or msg == 's':
stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
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_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
if diff >= update_frequencies['crypto'] or msg == 'c':
crypto_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateCrypto(api_key)
#updateCrypto(api_key)
last_updates['crypto'] = crypto_time
update_process = Process(target = updateCrypto, args = (api_key,))
update_process.start()
update_processes.append(update_process)
# weather
@ -652,8 +662,12 @@ if __name__ == '__main__':
diff = (NY_time - weather_time).total_seconds()/60 #minutes
if diff >= update_frequencies['weather'] or msg == 'w':
weather_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateWeather(weather_key)
#updateWeather(weather_key)
last_updates['weather'] = weather_time
update_process = Process(target = updateWeather, args = (weather_key,))
update_process.start()
update_processes.append(update_process)
# news
@ -664,8 +678,11 @@ if __name__ == '__main__':
diff = (NY_time - news_time).total_seconds()/60 #minutes
if diff >= update_frequencies['news'] or msg == 'n':
news_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateNews(api_key)
#updateNews(api_key)
last_updates['news'] = news_time
update_process = Process(target = updateNews, args = (api_key,))
update_process.start()
update_processes.append(update_process)
# sports
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
if diff >= update_frequencies['sports'] or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
updateSports(api_key)
#updateSports(api_key)
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
@ -692,10 +712,17 @@ if __name__ == '__main__':
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")
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+'))
for process in update_processes:
if not process.is_alive():
process.join()
process.terminate()
except Exception as e: