-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
88 lines (82 loc) · 2.38 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import wikipedia
import random
def searchselector():
global searchselect
searchselect=int(input('Select an option from the list (0 to '+ str(len(resultlist)-1)+'): '))
def randomsearchselector():
global searchselect
searchselect=random.randrange(len(resultlist))
def getpage(searchselect):
global page
page=wikipedia.page(resultlist[searchselect], auto_suggest=False)
def getrandompage(topic):
global page
page=wikipedia.page(topic)
def getsummary(page):
str="_"
print(str*64)
print(page.title)
print(str*64)
print(page.summary)
print(str*64)
def getcontent(page):
str="_"
print(str*64)
print(page.content)
print(str*64)
def exitfunc():
n=input('Do you want to exit? y/n: ')
if (n=="y"):
exit()
else:
searchfunc()
def newsearchfunc():
secondchoice=input("Do you want to make new search? y/n: ")
if (secondchoice=="y"):
searchfunc()
else:
linkaskfunc()
def linkaskfunc():
secondchoice=input("Do you want to jump to random link within current page? y/n: ")
if (secondchoice=="y"):
linkfunc()
else:
exitfunc()
def linkfunc():
global searchselect
global page
global resultlist
resultlist=page.links
searchselect=random.randrange(len(resultlist))
getpage(searchselect)
decidedisplaytype=input("Do you want to see a summary, no means full page? y/n: ")
if (decidedisplaytype=="y"):
getsummary(page)
else:
getcontent(page)
linkaskfunc()
def searchfunc():
global inputsearch
global resultlist
askrandom=input("Generate random article? y/n: ")
if (askrandom=="y"):
topic=wikipedia.random(1)
getrandompage(topic)
else:
inputsearch=input('Enter a search term to search in Wikipedia: ')
resultlist=list(wikipedia.search(inputsearch))
for i in range(len(resultlist)):
print(i,"- ",resultlist[i], end='\n')
decideselecttype=input("Do you want to select search list randomly? y/n: ")
if (decideselecttype=="y"):
randomsearchselector()
else:
searchselector()
getpage(searchselect)
decidedisplaytype=input("Do you want to see a summary, no means full page? y/n: ")
if (decidedisplaytype=="y"):
getsummary(page)
else:
getcontent(page)
newsearchfunc()
searchfunc()