-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinf.py
126 lines (92 loc) · 3.54 KB
/
inf.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users, urlfetch
from google.appengine.ext.webapp import template
from util import tmpl, add_user_to_context
from models import Videos, Twitter, NewsItem, Shout
import cgi
import settings
import urllib
import base64
class MainPage(webapp.RequestHandler):
def get(self):
context = { }
#context = add_user_to_context(context)
self.response.out.write(
template.render(tmpl('templates/twitter.html'),
context ))
import feedparser
from google.appengine.api import urlfetch
import datetime
class TwitterPage(webapp.RequestHandler):
def get(self):
t = Twitter.all()[0]
context = add_user_to_context({'keywords': t.keywords })
self.response.out.write(
template.render(tmpl('templates/twitter.html'),
context ))
class MapPage(webapp.RequestHandler):
def get(self):
context = { }
self.response.out.write(
template.render(tmpl('templates/map.html'),
context ))
class VideoPage(webapp.RequestHandler):
def get(self):
v = Videos.all()[0]
context = add_user_to_context({ 'users': v.users, 'searches': v.searches })
self.response.out.write(
template.render(tmpl('templates/video.html'),
context ))
class InitData(webapp.RequestHandler):
def get(self):
v = Videos(key_name='videos')
v.users = ["ShangoRBG","Halbertis","farhad43","abatebi","iranlover100","SasanShah1","Zendoaut","hadihadithegreat","saeidkermanshah"]
v.searches = ["iranelection","iran riot","tehran"]
v.put()
t = Twitter(key_name='twitter')
t.keywords = ['iranelection', 'tehran']
t.put()
self.response.out.write('init\'d')
class ShoutBox(webapp.RequestHandler):
def get(self):
items = db.GqlQuery("SELECT * FROM Shout ORDER BY date DESC LIMIT 25")
context = add_user_to_context({'shouts':items })
#context = add_user_to_context(context)
self.response.out.write(
template.render(tmpl('templates/shoutbox.html'),
context ))
class PostShout(webapp.RequestHandler):
def post(self):
text = cgi.escape(self.request.get('text'))
name = cgi.escape(self.request.get('name'))
s = Shout(text=text, name=name)
s.put()
# FIXME
apendix = ' #iranelection'
chars = 140 - len(apendix)
from secretsettings import twitter_password, twitter_username
payload= {'status' : text[:chars] + apendix, 'source' : "iranbreakingnews"}
payload= urllib.urlencode(payload)
base64string = base64.encodestring('%s:%s' % (twitter_username, twitter_password))[:-1]
headers = {'Authorization': "Basic %s" % base64string}
url = "http://twitter.com/statuses/update.xml"
result = urlfetch.fetch(url, payload=payload, method=urlfetch.POST, headers=headers)
self.redirect('/shoutbox/')
def get(self):
self.redirect('/shoutbox/')
application = webapp.WSGIApplication(
[
('/', TwitterPage ),
('/twitter/', TwitterPage),
('/map/', MapPage),
('/videos/', VideoPage),
#('/gnarf/', InitData),
('/shoutbox/', ShoutBox),
('/shoutbox/post/', PostShout),
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()