updateJokes function

This commit is contained in:
Justin 2023-07-12 17:51:44 +08:00 committed by GitHub
parent ea5400c1e2
commit 249d3d1992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -811,7 +811,34 @@ def updateEconomic(api_key, logf):
except:
pass
def updateJokes(api_key, logf):
try:
with open('csv/jokes_settings.json', 'r') as f:
jokes_settings = json.load(f)
except:
jokes_settings = {"feature": "Jokes", "speed": "medium", "speed2": "medium", "animation": "up", "title": true, "categories": ["Any"], "blacklist": [], "amount": "5", "jokes": []}
try:
categories = ','.join(jokes_settings['categories'])
blacklist = ','.join(jokes_settings['blacklist'])
amount = jokes_settings['amount']
jokes_settings['jokes'] = []
joke_url = 'https://v2.jokeapi.dev/joke/'+categories+'?amount='+amount
if blacklist != '':
joke_url = 'https://v2.jokeapi.dev/joke/'+categories+ '?blacklistFlags=' + blacklist + '&amount='+amount
get_jokes = requests.get(joke_url)
all_jokes = get_jokes.json()
for each_joke in all_jokes['jokes']:
jokes_settings['jokes'].append(each_joke)
with open('csv/jokes_settings.json', 'w') as f:
json.dump(jokes_settings,f)
except:
pass
def updateNews(api_key, logf):
try: