added quotes
This commit is contained in:
@@ -857,6 +857,33 @@ def updateJokes(api_key, logf):
|
|||||||
pass
|
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):
|
def updateMarket(api_key, logf):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@@ -1628,7 +1655,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, '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')
|
NY_zone = pytz.timezone('America/New_York')
|
||||||
CET_zone = pytz.timezone('EST')
|
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},
|
"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_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},
|
"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:
|
try:
|
||||||
if last_updates['scheduler']['force']:
|
if last_updates['scheduler']['force']:
|
||||||
@@ -1871,7 +1898,6 @@ if __name__ == '__main__':
|
|||||||
update_processes.append(update_process)
|
update_processes.append(update_process)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# jokes
|
# jokes
|
||||||
jokes_time = datetime.strptime(last_updates['jokes']['time'], "%d/%m/%Y %H:%M:%S")
|
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 = Process(target = updateJokes, args = (api_key,logf))
|
||||||
update_process.start()
|
update_process.start()
|
||||||
update_processes.append(update_process)
|
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
|
# indices
|
||||||
|
Reference in New Issue
Block a user