added quotes
This commit is contained in:
parent
4ec8bbf680
commit
440c92a4c5
@ -857,6 +857,33 @@ def updateJokes(api_key, logf):
|
||||
pass
|
||||
|
||||
|
||||
def updateQuotes(api_key, logf):
|
||||
try:
|
||||
with open('csv/quotes_settings.json', 'r') as f:
|
||||
quotes_settings = json.load(f)
|
||||
except:
|
||||
quotes_settings = {"feature": "Inspirational Quotes", "speed": "medium", "speed2": "medium", "animation": "up", "title": True, "amount": "3", "quotes": []}
|
||||
try:
|
||||
number = int(quotes_settings['amount'])
|
||||
url = 'https://zenquotes.io/api/random'
|
||||
quotes_settings['quotes'] = []
|
||||
for _ in range(number):
|
||||
try:
|
||||
data = requests.get(url).json()[0]
|
||||
quote = data['q']
|
||||
author = data['a']
|
||||
quotes_settings['quotes'].append({
|
||||
'quote': quote,
|
||||
'author': author
|
||||
})
|
||||
except:
|
||||
pass
|
||||
with open('csv/quotes_settings.json', 'w') as f:
|
||||
json.dump(quotes_settings,f)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def updateMarket(api_key, logf):
|
||||
try:
|
||||
try:
|
||||
@ -1628,7 +1655,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, 'economic': 15, 'jokes': 15, 'market': 5} #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, 'jokes': 15, 'market': 5, 'quotes': 10} #minutes
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
CET_zone = pytz.timezone('EST')
|
||||
@ -1706,7 +1733,7 @@ if __name__ == '__main__':
|
||||
"forex": {"time": "06/03/2022 03:54:02", "force": True}, "sports_l": {"time": "06/03/2022 04:10:09", "force": True},
|
||||
"sports_p": {"time": "06/03/2022 04:10:09", "force": True},
|
||||
"sports_u": {"time": "06/03/2022 04:10:09", "force": True},"sports_t": {"time": "06/03/2022 04:10:09", "force": True}, "commodities": {"time": "06/03/2022 04:10:09", "force": True}, "indices": {"time": "06/03/2022 04:10:09", "force": True}, "movies": {"time": "06/03/2022 04:10:09", "force": True}, "ipo": {"time": "06/03/2022 04:10:09", "force": True},
|
||||
"prepost": {"time": "06/03/2022 04:10:09", "force": True}, "economic": {"time": "06/03/2022 04:10:09", "force": True}, "jokes": {"time": "06/03/2022 04:10:09", "force": True}, "market": {"time": "06/03/2022 04:10:09", "force": True}, "sector": {"time": "06/03/2022 04:10:09", "force": True}}
|
||||
"prepost": {"time": "06/03/2022 04:10:09", "force": True}, "economic": {"time": "06/03/2022 04:10:09", "force": True}, "jokes": {"time": "06/03/2022 04:10:09", "force": True}, "market": {"time": "06/03/2022 04:10:09", "force": True}, "sector": {"time": "06/03/2022 04:10:09", "force": True}, "quotes": {"time": "06/03/2022 04:10:09", "force": True}}
|
||||
|
||||
try:
|
||||
if last_updates['scheduler']['force']:
|
||||
@ -1871,7 +1898,6 @@ if __name__ == '__main__':
|
||||
update_processes.append(update_process)
|
||||
|
||||
|
||||
|
||||
# jokes
|
||||
jokes_time = datetime.strptime(last_updates['jokes']['time'], "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
@ -1885,6 +1911,21 @@ if __name__ == '__main__':
|
||||
update_process = Process(target = updateJokes, args = (api_key,logf))
|
||||
update_process.start()
|
||||
update_processes.append(update_process)
|
||||
|
||||
|
||||
# quotes
|
||||
quotes_time = datetime.strptime(last_updates['quotes']['time'], "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - jokes_time).total_seconds()/60 #minutes
|
||||
|
||||
if last_updates['quotes']['force'] or diff >= update_frequencies['quotes']:# or msg == 'c':
|
||||
quotes_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
last_updates['quotes']['time'] = quotes_time
|
||||
last_updates['quotes']['force'] = False
|
||||
update_process = Process(target = updateQuotes, args = (api_key,logf))
|
||||
update_process.start()
|
||||
update_processes.append(update_process)
|
||||
|
||||
|
||||
# indices
|
||||
|
Loading…
Reference in New Issue
Block a user