-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgre.py
103 lines (78 loc) · 2.29 KB
/
gre.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
from bs4 import BeautifulSoup
from requests import get
from random import randrange
import time
import os
import requests
import pyttsx # text-to-speech library
def say(n) :
e = pyttsx.init() # initiates speech engine
#use the following if you want to hear in random languages
'''
voices = e.getProperty('voices')
i = randrange(0,len(voices))
e.setProperty('voice', voices[i].id)
'''
#e.setProperty('rate',120)
e.say(n) # loads text into engine
e.runAndWait() # THIS LINE IS IMPORTANT, runs the speech engine
say('Please wait')
#Generating request for the specific url
url = "https://quizlet.com/58647605/kaplan-900-flash-cards/"
htmldoc = get(url).text
#Extract the document from the request
soup = BeautifulSoup(htmldoc,'html.parser')
# soup is object of BeautifulSoup
wordlist = soup.find_all('span',{'class':'TermText qWord lang-en'})
meaningslist = soup.find_all('span',{'class':'TermText qDef lang-en'})
words = []
meanings = []
for tag in wordlist:
words.append(tag.get_text())
for tag in meaningslist:
meanings.append(tag.get_text())
index = randrange(0,737)
wo=words[index]
me=meanings[index]
w='"'+wo.upper()+'"'
m='"'+me.upper()+'"'
rest_command = "notify-send -i gre_logo.jpg "+w+" "+m
os.system(rest_command)
time.sleep(1)
say(words[index])
time.sleep(1)
say('Means: ')
say(meanings[index])
time.sleep(1)
say('This word has been added to list of learnt words.')
w='"'+wo+'"'
w="Word: "+w;
command="echo "+w+" >> learnt.txt"
os.system(command)
m='"'+me+'"'
m="Meaning: "+m;
command="echo "+m+" >> learnt.txt"
os.system(command)
line='"-----------------------"';
command="echo "+line+" >> learnt.txt"
os.system(command)
time.sleep(1)
say('Do you want to learn the pronunciation of a different word')
choice=raw_input("Do you want to learn the pronunciation of a different word?(y/n) ")
time.sleep(1)
if(choice=="y" or choice=="Y"):
say('Enter a word below whose pronunciation you want to know: ')
pronun=raw_input("Enter word here- ")
time.sleep(1)
say('pronounced as: ')
say(pronun)
time.sleep(1)
m="Asked pronunciation of: "+pronun;
m='"'+m+'"'
command="echo "+m+" >> learnt.txt"
os.system(command)
line='"-----------------------"';
command="echo "+line+" >> learnt.txt"
os.system(command)
print "File containing learnt words is learnt.txt"