-
Notifications
You must be signed in to change notification settings - Fork 0
/
alumnisearch.py
96 lines (62 loc) · 1.68 KB
/
alumnisearch.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
import sys
from PyQt4 import QtGui, QtCore
from bs4 import BeautifulSoup as soup
from urllib2 import Request,urlopen,HTTPError
import time
from xgoogle.search import GoogleSearch , SearchError
import httplib
import webbrowser
class GUI(QtGui.QWidget):
def __init__(self):
super(GUI,self).__init__()
self.initGUI()
def google(self,text):
try:
print "Trying to search for "+text
g1 = GoogleSearch(text)
g1.results_per_page = 25
results = g1.get_results()
if len(results)==0:
print "No search result!!"
else:
print "Results FOund!!"
print type(results)
print len(results)
for res in results[:2]:
time.sleep(1)
url = res.url.encode("utf8")
response = self.search(url)
if response == "Kgpian":
self.close()
break
except SearchError, e:
print "Failed Once"
except HTTPError:
print "Oops"
def initGUI(self):
self.btn = QtGui.QPushButton('Input Name',self)
self.btn.move(20,20)
self.btn.clicked.connect(self.showDialog)
self.setWindowTitle('Search')
self.setGeometry(300,300,250,150)
self.show()
def showDialog(self):
text,ok = QtGui.QInputDialog.getText(self,'Input','Enter The search term')
if ok:
self.text = str(text)
self.google(self.text)
def search(self,url):
request = Request(url,headers = {'User-Agent': 'Mozilla/5.0'})
data = urlopen(request).read()
if "Kharagpur" in data:
print "Kgpian"
# print "Url opened in your browser"
# webbrowser.open_new_tab(url)
return "Kgpian"
def main():
app = QtGui.QApplication(sys.argv)
obj = GUI()
sys.exit(app.exec_())
if __name__ == '__main__':
#httplib.HTTPConnection.debuglevel = 1
main()