My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#




import wsgiref.handlers
import codecs
import getopt
import sys
import twitter
import configs
from google.appengine.ext import webapp
from pyamf.remoting.gateway.google import WebAppGateway

api = twitter.Api(username=configs.TWITTER_USER, password=configs.TWITTER_PWD)

class MainHandler(webapp.RequestHandler):
def get(self):
statuses = api.GetFriendsTimeline()
self.response.out.write('<html><body>')
self.response.out.write("""
<form action="/" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="say"></div>
</form>
""")
for status in statuses:
img = '<img src="' + status.user.profile_image_url + '" />'
self.response.out.write('<div>%s %s: %s</div>' % (img, status.user.name, status.text))
self.response.out.write("""
</body>
</html>
""")

def post(self):
message = self.request.get('content')
self.response.out.write(message)
statuses = api.PostUpdate(unicode(message))
self.redirect('/')

class PhotoHandler(webapp.RequestHandler):
def get(self):
statuses = api.GetPublicTimeline()
self.response.out.write('<html><body>')
for status in statuses:
self.response.out.write('<div>%s: %s</div>' % (status.user.name, status.text))
self.response.out.write("""
</body>
</html>
""")

def echo(data):
statuses = api.GetFriendsTimeline()
first = "<tweet>\n"
content = ''
for status in statuses:
content += ('<status>\n')
content += ('<img src="%s" />\n' % (status.user.profile_image_url))
content += ('<p class="name">%s</p>\n' % (str(status.user.name).strip()))
content += ('<p class="status">%s</p>\n' % (status.text))
content += ('</status>\n')
last = "</tweet>"
return first + content + last

class SampleXml(webapp.RequestHandler):
def get (self):
statuses = api.GetFriendsTimeline()
first = "<tweet>\n"
content = ''
for status in statuses:
content += ('<status>\n')
content += ('<img src="%s" />\n' % (status.user.profile_image_url))
content += ('<p class="name">%s</p>\n' % (str(status.user.name).strip()))
content += ('<p class="status">%s</p>\n' % (status.text))
content += ('</status>\n')
last = "</tweet>"
self.response.out.write(first + content + last)

services = {
'echo': echo,
}

def main():
application = webapp.WSGIApplication([
('/', MainHandler),
('/xml/', SampleXml),
('/flash/', WebAppGateway(services))
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
main()

Change log

r1982 by tissi0708 on Apr 11, 2009   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r1978 by surgo.jp on Apr 11, 2009   Diff
marge echo
r1974 by fukuzo on Apr 11, 2009   Diff
[No log message]
r1971 by surgo.jp on Apr 11, 2009   Diff
add get post request
All revisions of this file

File info

Size: 3268 bytes, 108 lines
Powered by Google Project Hosting