MCPcopy
hub / github.com/geekcomputers/Python / load

Function load

wiki_random.py:29–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27
28
29def 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
58if __name__ == "__main__":

Callers 1

wiki_random.pyFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected