X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fsam.git;a=blobdiff_plain;f=rate-my-litreview.py;fp=rate-my-litreview.py;h=251ad6aee20e8608bccd72b12151427f1f051f3e;hp=0000000000000000000000000000000000000000;hb=a7d21e530f640a6e0f8493cfa9fded2c71b7c42d;hpb=0101621ac53853f3c9d0f0ad2873f2b65c2b6130 diff --git a/rate-my-litreview.py b/rate-my-litreview.py new file mode 100755 index 0000000..251ad6a --- /dev/null +++ b/rate-my-litreview.py @@ -0,0 +1,171 @@ +#!/usr/bin/python + +import sys +import os +import sqlite3 +import cgi +import smtplib +from email.mime.text import MIMEText +import datetime +import subprocess +import random + +# Setup a sqlite3 database before deploying: +# sqlite3 ratings.db +# sqlite> CREATE TABLE ratings(formalness, citeyness, reviewyness, accurateness, boringness, pointyness, overallness, version, time, message, page); +# Get rid of database by DROP TABLE or deleting the file + +target_email = "matches@ucc.asn.au" +secret_answers = ["No", "no"] +dbfile = "ratings.db" + +def print_form(name): + """ Print the form """ + f = open(name,"r") + for line in f.readlines(): + print(line) + f.close() + +def git_stamp(): + # Python is nice but sometimes you just need to bash it over the head + p = subprocess.Popen("git show | head --lines=1 | awk '{print $NF}'", stdout=subprocess.PIPE, shell=True) + return p.stdout.readline().strip(" \r\n") + +def main(argv): + """ Do the shit """ + con = sqlite3.connect(dbfile) + c = con.cursor() + + # Values we expect + values = { + "formalness" : "", + "citeyness" : "", + "reviewyness" : "", + "accurateness" : "", + "boringness" : "", + "pointyness" : "", + "overallness" : "", + "page" : 0, + "secret" : "No" + } + + sanity = True + + # Max pages + p = subprocess.Popen("pdfinfo thesis.pdf | grep Pages | sed 's/[^0-9]*//'", stdout=subprocess.PIPE, shell=True) + max_pages = int(p.stdout.read().strip(" \r\bn")) + + + + form = cgi.FieldStorage() + + # Check we have all the values + for k in values.keys(): + if k in form: + values[k] = form[k].value + + + # No values? Print the form + if len(form.keys()) <= 0 or "page" not in form: + values["page"] = random.randint(1, max_pages) + + print("Content-type: text/html\n") + print("") + print("") + print("
Invalid Page %s!
" % values["page"]) + values["page"] = random.randint(1, max_pages) + sanity = False + + print("