-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
64 lines (60 loc) · 1.77 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import webapp2
from datetime import datetime
import pypdftk
from collections import namedtuple
from mako.template import Template
from mako.lookup import TemplateLookup
lookup=TemplateLookup(directories=[".","..","./templates/","../templates/"])
signin=Template(filename="templates/signin.mako",lookup=lookup)
proof=Template(filename="templates/proof.mako",lookup=lookup)
Course = namedtuple("Course",["code","title","hours"])
def fillPdf(kwargs):
try:
pdfData={}
try:
if kwargs["title"]=="Mr":
pdfData["RB2"]=1
elif kwargs["title"]=="Mrs":
pdfData["RB2"]=2
elif kwargs["title"]=="Miss":
pdfData["RB2"]=3
elif kwargs["title"]=="Ms":
pdfData["RB2"]=4
else:
pdfData["Text2"]=kwargs["title"]
pdfData["RB2"]=5
except KeyError:
pass
pdfData["Text3"]=kwargs["surname"]
pdfData["Text4"]=kwargs["givennames"]
pdfData["Text5"]=kwargs["university"]
pdfData["SN1"]=kwargs["studentno"]
pdfData["Text6"]=kwargs["resunit/num"]
pdfData["Text7"]=kwargs["resstreet"]
pdfData["Text8"]=kwargs["ressuburb"]
pdfData["Text9"]=kwargs["resstate"]
pdfData["Text10"]=kwargs["respostcode"]
if kwargs["as_above"]==True:
pdfData["Text11"]="As above"
else:
pdfData["Text11"]=kwargs["postaddress"]
pdfData["Text12"]=kwargs["postsuburb"]
pdfData["Text13"]=kwargs["poststate"]
pdfData["Text14"]=kwargs["postpostcode"]
pdfData["Text15"]=kwargs["phone"]
pdfData["Text16"]=kwargs["email"]
now=datetime.now()
pdfData["Text17"]=now.day
pdfData["Text18"]=now.month
pdfData["Text19"]=now.year
except Exception as e:
print "PdfError "+str(e)
pass
newfile=pypdftk.fill_form("./new.pdf",pdfData)
f=open(newfile,"rb")
return f
def pullClosure(url):
def closure(browser):
browser.open(url)
return browser.response().read()
return closure