Permalink
Browse files

Simplistic flask based app server

  • Loading branch information...
1 parent b0e791d commit a40ec4d782e673278eb038e5e78226f22cc05ce8 @yuvipanda yuvipanda committed Mar 14, 2012
Showing with 37 additions and 3 deletions.
  1. +35 −0 app.py
  2. +2 −3 refreshCache.bash
View
35 app.py
@@ -0,0 +1,35 @@
+from flask import Flask, redirect
+from random import choice
+from datetime import datetime
+import os.path
+
+DIR = os.path.dirname(__file__)
+
+allTitles = {}
+
+app = Flask(__name__)
+app.debug = True
+
+def urlForTitle(title):
+ return "//en.wikipedia.org/wiki/" + title
+
+def getTitles(cat):
+ def updateTitles():
+ f = open(os.path.join(DIR, cat))
+ allTitles[cat] = {
+ "lastupdate": datetime.now(),
+ "titles": [l.strip() for l in f.readlines()]
+ }
+
+ if cat not in allTitles:
+ updateTitles()
+
+ return allTitles[cat]['titles']
+
+@app.route('/r/<cat>/')
+def randomTitle(cat):
+ titles = getTitles(cat)
+ return redirect(urlForTitle(choice(titles)))
+
+if __name__ == '__main__':
+ app.run()
View
@@ -1,5 +1,4 @@
#!/bin/bash
CATEGORY=Unassessed_India_articles
-FILE=unassessed.txt
-curl -d "language=en&categories=$CATEGORY&depth=0&ns[1]=1&format=csv&doit=Do it\!" http://toolserver.org/~magnus/catscan_rewrite.php | sed 's/"Talk:\([^"]*\).*"/\1/' > $FILE.tmp
-mv $FILE.tmp $FILE
+curl -d "language=en&categories=$CATEGORY&depth=0&ns[1]=1&format=csv&doit=Do it\!" http://toolserver.org/~magnus/catscan_rewrite.php | sed 's/"Talk:\([^"]*\).*"/\1/' > $CATEGORY.tmp
+mv $CATEGORY.tmp $CATEGORY

0 comments on commit a40ec4d

Please sign in to comment.