Permalink
Browse files

get favs ok.

  • Loading branch information...
1 parent ce7bc81 commit d553fb8d19793570dbad927ecb455aa843af3b7f @ydoovv ydoovv committed Oct 16, 2010
Showing with 275 additions and 1 deletion.
  1. +21 −1 main.py
  2. +197 −0 static/style.css
  3. +28 −0 templates/base.html
  4. +29 −0 templates/main.html
View
22 main.py
@@ -2,14 +2,34 @@
# -*- coding: utf-8 -*-
"""Run some bot jobs on GAE."""
+import os
+import re
+
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import urlfetch
from google.appengine.ext.webapp.util import run_wsgi_app
+from django.utils import simplejson as json
+from google.appengine.ext.webapp import template
class MainHandler(webapp.RequestHandler):
def get(self):
- self.response.out.write("<h1>I'm here =.=!</h1>")
+ id_ = self.request.get("id")
+ page = self.request.get("p")
+ if page == "": page = "1"
+ proxy = 'http://api.twitter.com/1/'
+ url = '%s/favorites/%s.json?page=%s' % (proxy, id_, page)
+ res = urlfetch.fetch(url)
+ favs = json.loads(res.content)
+ template_values = {"tweets": [], "id": id_, "page": int(page) + 1, "flashes":{"message": "Here is %s's favorites." % id_}}
+ for fav in favs:
+ tweet = fav["text"]
+ urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tweet)
+ for url in urls:
+ tweet = tweet.replace(url, '<a href="%s">%s</a>' % (url, url))
+ template_values["tweets"].append({"content":"%s" % tweet})
+ path = os.path.join(os.path.dirname(__file__), 'templates/main.html')
+ self.response.out.write(template.render(path, template_values))
def main():
application = webapp.WSGIApplication(
View
@@ -0,0 +1,197 @@
+body {
+ background: #CAECE9;
+ font-family: 'Trebuchet MS', sans-serif;
+ font-size: 14px;
+}
+
+a {
+ color: #26776F;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #333;
+ text-decoration: underline;
+}
+
+input[type="text"],
+input[type="password"] {
+ background: white;
+ border: 1px solid #BFE6E2;
+ padding: 2px;
+ font-family: 'Trebuchet MS', sans-serif;
+ font-size: 14px;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ color: #105751;
+}
+
+input[type="submit"] {
+ background: #105751;
+ border: 1px solid #073B36;
+ padding: 1px 3px;
+ font-family: 'Trebuchet MS', sans-serif;
+ font-size: 14px;
+ font-weight: bold;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ color: white;
+}
+
+div.page {
+ background: white;
+ border: 1px solid #6ECCC4;
+ width: 700px;
+ margin: 30px auto;
+}
+
+div.page h1 {
+ background: #6ECCC4;
+ margin: 0;
+ padding: 10px 14px;
+ color: white;
+ letter-spacing: 1px;
+ text-shadow: 0 0 3px #24776F;
+ font-weight: normal;
+}
+
+div.page div.navigation {
+ background: #DEE9E8;
+ padding: 4px 10px;
+ border-top: 1px solid #ccc;
+ border-bottom: 1px solid #eee;
+ color: #888;
+ font-size: 12px;
+ letter-spacing: 0.5px;
+}
+
+div.page div.navigation a {
+ color: #444;
+ font-weight: bold;
+}
+
+div.page h2 {
+ margin: 0 0 15px 0;
+ color: #105751;
+ text-shadow: 0 1px 2px #ccc;
+}
+
+div.page div.body {
+ padding: 10px;
+}
+
+div.page div.footer {
+ background: #eee;
+ color: #888;
+ padding: 5px 10px;
+ font-size: 12px;
+}
+
+div.page div.followstatus {
+ border: 1px solid #ccc;
+ background: #E3EBEA;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ padding: 3px;
+ font-size: 13px;
+}
+
+div.page ul.messages {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+div.page ul.messages li {
+ margin: 10px 0;
+ padding: 5px;
+ background: #F0FAF9;
+ border: 1px solid #DBF3F1;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ min-height: 48px;
+}
+
+div.page ul.messages li:hover {
+ background-color: #7EE8DE;
+}
+
+div.page ul.messages p {
+ margin: 0;
+}
+
+div.page ul.messages li .avatar{
+ float: left;
+ padding: 0 10px 0 0;
+}
+
+div.page ul.messages li .action{
+ float: right;
+ padding: 0 10px 0 0;
+ visibility: visible;
+}
+
+div.page ul.messages li .action:hover{
+ visibility: visible;
+}
+div.page ul.messages li small {
+ font-size: 0.9em;
+ color: #888;
+}
+
+div.page div.twitbox {
+ margin: 10px 0;
+ padding: 5px;
+ background: #F0FAF9;
+ border: 1px solid #94E2DA;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+}
+
+div.page div.twitbox h3 {
+ margin: 0;
+ font-size: 1em;
+ color: #2C7E76;
+}
+
+div.page div.twitbox p {
+ margin: 0;
+}
+
+div.page div.twitbox input[type="text"] {
+ width: 585px;
+}
+
+div.page div.twitbox input[type="submit"] {
+ width: 70px;
+ margin-left: 5px;
+}
+
+ul.flashes {
+ list-style: none;
+ margin: 10px 10px 0 10px;
+ padding: 0;
+}
+
+ul.flashes li {
+ background: #B9F3ED;
+ border: 1px solid #81CEC6;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ padding: 4px;
+ font-size: 13px;
+}
+
+div.error {
+ margin: 10px 0;
+ background: #FAE4E4;
+ border: 1px solid #DD6F6F;
+ -moz-border-radius: 2px;
+ -webkit-border-radius: 2px;
+ padding: 4px;
+ font-size: 13px;
+}
+
+.notfound {
+ text-align: center;
+}
View
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <title>digest-favs</title>
+ <link rel=stylesheet type=text/css href="/static/style.css">
+</head>
+<body>
+<div class=page>
+ <h1>Digest Your Twitter's Favorites</h1>
+ <div class=navigation>
+ <a href="/">Home</a> |
+ <a href="/about">About</a> |
+ </div>
+ {% if flashes %}
+ <ul class=flashes>
+ <li>{{ flashes.message }}</li>
+ </ul>
+ {% endif %}
+ <div class=body>
+ {% block body %}{% endblock %}
+ </div>
+ <div class=footer>
+ vvoody's. Powered by Google App Engine & Python.
+ </div>
+</div>
+</body>
+</html>
View
@@ -0,0 +1,29 @@
+{% extends "base.html" %}
+{% block title %}
+{% endblock %}
+
+{% block body %}
+<script type="text/javascript">
+</script>
+
+ <div class=twitbox>
+ <h3>Your twitter id?</h3>
+ <form action="/" method="get">
+ <p><input id="id" type="text" name="id" size=20><!--
+ --><input type="submit" value="Get favs!">
+ </form>
+ </div>
+
+<!-- tweets body -->
+ <ul class=messages id="messages_body">
+ {% for tweet in tweets %}
+ <li><p>
+ <span>{{ tweet.content }}</span>
+<!---->
+ {% endfor %}
+ </ul>
+
+<div style="float: right;">
+<a href="/?id={{ id }}&p={{ page }}">Next</a>
+</div><br />
+{% endblock %}

0 comments on commit d553fb8

Please sign in to comment.