Skip to content

Instantly share code, notes, and snippets.

@shyang
Created May 6, 2012 07:18
Show Gist options
  • Save shyang/2620743 to your computer and use it in GitHub Desktop.
Save shyang/2620743 to your computer and use it in GitHub Desktop.
解决Dropbox中国无法及时自动同步的问题
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
参考:解决Dropbox中国无法及时自动同步的问题
http://www.chinagfw.org/2012/04/dropbox.html
ping notify17.dropbox.com => 199.47.218.150
/etc/hosts:
127.0.0.1 notify17.dropbox.com
sudo python3 dropbox.py # need to listen on port 80
'''
import logging
from tornado.ioloop import IOLoop
from tornado.httpclient import AsyncHTTPClient
from tornado.web import Application, RequestHandler, asynchronous
from tornado.options import parse_command_line
class HomeHandler(RequestHandler):
def get(self):
self.set_header('Content-Type', 'text/plain')
self.write('Hello from Tornado!')
class NotifyHandler(RequestHandler):
@asynchronous
def get(self):
self.set_header('Content-Type', 'text/plain')
url = 'http://199.47.218.150' + self.request.uri
logging.info(url)
client = AsyncHTTPClient()
client.fetch(url, self.handle_response, request_timeout=100.0)
def handle_response(self, response):
if response.error:
logging.info('can not connect.')
self.write('{\'ret\': \'new\'}')
else:
logging.info('connect successfully: %s', response.body)
self.write(response.body)
self.finish()
def main():
parse_command_line() # enable_pretty_logging
application = Application([
(r'/subscribe', NotifyHandler),
(r'/.*', HomeHandler),
], debug=True)
application.listen(80)
IOLoop.instance().start()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment