-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.py
More file actions
executable file
·95 lines (77 loc) · 3.42 KB
/
code.py
File metadata and controls
executable file
·95 lines (77 loc) · 3.42 KB
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
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import web
import re
from goparse.search import GoogleSearch
urls = ('/','index',
'/newsearch','search',
'/unavailable','sorry')
render = web.template.render("template/")
app = web.application(urls,globals())
class index:
"""
"""
def GET(self):
layout = {
's':'''<span class="mytop_n">Smart</span><a href="javascript:_sq('w');" class="mytop_navi">Web</a><a href="javascript:_sq('n');" class="mytop_navi">News</a><a href="javascript:_sq('v');" class="mytop_navi">Visualization</a>''',
'w':"""<a href="javascript:_sq('s');" class="mytop_navi">Smart</a><span class="mytop_n">Web</span><a href="javascript:_sq('n');" class="mytop_navi">News</a><a href="javascript:_sq('v');" class="mytop_navi">Visualization</a>""",
'n':"""<a href="javascript:_sq('s');" class="mytop_navi">Smart</a><a href="javascript:_sq('w')" class="mytop_navi">Web</a><span class="mytop_n">News</span><a href="javascript:_sq('v');" class="mytop_navi">Visualization</a>""",
'v':"""<a href="javascript:_sq('s');" class="mytop_navi">Smart</a><a href="javascript:_sq('w');" class="mytop_navi">Web</a><a href="javascript:_sq('n');" class="mytop_navi">News</a><span " class="mytop_n">Visualization</span>"""
}
q = web.input()
if q and q.t in ['s','w','n','v']:
guider = layout[q.t]
elif not q:
guider = layout['s']
else:
raise web.seeother("/")
html = web.template.frender("template/index.html",globals={'sun':guider})
#return guider
#html._globals = {'sun':guider}
#html.globals['time'] = '1'
# s=web.template.render("template/index.html",{"sun":guider})
return html()
class search:
"""
"""
def GET(self):
query = web.input()
if query and query.t and query.key:
if query.t == 's':
rawstr = r"""p://(\S*link.php\?ref=\w*)"""
compile_obj = re.compile(rawstr)
gs = GoogleSearch("link.php?ref="+query.key.encode('utf-8'))
gs.results_per_page = 10
if query.has_key('start'):
#return query.start
gs.page = int(query.start)/gs.results_per_page
else:
gs.page = 1
results = gs.get_results()
data = []
for res in results:
match_obj = compile_obj.search(res.desc)
if match_obj:
url = match_obj.group(1)
if url.find("http://") > 0:
url = url[url.find("http://"):len(url)]
else:
url = "http://"+url
else:
url = res.url
data.append([res.title,url])
html = web.template.frender("template/newsearch.html",globals={'data':data,'key':query.key})
# html.globals['data'] = data
# html.globals['key'] = query.key
return html()
else:
raise web.seeother("/unavailable")
else:
raise web.seeother("/unavailable")
return results()
class sorry:
def GET(self):
html = web.template.frender("template/unavailable.html")
return html()
if __name__ == "__main__":
app.run()