File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import requests , json , webbrowser
2+
3+ url = 'https://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json'
4+
5+ def load ():
6+ response = requests .get (url )
7+ if response .ok :
8+ jsonData = response .json ()['query' ]['random' ]
9+ print ("10 Random generted WIKI pages..." )
10+ for idx ,j in enumerate (jsonData ):
11+ print (str (idx )+ ": " ,j ['title' ])
12+ i = input ("Which page you want to see, enter index..[r: for retry,n: exit]?" ).lower ()
13+ if i == 'r' :
14+ print ('Loading randoms again...' )
15+ elif i == 'n' :
16+ print ('Auf Wiedersehen!' )
17+ return
18+ else :
19+ try : int (i )
20+ except Exception : raise Exception ("Wrong Input..." )
21+ print ('taking you to the browser...' )
22+ webbrowser .get ().open ('https://en.wikipedia.org/wiki?curid=' + str (jsonData [int (i )]['id' ]))
23+ load ()
24+ else :
25+ response .raise_for_status ()
26+
27+ if __name__ == '__main__' :
28+ load ()
You can’t perform that action at this time.
0 commit comments