source: client/downloader.py @ 922e0e5

client
Last change on this file since 922e0e5 was f8a5e4b, checked in by Alex Dehnert <adehnert@…>, 14 years ago

Error out if downloader gets HTML

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/usr/bin/python
2
3import os
4import subprocess
5import sys
6import re
7import datetime
8from mechanize import Browser
9
10pdfviewer = 'evince'
11django_username = 'downloader'
12
13from settings import *
14
15
16def id_predicate(value):
17    def _predicate(form):
18        if 'id' in form.attrs:
19            if form.attrs['id'] == value:
20                return True
21        return False
22    return _predicate
23
24def login2Admin(br):
25    # Log in to the admin interface
26    br.open(baseurl + 'admin/')
27    assert br.viewing_html()
28    sys.stderr.write("Viewing '%s'\n" % (br.title(), ))
29    assert br.title() == "Log in | Django site admin"
30    br.select_form(predicate=id_predicate('login-form'))
31    # Browser passes through unknown attributes (including methods)
32    # to the selected HTMLForm (from ClientForm).
33    br["username"] = django_username  # (the method here is __setitem__)
34    br["password"] = password  # (the method here is __setitem__)
35    response2 = br.submit()  # submit current form
36
37def getLaTeX(br, latex_file, ):
38    br.open(baseurl + 'vouchers/generate/')
39    if br.viewing_html():
40        print br.response().get_data()
41        assert not br.viewing_html()
42    latex_file.write(br.response().get_data())
43
44if __name__ == '__main__':
45    label = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
46    texpath  = pathtpl % { 'label':label, 'ext':'tex' }
47    pdfpath  = pathtpl % { 'label':label, 'ext':'pdf' }
48    texdir, texfile = os.path.split(texpath)
49
50    br = Browser()
51    login2Admin(br)
52    texfileobj = open(texpath, 'w')
53    getLaTeX(br, texfileobj, )
54    texfileobj.close()
55
56    subprocess.check_call(['pdflatex', texfile], cwd=texdir)
57    subprocess.check_call(['pdflatex', texfile], cwd=texdir)
58    subprocess.check_call([pdfviewer, pdfpath])
Note: See TracBrowser for help on using the repository browser.