-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretwite.py
34 lines (27 loc) · 1011 Bytes
/
retwite.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
import re
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api.urlfetch import fetch
class Twitter(webapp.RequestHandler):
def doit(self, method):
p = re.compile(r'retwite.appspot.com/search/')
if p.search(self.request.url):
url = p.sub('search.twitter.com/', self.request.url, 1)
else:
p = re.compile(r'retwite.appspot.com')
url = p.sub('twitter.com', self.request.url, 1)
r = fetch(url, self.request.body, method, self.request.headers)
self.response.set_status(r.status_code)
self.response.headers = r.headers
self.response.out.write(r.content)
def get(self):
self.doit('GET')
def delete(self):
self.doit('DELETE')
def post(self):
self.doit('POST')
application = webapp.WSGIApplication([('/.*', Twitter)], debug=False)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()