Permalink
Browse files

Added basic styling and thumbnails.

  • Loading branch information...
1 parent fad9a89 commit 52e47cb3c918829a9944d74a08a30921b0feb295 @voodoochild committed Dec 9, 2011
Showing with 70 additions and 16 deletions.
  1. +18 −11 app.py
  2. +44 −4 static/css/readnext.css
  3. +8 −1 templates/index.html
View
@@ -1,4 +1,4 @@
-from flask import Flask, render_template
+from flask import Flask, render_template, abort
import random
import requests
import json
@@ -8,7 +8,7 @@
app = Flask(__name__)
app.config.from_object(__name__)
-@app.route('/')
+@app.route('/', methods=['GET'])
def index():
"""Index view."""
feeds = []
@@ -17,9 +17,9 @@ def index():
add_feed(feeds, 'Latest sport', 'sport')
add_feed(feeds, 'Latest music', 'music')
random.shuffle(feeds)
- response = render_template('index.html', feeds=feeds)
- # set max-age http header
- return response
+ if not feeds:
+ abort(404)
+ return render_template('index.html', feeds=feeds)
def add_feed(feeds, title, section):
"""Adds a feed to be obtained and outputted."""
@@ -45,14 +45,21 @@ def process_json(data):
data = json.loads(data)
results = []
for result in data['response']['results']:
- results.append({
- 'title': result['webTitle'],
- 'url': result['webUrl'],
- #'thumbnail': result['fields']['thumbnail']
- })
+ results.append(build_article_dict(result))
return results
-
return False
+def build_article_dict(json):
+ """Parses supplied JSON to build a dictionary for an article."""
+ article = {
+ 'title': json['webTitle'],
+ 'url': json['webUrl'],
+ }
+ try:
+ article['thumbnail'] = json['fields']['thumbnail']
+ except KeyError:
+ pass
+ return article
+
if __name__ == "__main__":
app.run(debug=True)
@@ -1,5 +1,45 @@
-.hidden {
- //position: absolute;
- //left: -9999px;
- opacity: .25;
+.read-next {
+ border: 3px solid #ededed;
+ border-radius: 10px;
+ font: normal 16px/1 Ubuntu, sans-serif;
+ padding: 5px;
+ width: 620px;
+}
+
+.read-next .hidden {
+ position: absolute;
+ left: -9999px;
+}
+
+.read-next a,
+.read-next a:visited,
+.read-next a:active,
+.read-next a:hover {
+ color: #005689;
+ text-decoration: none;
+}
+
+.read-next ul {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+
+.read-next ul li {
+ clear: both;
+ margin-bottom: 10px;
+ overflow: hidden;
+}
+
+.read-next ul li img {
+ float: left;
+}
+
+.read-next ul li h3 {
+ float: left;
+ font-size: 14px;
+ font-weight: normal;
+ line-height: 1.5;
+ margin-left: 10px;
+ width: 70%;
}
@@ -10,7 +10,14 @@
<ul>
{% for article in feed.articles %}
<li>
- <a href="{{ article.url }}">{{ article.title }}</a>
+ <a href="{{ article.url }}" title="{{ article.title|safe }}">
+ {% if article.thumbnail %}
+ <img src="{{ article.thumbnail }}">
+ {% else %}
+ <img src="http://placekitten.com/g/140/84">
+ {% endif %}
+ <h3>{{ article.title|safe }}</h3>
+ </a>
</li>
{% endfor %}
</ul>

0 comments on commit 52e47cb

Please sign in to comment.