Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.0

  • Loading branch information...
commit be8bdfe47e737fd27742552d7106ae7f11cf4cd3 1 parent e6f3772
@sharms authored
View
64 homepage.py
@@ -28,6 +28,10 @@
print app
app.config.from_object(__name__)
+@app.template_filter('datetimeformat')
+def datetimeformat(value, format='%Y-%m-%d %H:%M'):
+ return value.strftime(format)
+
def connect_db():
"""Returns a new connection to the sqlite database"""
return sqlite3.connect(app.config['DATABASE'], detect_types=sqlite3.PARSE_DECLTYPES)
@@ -35,6 +39,7 @@ def connect_db():
def init_db():
"""Create the database if it doesn't exist"""
if not os.path.isfile(app.config['DATABASE']):
+ print "DB disappeared, making a new one"
f = app.open_resource('schema.sql')
db = connect_db()
db.cursor().executescript(f.read())
@@ -47,20 +52,25 @@ def query_db(query, args=(), one = False):
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
-def format_datetime(timestamp):
- return datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d @ %H:%M')
-
def populate_database():
+ init_db()
if data_is_stale():
load_twitter()
load_github()
+ load_wordpress()
+ load_picasa()
def data_is_stale():
"""Find the last entry in the sqlite database to determine if we need to
refresh the data. This stops us from pulling them each request"""
- last_updated = g.db.cursor().execute('select last_refresh from entries order by last_refresh desc limit 1').fetchone()[0]
- if (datetime.now() - last_updated).seconds > 5000:
+ try:
+ last_updated = g.db.cursor().execute('select last_refresh from entries order by last_refresh desc limit 1').fetchone()[0]
+ except:
return True
+
+ if not last_updated or (datetime.now() - last_updated).seconds > 10800:
+ return True
+
return False
def load_twitter():
@@ -69,15 +79,51 @@ def load_twitter():
for entry in twitter.entries:
print entry
- g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?)',
+ g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?, ?)',
(None,
entry['link'],
+ "http://www.sharms.org/static/twitter_1.png",
entry['summary'],
"twitter",
datetime.strptime(entry['updated'][:-6], '%a, %d %b %Y %H:%M:%S'),
datetime.now()))
g.db.commit()
+
+def load_picasa():
+ picasa = feedparser.parse("http://picasaweb.google.com/data/feed/base/user/thisdyingdream/albumid/5501252408388252785?alt=rss&kind=photo&hl=en_US")
+ g.db.cursor().execute('DELETE FROM entries WHERE source = "picasa"')
+
+ for entry in picasa.entries:
+ print entry
+ g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?, ?)',
+ (None,
+ entry['link'],
+ "http://www.sharms.org/static/picture.png",
+ entry['media_description'],
+ "picasa",
+ datetime.strptime(entry['updated'][:-6], '%Y-%m-%dT%H:%M:%S'),
+ datetime.now()))
+
+ g.db.commit()
+
+
+def load_wordpress():
+ wordpress = feedparser.parse("http://www.sharms.org/blog/feed/")
+ g.db.cursor().execute('DELETE FROM entries WHERE source = "wordpress"')
+
+ for entry in wordpress.entries:
+ print entry
+ g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?, ?)',
+ (None,
+ entry['link'],
+ "http://www.sharms.org/static/wordpress.png",
+ entry['title'],
+ "wordpress",
+ datetime.strptime(entry['updated'][:-6], '%a, %d %b %Y %H:%M:%S'),
+ datetime.now()))
+
+ g.db.commit()
def load_github():
github = feedparser.parse("http://github.com/sharms.atom")
@@ -85,9 +131,10 @@ def load_github():
for entry in github.entries:
print entry
- g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?)',
+ g.db.cursor().execute('INSERT INTO entries VALUES (?, ?, ?, ?, ?, ?, ?)',
(None,
entry['link'],
+ "http://www.sharms.org/static/cog.png",
entry['title'],
"github",
datetime.strptime(entry['updated'][:-6], '%Y-%m-%dT%H:%M:%S'),
@@ -108,7 +155,8 @@ def after_request(response):
@app.route('/')
def index():
populate_database()
- return render_template('index.html')
+ results = query_db("select * from entries order by updated desc")
+ return render_template('index.html', results = results)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=443)
View
3  schema.sql
@@ -3,7 +3,8 @@ drop table if exists entries;
create table entries (
id integer primary key autoincrement,
url string not null,
- experpt string not null,
+ image_url string not null,
+ excerpt string not null,
source string not null,
updated timestamp not null,
last_refresh timestamp not null);
View
11 static/sharms.css
@@ -1,2 +1,9 @@
-body { font-family: 'Georgia', serif; font-size: 15px; color: #000; }
-
+body { font-family: 'Georgia', serif; font-size: 15px; color: #000;
+ text-align: left; }
+ul { margin-left: 0; }
+li { list-style-type: none; margin-left: 0; }
+.li-img { vertical-align: text-top; margin-right: 3px; }
+#about { background-color: #EEE; }
+#about div { padding: 5px; }
+#footer { text-align: center; font-size: 70%; font-style: italic; }
+#resources li { list-style-type: square; margin-left: 1em; }
View
44 templates/index.html
@@ -1 +1,43 @@
-Big huge tes
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>Steven Harms</title>
+ <link rel="stylesheet" href="http://www.sharms.org/static/reset.css" />
+ <link rel="stylesheet" href="http://www.sharms.org/static/text.css" />
+ <link rel="stylesheet" href="http://www.sharms.org/static/960.css" />
+ <link rel="stylesheet" href="http://www.sharms.org/static/sharms.css" />
+ </head>
+ <body>
+ <div class="container_12">
+ <div class="grid_12" id="header">
+ <h1>Steven Harms</h1>
+ </div>
+ <div class="clear"></div>
+ <div class="grid_8" id="rss-updates">
+ <h2>Activities</h2>
+ <ul>
+ {% for result in results %}
+ <li><img src="{{ result.image_url }}" alt="{{ result.source }}" title="{{ result.source }}" class="li-img" /><i style="font-size: 78%;">{{ result.updated|datetimeformat }}</i> {{ result.excerpt }} <a href="{{result.url}}" style="font-size: 78%">more</a></li>
+ {% endfor %}
+ </ul>
+ </div>
+ <div class="grid_4" id="about">
+ <div>
+ <h2>About</h2>
+ <p>Steven Harms (sharms) is a open source hacker, system administrator and programmer.</p>
+ <h2>Resources</h2>
+ <ul id="resources">
+ <li><a href="http://www.sharms.org/blog">Blog</a></li>
+ <li><a href="http://www.github.com/sharms">Github</a></li>
+ <li><a href="http://www.twitter.com/stevenharms">Twitter</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="clear"></div>
+ <div class="grid_12" id="footer">
+ <p>(c) 2010 Steven Harms. Powered by <a href="http://flash.pocoo.org">Flask</a>. Icons provided by <a href="http://www.fatcow.com/free-icons/">Fatcow</a></p>
+ </div>
+ </div>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.