Skip to content

Commit

Permalink
Merge /var/home/sf/pysoso
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Jones committed Dec 21, 2010
2 parents 3ce51a7 + e9348f0 commit 9dd1f76
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import urllib2
import urlparse
import feedparser
import lxml.html
# import lxml.html
import email.utils
import sqlite3
import xml.dom.minidom
Expand Down
72 changes: 58 additions & 14 deletions pysoso.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import psutil
import werkzeug
import sys
import os
import re

from sqlite3 import dbapi2 as sqlite3
Expand All @@ -28,7 +30,9 @@

# configuration
# DATABASE = 'pysoso.db'
DATABASE = '/var/www/vhosts/ideoforms.com/apps/pysoso/pysoso.db'
# DATABASE = '/var/www/vhosts/ideoforms.com/apps/pysoso/pysoso.db'
DATABASE = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "pysoso.db")
# DATABASE = '/var/www/vhosts/ideoforms.com/apps/pysoso/pysoso.db'
PER_PAGE = 30
DEBUG = True
SECRET_KEY = 'development key'
Expand Down Expand Up @@ -221,22 +225,32 @@ def bookmark_import():
if 'user_id' not in session:
abort(401)

if request.method == 'POST':
opml = request.files['file'].read()
error = ""
if request.method == 'GET':
return render_template('bookmark/import.html')

opml = request.files['file'].read()
bookmarks = []
error = None

try:
bookmarks = psutil.parse_opml(opml)
except Exception, e:
return render_template("bookmark/import.html", error = "Import failed, sorry! (%s)" % e)

for bookmark in bookmarks:
bookmark["imported"] = False
try:
bookmarks = psutil.parse_opml(opml)
for bookmark in bookmarks:
psutil.feed_bookmark(g.db, session["user_id"], bookmark["url"], bookmark["rss"], bookmark["title"])
flash("Successfully imported %d bookmarks." % len(bookmarks))

psutil.feed_bookmark(g.db, session["user_id"], bookmark["url"], bookmark["rss"], bookmark["title"])
bookmark["imported"] = True
except Exception, e:
error = "Import failed, sorry! (%s)" % e
bookmark["exception"] = e

return render_template('home.html', error = error)

else:
return render_template('bookmark/import.html')
bookmarks_imported = filter(lambda n: n["imported"], bookmarks)
bookmarks_failed = filter(lambda n: not n["imported"], bookmarks)

flash("Successfully imported %d bookmarks." % len(bookmarks_imported))

return render_template('bookmark/import_done.html', bookmarks_imported = bookmarks_imported, bookmarks_failed = bookmarks_failed)

@app.route('/bookmark/export', methods = ['GET', 'POST'])
def bookmark_export():
Expand All @@ -252,6 +266,19 @@ def bookmark_export():
else:
return render_template('bookmark/export.html')

@app.route('/bookmark/mark/<int:value>')
def mark(value):
"""Mark all bookmarks as fresh or stale"""
if 'user_id' not in session:
abort(401)

if (value == 0 or value == 1):
g.db.execute('update bookmark set stale = ? where user_id = ?', [ value, session['user_id'] ])
g.db.commit()
flash("bookmarks updated successfully.")

return redirect(url_for('home'))

@app.route('/login', methods=['GET', 'POST'])
def login():
"""Logs the user in."""
Expand Down Expand Up @@ -312,6 +339,23 @@ def register():

return render_template('register.html', error=error)

@app.route('/lost', methods = ['GET', 'POST'])
def lost():
"""Sends out a lost password reminder."""
if g.user:
return redirect(url_for('home'))

if request.method == 'GET' or not request.form['username']:
return render_template("lost.html")
else:
rv = g.db.execute('select * from user where username = ?',
[ request.form['username'] ]).fetchone()
if not rv:
return render_template("lost.html", error = "sorry, couldn't find that username.")

flash("a new password has been sent out. it should be with you within a few minutes.")
return render_template("lost.html")

@app.route('/about')
def about():
"""About page"""
Expand Down
1 change: 1 addition & 0 deletions static/pysoso.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ $(function()
$('#bookmarks .bookmark').bind('click', function () {
$(this).parents("li").hide("slow");
});

});
7 changes: 6 additions & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,14 @@ input, textarea
opacity: 1.0;
}

.controls
{
color: #999;
}

.controls a
{
color: #888;
color: #666;
}
.controls a.active
{
Expand Down
7 changes: 5 additions & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ <h2>Stale <a href="#" id="bookmarks_show"><img src="{{ url_for("static", filenam
{% endif %}

</div>
{% if stale or bookmnarks %}
{% if stale or bookmarks %}
<hr />
<div class="controls">
<a href="#" id="edit">edit bookmarks</a>
<a href="#" id="edit">edit bookmarks</a> |
mark all as:
<a href="{{ url_for("mark", value = 0) }}" id="mark_fresh">fresh</a>,
<a href="{{ url_for("mark", value = 1) }}" id="mark_stale">stale</a>
</div>
{% endif %}

Expand Down

0 comments on commit 9dd1f76

Please sign in to comment.