Skip to content

Instantly share code, notes, and snippets.

@jbaranski
Created February 12, 2023 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbaranski/5419c049af1989c1808a71bc73c9f3f4 to your computer and use it in GitHub Desktop.
Save jbaranski/5419c049af1989c1808a71bc73c9f3f4 to your computer and use it in GitHub Desktop.
Download all questions from Open Trivia DB (opentdb.com)
import requests
import json
import time
if __name__ == '__main__':
db = {}
while True:
r = requests.get('https://opentdb.com/api.php?amount=50')
results = r.json()['results']
for result in results:
db[result['question']] = result
len_db = len(list(db.values()))
if len_db >= 4098:
break
time.sleep(.5)
print(len_db)
with open('db.json', 'w') as f:
json.dump(list(db.values()), f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment