--- /dev/null
+#!/usr/bin/env python
+#
+# This small script adds daily actions for every user.
+# It is run by cron
+
+from pymongo import Connection
+from pymongo.objectid import ObjectId
+import random
+import models
+
+connection = Connection()
+db = connection.fuzzr
+random.seed(None)
+
+users = db.users
+actions = db.actions
+
+def get_random_action():
+ a = actions.find()
+ r = True
+ for i in range(random.randint(0, actions.count())):
+ r = a.next()
+
+ return r
+
+for user in users.find():
+ act = get_random_action()
+ while (act["_id"] in user["actions-accomplished"]) == True:
+ act = get_random_action()
+
+ models.user_has_done(user["username"], act)
+
--- /dev/null
+import web
+from web import form
+import models
+from pymongo import Connection
+from pymongo.objectid import ObjectId
+
+
+web.config.debug = False
+
+urls = (
+ '/', 'index',
+ '/add/', 'add',
+ '/page/(.+)/', 'page',
+ '/feed/(.+)/', 'feed',
+ '/login/', 'login',
+ '/logout/', 'logout',
+)
+
+
+app = web.application(urls, globals())
+session = web.session.Session(app, web.session.DiskStore('sessions'))
+render = web.template.render('templates/', base='layout')
+
+connection = Connection()
+db = connection.fuzzr
+users = db.users
+actions = db.actions
+
+def logged():
+ if hasattr(session, 'loggedin') == True:
+ return True
+ else:
+ return False
+
+def notfound():
+ return web.notfound(render.error("404 - Unable to find the requested page"))
+
+class index:
+ def GET(self):
+ return render.index()
+
+
+class add:
+ def __init__(self):
+ self.add_form = form.Form(
+ form.Textbox("title"),
+ form.Textbox("description"))
+
+ def GET(self):
+
+ if not logged():
+ return render.error("You don't have the priviledges to add actions")
+
+ form = self.add_form()
+ return render.add(form)
+
+ def POST(self):
+ form = self.add_form()
+ if not form.validates():
+ return render.add(form)
+ else:
+ act = models.create_post(form.d.title, form.d.description)
+ actions.insert(act)
+ raise web.seeother("/add/")
+
+class page:
+ def GET(self, name):
+# if logged() == False:
+# return render.error("You are not logged in")
+
+ user = users.find_one({"username" : name})
+
+ if user == None:
+ return render.error("Page not found")
+
+ l = list() # We need to give a list because mongo returns an iterator.
+
+ for id in user["actions-accomplished"]:
+ act = actions.find_one({"_id" : ObjectId(id)})
+ if act != None:
+ l.append(act)
+
+
+ return render.page(l, name)
+
+class feed:
+ def GET(self, name):
+
+ user = users.find_one({"username" : name})
+ if user == None:
+ return render.error("Page not found")
+
+ l = list() # We need to give a list because mongo returns an iterator.
+
+ for id in user["actions-accomplished"]:
+ act = actions.find_one({"_id" : ObjectId(id)})
+ if act != None:
+ l.append(act)
+
+ feed_render = web.template.render('templates/')
+ web.header('Content-Type', 'application/rss+xml')
+ return feed_render.feed(l, name)
+
+
+class login:
+
+ def __init__(self):
+ self.login_form = form.Form(
+ form.Textbox("username"),
+ form.Textbox("password"))
+
+ def GET(self):
+ form = self.login_form()
+ return render.login(form, None)
+
+ def POST(self):
+ form = self.login_form()
+ if not form.validates():
+ return render.login(form, None)
+ else:
+ user = users.find_one({"username" : form.d.username})
+ if user == None:
+ return render.login(form, "Incorrect username or password")
+ else:
+ session.loggedin = True
+ session.username = user["username"]
+
+ raise web.seeother("/page/" + user["username"] + "/")
+
+class logout:
+ def GET(self):
+ session.kill()
+ raise web.seeother("/")
+
+web.internalerror = web.debugerror
+
+if __name__ == "__main__":
+ app.run()
+
--- /dev/null
+from pymongo import Connection
+from pymongo.objectid import ObjectId
+
+
+connection = Connection()
+
+db = connection.fuzzr
+
+users = db.users
+actions = db.actions
+
+def create_post(title, desc, for_musicians=0):
+ return {"title": title,
+ "description": desc,
+ "for-musicians": for_musicians)
+ }
+
+def create_user(username, passwd, is_root, is_musician=0):
+ return {"username": username,
+ "password": passwd,
+ "actions-accomplished": [],
+ "is_root": is_root,
+ "is_musician": is_musician,
+ }
+
+def user_has_done(username, action):
+ user = users.find_one({"username" : username})
+
+ if user == None:
+ return
+
+ user["actions-accomplished"].append(action["_id"])
+ users.save(user, safe=True)
+
+# Simply insert a post and a root user
+def create_db(root, passwd):
+
+ ac = create_post("Wear something green", "Today you're gonna wear something green, to celebrate your irish ancestors")
+ actions.insert(ac)
+
+ us = create_user(root, passwd, 1)
+ users.insert(us)
+
+
--- /dev/null
+#!/bin/sh
+
+./mongo/bin/mongod --dbpath ./db
\ No newline at end of file
--- /dev/null
+body {
+ background-color: white;
+ font: 13.34px helvetica, arial, clean, sans-serif;
+ width: 750px;
+ margin: 0 auto;
+
+}
+
+#content {
+ font-size: 150%;
+ float: left;
+ width: 500px;
+ height:500px;
+}
+
+ul {
+
+}
+
+li {
+ list-style-type: none;
+ border: solid 1px;
+ padding: 2px;
+ padding-left: 5px;
+ padding-right: 5px;
+ margin: 20px;
+
+}
+#sidebar {
+ float: right;
+ width: 250px;
+ margin: 5px;
+}
+
+#footer {
+ clear:both;
+ text-align: center;
+}
--- /dev/null
+body {
+ background-color: white;
+ font: 13.34px helvetica, arial, clean, sans-serif;
+ font-size: small;
+ width: 750px;
+ margin: 0 auto;
+
+}
+
+#wrap {
+}
\ No newline at end of file
--- /dev/null
+$def with (form)
+
+<form name="main" method="post">
+$if not form.valid: <p class="error">Try again</p>
+$:form.render()
+<input type="submit" /> </form>
--- /dev/null
+$def with (error)
+
+$error
--- /dev/null
+$def with (actions, username)
+<xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+
+<channel>
+<title>$username Fuzzr RSS feed</title>
+<description></description>
+<link>http://fuzzr.org/page/$username/feed.xml</link>
+<lastBuildDate></lastBuildDate>
+<pubDate></pubDate>
+
+$for action in actions:
+ <item>
+ <title>$action["title"]</title>
+ <description>$action["description"]</description>
+ <link>http://fuzzr.org/page/$username/</link>
+ </item>
+
+</channel>
+</rss>
--- /dev/null
+$def with (actions, username)
+
+<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+
+<channel>
+<title>$username Fuzzr RSS feed</title>
+<description></description>
+<link>http://fuzzr.org/page/$username/feed.rss</link>
+<lastBuildDate></lastBuildDate>
+<pubDate></pubDate>
+
+$for action in actions:
+<item>
+<title>$action["title"]</title>
+<description>$action["description"]</description>
+<link>http://fuzzr.org/page/$username/</link>
+</item>
+
+</channel>
+</rss>
\ No newline at end of file
--- /dev/null
+<link rel="alternate" type="application/rss+xml"
+ href="/feed/karim/" title="RSS feed for My Page">
+
+<a href="/page/karim/">Page</a>
+<a href="/feed/karim/" type="application/rss+xml">Karim's feed</a>
+<a href="/login/">login</a>
+<a href="/logout/">logout</a>
+<a href="/add/">Add</a>
+
+<div class="content">
+Did you read the Diceman ? If not, you have to know that it's the story of a guy who decides
+to play everything with a dice. I feel a little anxious at the idea of doing something like
+that, but I thought "what if I had to do a random action, something incongruous, to get
+me out of my confort zone ?", and thus fuzzr was born.
+</div>
--- /dev/null
+<link rel="alternate" type="application/rss+xml"
+ href="/feed/karim/" title="RSS feed for My Page">
+
+<a href="/page/karim/">Page</a>
+<a href="/feed/karim/" type="application/rss+xml">Karim's feed</a>
+<a href="/login/">login</a>
+<a href="/logout/">logout</a>
+<a href="/add/">Add</a>
--- /dev/null
+$def with (content)
+<html>
+<head>
+ <title>Fuzzr</title>
+ <link rel="stylesheet" href="/static/style.css" type="text/css" />
+</head>
+<body>
+<div id="sidebar">
+ <a href="/">Home, home again</a>
+</div>
+<div id="content">
+ $:content
+</div>
+<div id="footer">
+ <tr>
+ <td>
+ <a href="/about/">About</a>
+ </td>
+ <td>
+ <a href="/tos/">Terms of service</a>
+ </td>
+ </tr>
+</div>
+</body>
+</html>
--- /dev/null
+$def with (content)
+<html>
+<head>
+ <title>Fuzzr</title>
+ <link rel="stylesheet" href="/static/style.css" type="text/css" />
+</head>
+<body>
+ <a href="/">Home, home again</a>
+ $:content
+</body>
+</html>
--- /dev/null
+$def with (form, error)
+
+<form name="main" method="post">
+$if not form.valid: <p class="error">Unable to log you, please retry</p>
+$if error: <p class="error">$error</p>
+$:form.render()
+<input type="submit" /> </form>
--- /dev/null
+$def with (form)
+
+<form name="main" method="post">
+$if not form.valid: <p class="error">Unable to log you, please retry</p>
+$:form.render()
+<input type="submit" /> </form>
--- /dev/null
+$def with (actions, username)
+
+<div class="content">
+$if username != None: <h1>$username's page</h1>
+ <ul>
+ $for action in actions:
+ <li>
+ <h3>$action["title"]</h3>
+ <p>$action["description"]</p>
+ </li>
+ </ul>
+</div>
--- /dev/null
+$def with (actions, username)
+
+<div class="content">
+$if username != None: <h1>$username's page</h1>
+ <ul>
+ $for action in actions:
+ <li>$action["description"]</li>
+ </ul>
+</div>
--- /dev/null
+$def with (actions, username)
+
+<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+
+<channel>
+<title>$username Fuzzr RSS feed</title>
+<description></description>
+<link>http://fuzzr.org/page/$username/feed.rss</link>
+<lastBuildDate></lastBuildDate>
+<pubDate></pubDate>
+
+$for action in actions:
+<item>
+<title>$action["title"]</title>
+<description>$action["description"]</description>
+<link>http://fuzzr.org/page/$username/</link>
+</item>
+
+</channel>
+</rss>
\ No newline at end of file
--- /dev/null
+$def with (actions, username)
+
+<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+
+<channel>
+<title>$username Fuzzr RSS feed</title>
+<description></description>
+<link>http://fuzzr.org/page/$username/feed.rss</link>
+<lastBuildDate></lastBuildDate>
+<pubDate></pubDate>
+
+$for action in actions:
+<item>
+<title>$action["title"]</title>
+<description>$action["description"]</description>
+<link>http://fuzzr.org/page/$username/</link>
+</item>
+
+</channel>
+</rss>
\ No newline at end of file