Skip to content

Commit b31b2ee

Browse files
committed
Wikipedia CLI version
1 parent 5f182e4 commit b31b2ee

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

python/wiku.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#~!~#
2+
#python 3.7.X
3+
#if you are new run this program run this command
4+
#python -m pip install gtts playsound wikipedia
5+
6+
from gtts import gTTS
7+
from playsound import playsound
8+
import os,wikipedia,argparse
9+
10+
class Run:
11+
def lang(self,lg):
12+
if lg == None:
13+
self.langue='en'
14+
else:
15+
self.langue=lg
16+
17+
def wiki(self,query):
18+
wikipedia.set_lang(self.langue)
19+
if type(query) == list:
20+
kalimat=wikipedia.summary(" ".join(str(x) for x in query))
21+
else:
22+
kalimat=wikipedia.summary(query)
23+
print(kalimat)
24+
if args['say'] == True:
25+
self.say=gTTS(text=kalimat,lang=self.langue)
26+
print("\n[!] Making audio...")
27+
self.say.save('say.mp3')
28+
print("[OK] Audio started.")
29+
playsound('say.mp3')
30+
31+
def _help():
32+
global args
33+
parser = argparse.ArgumentParser()
34+
parser.add_argument('-s','--say', help='To read out the search results', action='store_true')
35+
parser.add_argument('-l',dest='lang', help='for change language (default:english)')
36+
parser.add_argument('-q',dest='query', help='for search something to wikipedia', required=True, nargs='*')
37+
args = vars(parser.parse_args())
38+
# print(args)
39+
40+
os.system('clear')
41+
print("WIKIPEDIA-CLI")
42+
_help()
43+
try:
44+
wik=Run()
45+
wik.lang(args['lang'])
46+
wik.wiki(args['query'])
47+
except Exception as Err:
48+
print("ERR: %s"%(Err))

0 commit comments

Comments
 (0)