| 27 | |
| 28 | |
| 29 | def load(): |
| 30 | response = requests.get(url) |
| 31 | if response.ok: |
| 32 | jsonData = response.json()["query"]["random"] |
| 33 | print("10 Random generted WIKI pages...") |
| 34 | for idx, j in enumerate(jsonData): |
| 35 | print(str(idx) + ": ", j["title"]) |
| 36 | i = input( |
| 37 | "Which page you want to see, enter index..[r: for retry,n: exit]?" |
| 38 | ).lower() |
| 39 | if i == "r": |
| 40 | print("Loading randoms again...") |
| 41 | elif i == "n": |
| 42 | print("Auf Wiedersehen!") |
| 43 | return |
| 44 | else: |
| 45 | try: |
| 46 | jsonData[int(i)]["id"] |
| 47 | except Exception: |
| 48 | raise Exception("Wrong Input...") |
| 49 | print("taking you to the browser...") |
| 50 | webbrowser.get().open( |
| 51 | "https://en.wikipedia.org/wiki?curid=" + str(jsonData[int(i)]["id"]) |
| 52 | ) |
| 53 | load() |
| 54 | else: |
| 55 | response.raise_for_status() |
| 56 | |
| 57 | |
| 58 | if __name__ == "__main__": |