Permalink
Browse files

doing some pep8 cleanup

  • Loading branch information...
1 parent d855cc0 commit 513269102fc085bb4280ef2814d075f468077e5c @peterbe committed Sep 2, 2011
Showing with 21 additions and 104 deletions.
  1. +3 −5 app.py
  2. +0 −82 dotjs/twitter.com.js
  3. +18 −17 handlers.py
View
8 app.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import os
-import logging
import tornado.httpserver
import tornado.ioloop
import tornado.options
@@ -9,6 +8,7 @@
from tornado.options import define, options
import settings
from tornado_utils.routes import route
+import handlers
define("debug", default=False, help="run in debug mode", type=bool)
@@ -18,7 +18,7 @@
class Application(tornado.web.Application):
def __init__(self, database_name=None):
- handlers = route.get_routes()
+ routed_handlers = route.get_routes()
app_settings = dict(
title=settings.PROJECT_TITLE,
template_path=os.path.join(os.path.dirname(__file__), "templates"),
@@ -28,13 +28,11 @@ def __init__(self, database_name=None):
twitter_consumer_key=settings.TWITTER_CONSUMER_KEY,
twitter_consumer_secret=settings.TWITTER_CONSUMER_SECRET,
)
- super(Application, self).__init__(handlers, **app_settings)
+ super(Application, self).__init__(routed_handlers, **app_settings)
self.redis = redis.client.Redis(settings.REDIS_HOST,
settings.REDIS_PORT)
-import handlers
-
def main(): # pragma: no cover
tornado.options.parse_command_line()
View
@@ -1,82 +0,0 @@
-/* Version 0.1
- * 26 August 2011
- *
- * Copyright http://toocoolfor.me
- */
-
-
-function L() {
- if (window.console && window.console.log)
- console.log.apply(console, arguments);
-}
-
-var Lookup = (function() {
- var BASE_URL = 'http://toocoolfor.me';
-
- var screennames = [];
- function findScreenNames() {
- var new_screennames = [];
- $('a.tweet-screen-name').each(function(i, e) {
- var v = $.trim($(this).text());
- if (v && $.inArray(e, screennames) == -1) {
- screennames.push(v);
- new_screennames.push(v);
- }
- });
- return new_screennames;
- }
- return {
- search: function () {
- var names = findScreenNames();
- var your_screen_name = $.trim($('#screen-name').text());
- var data = {
- you: your_screen_name,
- usernames: names.join(',')
- };
- $.getJSON(BASE_URL + '/json', data, function (response) {
- if (response.ERROR) {
- alert(response.ERROR);
- return;
- }
- var screen_name, tag;
-
- $('div.tweet-content').each(function() {
- // if it's got one of those 'retweeted by <someoneyoufollow>'
- // then just skip
- if ($('.retweet-icon', this).size())
- return;
- screen_name = $('a.tweet-screen-name', this).text();
- // or if it's you
- if (screen_name == your_screen_name)
- return;
-
- if (response[screen_name]) {
- tag = $('<a>', {text: 'follows me'})
- .addClass('followsyou')
- .css('color', 'green');
- } else {
- tag = $('<a>', {text: 'too cool for me'})
- .addClass('followsyounot')
- .css('color', '#666');
- }
- tag
- .attr('href', BASE_URL + '?username=' + screen_name)
- .attr('target', '_blank')
- .attr('title', 'According to follows.me')
- .css('float', 'right')
- .css('padding-right', '30px')
- .css('font-size', '11px')
- .appendTo($('span.tweet-user-name', this));
-
- });
- });
- }
- }
-})();
-
-setTimeout(function() {
- Lookup.search();
- //$('a.tweet-screen-name').live(function() {
- // Lookup.search();
- //});
- }, 2*1000);
View
@@ -4,9 +4,10 @@
import tornado.web
from tornado.web import HTTPError
from tornado_utils.routes import route
-from tornado_utils.decorators import login_required
+#from tornado_utils.decorators import login_required
from tornado.escape import json_decode, json_encode
-import settings
+#import settings
+
class BaseHandler(tornado.web.RequestHandler):
@@ -16,7 +17,6 @@ def write_json(self, struct, javascript=False):
def write_jsonp(self, callback, struct):
self.set_header("Content-Type", "text/javascript; charset=UTF-8")
-# pprint(struct)
self.write('%s(%s)' % (callback, tornado.escape.json_encode(struct)))
def get_current_user(self):
@@ -74,9 +74,8 @@ def get(self, jsonp=False):
else:
self.jsonp = False
- print "USERNAMES"
- print usernames
-
+ #print "USERNAMES"
+ #print usernames
# All of this is commented out until I can figure out why cookie
# headers aren't sent from bookmarklet's AJAX code
@@ -138,7 +137,6 @@ def get(self, jsonp=False):
print "ACCESS_TOKEN"
print access_token
# See https://dev.twitter.com/docs/api/1/get/friendships/lookup
- print "Starting request",','.join(usernames)
self.twitter_request(
"/friendships/lookup",
screen_name=','.join(usernames),
@@ -157,7 +155,6 @@ def get(self, jsonp=False):
pprint(results)
self.finish()
-
def _on_lookup(self, result, this_username, data):
print "RESULT"
pprint(result)
@@ -201,6 +198,7 @@ class BaseAuthHandler(BaseHandler):
def get_next_url(self):
return '/'
+
@route('/auth/twitter/', name='auth_twitter')
class TwitterAuthHandler(BaseAuthHandler, tornado.auth.TwitterMixin):
@@ -223,9 +221,12 @@ def _on_auth(self, user_struct):
assert access_token
self.redis.set('username:%s' % username, json_encode(access_token))
#profile_image_url = user_struct.get('profile_image_url', None)
- self.set_secure_cookie("user", username.encode('utf8'), expires_days=30, path='/')
+ self.set_secure_cookie("user",
+ username.encode('utf8'),
+ expires_days=30, path='/')
self.redirect('/')
+
@route(r'/auth/logout/', name='logout')
class AuthLogoutHandler(BaseAuthHandler):
def get(self):
@@ -246,6 +247,7 @@ def get(self):
options['page_title'] = "Test the service"
self.render('test.html', **options)
+
@route('/following/(\w+)')
class FollowingHandler(BaseHandler, tornado.auth.TwitterMixin):
@@ -281,7 +283,7 @@ def _on_friendship(self, result, key, options):
if isinstance(result, bool):
value = result
else:
- logging.info("Result (%r): %r"%(key,result))
+ logging.info("Result (%r): %r" % (key, result))
if result and 'relationship' in result:
value = result['relationship']['target']['following']
if key and value is not None:
@@ -294,10 +296,10 @@ def _fetch_info(self, options, username=None):
username = options['username']
key = 'info:%s' % username
value = self.redis.get(key)
- if value=='null':value=None # temporary hack
if value is None:
- access_token = self.redis.get('username:%s' % options['this_username'])
+ access_token = self.redis.get('username:%s' %
+ options['this_username'])
access_token = json_decode(access_token)
self.twitter_request(
"/users/show",
@@ -356,7 +358,8 @@ def _set_ratio(self, options, key):
options['info'][value]['rank'] = _usernames.index(value)
except:
- logging.error("KEY=%r, VALUE=%r, options['info']=%s" % (key, value, pformat(options['info'])))
+ logging.error("KEY=%r, VALUE=%r, options['info']=%s" %
+ (key, value, pformat(options['info'])))
raise
@@ -366,13 +369,11 @@ class CoolestHandler(BaseHandler):
def get(self):
options = {}
user = self.get_current_user()
-# if not user:
-# self.redirect('/auth/twitter/')
-# return
key = 'ratios'
ratios = self.redis.zrange(key, 0, -1, withscores=True)
ratios.reverse()
options['ratios'] = ratios
options['user'] = user
- options['page_title'] = 'Coolest in the world! ...on Twitter ...using this site'
+ options['page_title'] = \
+ "Coolest in the world! ...on Twitter ...using this site"
self.render('coolest.html', **options)

0 comments on commit 5132691

Please sign in to comment.