Skip to content

Commit 0099aca

Browse files
updated wiki_random.py, added module doc and few exception handing.
1 parent 7e641f4 commit 0099aca

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

wiki_random.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
'''Author Anurag Kumar(mailto:anuragkumarak95@gmail.com)
2+
Module for Fetching Random Wiki Pages and asking user for opening one of them
3+
4+
Python:
5+
- 3.5
6+
7+
Requirements:
8+
- requests
9+
- json
10+
- webbrowser
11+
12+
Usage:
13+
- $python3 wiki_random.py
14+
15+
enter index of article you would like to see, or 'r' for retry and 'n' for exit.
16+
'''
117
import requests, json, webbrowser
218

3-
url = 'https://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json'
19+
page_count = 10
20+
url = 'https://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit='+str(page_count)+'&format=json'
421

522
def load():
623
response = requests.get(url)
@@ -16,7 +33,7 @@ def load():
1633
print('Auf Wiedersehen!')
1734
return
1835
else:
19-
try: int(i)
36+
try: jsonData[int(i)]['id']
2037
except Exception: raise Exception("Wrong Input...")
2138
print('taking you to the browser...')
2239
webbrowser.get().open('https://en.wikipedia.org/wiki?curid='+str(jsonData[int(i)]['id']))

0 commit comments

Comments
 (0)