forked from ideamonk/Web2Hunter-GAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
executable file
·93 lines (76 loc) · 2.4 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
89
90
91
92
'''
index.py I shall do nothing but render the interface
'''
import os
import random
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import web2hunter as WH
from preparefood import preparefood, customfood
class MainHandler(webapp.RequestHandler):
tPath = os.path.join( os.path.dirname (__file__), "templates" )
def get(self):
todo = self.request.get('getname')
if (todo == 'true'):
if (self.request.headers.get('Referer') != None):
# stop others from stealing your bandwidth
#if (self.request.headers.get('Referer').find('web2hunter.appspot.com')!=-1):
# return a possible domain name
sessionkey = self.request.get('sessionkey')
#seedfood = self.request.get('seedfood')
possiblename = WH.genName(sessionkey)
while (possiblename == ""):
possiblename = WH.genName(sessionkey)
# lets sanitize the possible name
# for sometime we get the response header for some reason -
# Content-Type: text/html; charset=utf-8 Cache-Control: ... blabla
# well a foo.split()[-1] would help
# food for javascript + sanitization
self.response.out.write (possiblename.split()[-1])
#else:
#self.response.out.write ("nothing for you");
else:
self.response.out.write ("nothing for you");
else:
custom = self.request.get('custom')
if custom == 'search':
name = self.request.get('name')
sessionkey, np = customfood(name)
words = name
newstitle = None
newslink = None
newsdesc = None
else:
# prepare food
try:
sessionkey, words, news, np = preparefood()
newstitle = news[0]
newslink = news[1]
newsdesc = news[2]
words = " ".join(words)
except Exception:
sessionkey = None
words = None
newstitle = None
newslink = None
newsdesc = None
np = None
if np:
self.redirect("/?rnd=", str(random.random()))
template_values = {
'sessionkey': sessionkey,
'words': words,
'newstitle': newstitle,
'newslink': newslink,
'newsdesc': newsdesc,
}
# render the template
outstr = template.render (
self.tPath + '/index.html', template_values )
self.response.out.write (outstr)
def main():
application = webapp.WSGIApplication( [('/.*',MainHandler)], debug=True )
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()