From: Sam Moore Date: Mon, 5 May 2014 15:44:43 +0000 (+0800) Subject: Created Rate My Lit Review X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fsam.git;a=commitdiff_plain;h=a7d21e530f640a6e0f8493cfa9fded2c71b7c42d Created Rate My Lit Review A system to Rate My Lit Review Look, you may be thinking "Why didn't he just work on his Lit Review?" ... That is pretty much exactly what I am thinking right now. --- diff --git a/.gitignore b/.gitignore index d6f44f6..5197191 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ *.bbl *.blg *.toc +page*.pdf +page*.svg +ratings.db diff --git a/hack-my-litreview.html b/hack-my-litreview.html new file mode 100644 index 0000000..55bc7fb --- /dev/null +++ b/hack-my-litreview.html @@ -0,0 +1,12 @@ + + + + Hack My LitReview (Patent Pending) + + +

Someone once told me I needed to rest more, or maybe they meant something different, but basically you need to POST your answers.

+

Hopefully you can overcome this diabolical security measure I have so cunningly wrought upon my form.

+

Happy HACKING

+ + + diff --git a/rate-my-litreview.html b/rate-my-litreview.html new file mode 100644 index 0000000..be96b88 --- /dev/null +++ b/rate-my-litreview.html @@ -0,0 +1,100 @@ + +
+ +

Rate This Page

+

Please answer the folowing questions first.

+

Or don't to give minimum rating.

+ + +

Formalness Of Language

+ + + + + + +
Space Baboon
Pirate Ship
Royal Dementia
School Ball
Officer Of The Day
+ +

Citeyness

+ + + + + + +
Nary A Reference In Cite
[Citation Needed]
[?] Does Not Count
Citation Ham Sandwich
More Citations Than Words
+ +

Reviewyness

+ + + + + + + + +
A Plague of Iarism
Wikipedia
The Articles Linked From Wikipedia
Blog Posts
Papers that link to Blog Posts
What, you expected me to check your citations?
+ +

Overallness

+ + + + + + +
Tear Inducingly Bad
Just Bad Enough To Read
Interestingly Insignificant
Blog Post Worthy
Would Read Another Page
+
+ +
+ +

Accurateness

+ + + + + + + + +
Dan Brown
A Body Of Lies
As Right As Stalin
Ministry Of Truth
Right Until Proven Left
No Shit Sherlock
+ +

Boringness

+ + + + + + + + + +
A Joy To Read
Somebody call the Fun Police
Too Punishing
Needs Salt
Deliciously Dry
Desert With One S
RFC2324
+ +

Pointyness

+ + + + + + +
Blunt As A Pixel
Infinitely Flat
Arbitrarily Smooth
Precisely Vague
Lead Pencil
+ + +

Words of Wisdom

+ + +

Turing Test

+

Are You A Robot?

+ + + +
+ + + 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("Rate My LitReview(TM) (Patent Pending)") + print("") + print("") + print("") + + # Check page number + try: + values["page"] = int(values["page"]) + except: + print("

Invalid Page %s!

" % values["page"]) + values["page"] = random.randint(1, max_pages) + sanity = False + + print("
") + + + print("

Rate My Lit Review

") + print("

Read a page, then rate it with the hammer of judgement!

") + print("

Page: of %d" % (values["page"], max_pages)) + if values["page"] > 1: + print("Prev" % (values["page"]-1)) + if values["page"] < max_pages: + print("Next" % (values["page"]+1)) + print("

") + + + + + + # Check secret question + if values["secret"] not in secret_answers: + print("

You failed the turing test! Hint: The answer is \"No\"

") + sanity = False + del values["secret"] + + + print("
") + print("" % values["page"]) + print("
") + + + print("
") + print_form("rate-my-litreview.html") + print("
") + + + if not sanity: + return 1 + + if len(form.keys()) <= 1: + print("") + return 0 + + # Sanity checks complete; set other values + values.update({"time" : int(datetime.datetime.now().strftime("%s"))}) + values.update({"version" : git_stamp()}) + + # Produce emails + + # Send emails + emails = ["matches@ucc.asn.au"] + userMsg = "Someone Rated Your LitReview!\n" + userMsg += "Your ratings\n-----------------\n" + for k in values: + userMsg += str(k) + ":\t" + str(values[k]) + + userMsg += "Happy LitReviewing!\n" + userMsg += "\n\nNOTE: This Message Automatically Sent By Rate My LitReview(TM) (Patent Pending)\n" + userMsg = MIMEText(userMsg) + for i,msg in enumerate([userMsg]): + msg["Subject"] = "Rate My LitReview" + msg["From"] = "matches@ucc.asn.au" + msg["To"] = emails[i] + s = smtplib.SMTP("localhost") + s.sendmail(msg["From"], [msg["To"]], msg.as_string()) + s.quit() + + # Tell them what happened. + # Do the thing + c.execute("INSERT INTO ratings("+",".join(values.keys())+") VALUES("+",".join(["?" for _ in xrange(len(values.keys()))])+")", [values[k] for k in values.keys()]) + con.commit() + con.close() + + print("" % (values["page"], values["page"])) + print("") + return 0 + + +if __name__ == "__main__": + #try: + sys.exit(main(sys.argv)) + #except: + # print "Content-type: text/plain\r\n\r\n" + # print "Something went wrong! You were unable to Rate Sam's LitReview(TM)!\nPlease send him an abusive email instead \n" + diff --git a/read-my-litreview.py b/read-my-litreview.py new file mode 100755 index 0000000..d675233 --- /dev/null +++ b/read-my-litreview.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +import sys +import os +import cgi +import time + +def main(argv): + form = cgi.FieldStorage() + page = int(form["page"].value) + + + try: + f = open("page%d.svg" % page) + except IOError: + os.system("pdftk A=thesis.pdf cat A%d output page%d.pdf" % (page, page)) + os.system("inkscape -l page%d.svg page%d.pdf" % (page, page)) + os.unlink("page%d.pdf" % page) + f = open("page%d.svg" % page) + + output = f.read() + print("Content-Length: %d" % len(output)) + print("Content-Type: image/svg+xml\n") + sys.stdout.write(output) + f.close() + + # TODO: Auto remove these on git pull, for now will just have to remember to do it + #os.unlink("page%d.svg" % page) + + + + +if __name__ == "__main__": + #try: + main(sys.argv) + #except: + # print("Content-type: text/plain\n") + # print("Something went wrong!\n") + sys.exit(0) diff --git a/sledgehammer.png b/sledgehammer.png new file mode 100644 index 0000000..949786f Binary files /dev/null and b/sledgehammer.png differ