Mercurial > hg > python
comparison bobi.py @ 0:fee51ab07d09
blanket publication of all existing python files in lib/python on maritain
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 09 Mar 2020 14:58:04 +0000 |
parents | |
children | 0a3abe59e364 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fee51ab07d09 |
---|---|
1 #!/bin/python | |
2 from sys import stdin | |
3 from urllib2 import Request,urlopen, HTTPError | |
4 | |
5 l='' | |
6 year='2015' | |
7 uuns={} | |
8 | |
9 def cc(names): | |
10 return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split())) | |
11 | |
12 while l=='': | |
13 l=stdin.readline().rstrip() | |
14 oldf=l.find("ILCC PGR live applications: ")==0 | |
15 if ((not oldf) and | |
16 l.find("EUCLID Admissions core applicant data - applications for next session")!=0 and | |
17 l.find("HST PGR applicants incl Beihang")!=0): | |
18 print "Not what I was expecting: %s"%l | |
19 exit(1) | |
20 while l.find('UUN\t')<0: | |
21 l=stdin.readline().rstrip() | |
22 for l in stdin: | |
23 l=l.rstrip().decode('latin-1'); | |
24 if l=='': | |
25 continue | |
26 | |
27 ff=l.split('\t') | |
28 if oldf: | |
29 if len(ff)==9: | |
30 (uun,surname,forenames,cat,stat,dec,entry,email,country)=ff | |
31 pgrm='PRPHDLNGCC1F' | |
32 nat='Unknown' | |
33 else: | |
34 print "Bad old-style input: %s"%('|'.join(l.split('\t'))) | |
35 continue | |
36 else: | |
37 if len(ff)==11: | |
38 (nat,stat,pgrm,dec,surname,forenames,entry,cat,uun,email,country)=ff | |
39 else: | |
40 print "Bad new-style input: %s"%('|'.join(l.split('\t'))) | |
41 continue | |
42 if uun in uuns: | |
43 print "!!! Careful !!!: %s seen before today with status %s, now %s"%(uun,uuns[uun],stat) | |
44 else: | |
45 uuns[uun]=stat | |
46 surname=cc(surname) | |
47 forenames=cc(forenames) | |
48 if pgrm=='PRPHDLNGCC1F': | |
49 ptype='I' | |
50 else: | |
51 ptype='B' | |
52 req='<app year="%s" uun="%s" type="PHD %s" surname="%s" forenames="%s" cat="%s" stat="%s" decision="%s" pgm="PhD ILCC" entry="%s" email="%s" country="%s" nationality="%s"/>'%(year,uun,ptype,surname,forenames,cat,stat,dec,entry,email,country,nat) | |
53 #print req.encode('iso-8859-1') | |
54 #continue | |
55 r=Request("http://localhost:8080/exist/apps/phd/new-app-maybe.xq", | |
56 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) | |
57 try: | |
58 res=urlopen(r) | |
59 except HTTPError as err: | |
60 print "Error:",err.read() | |
61 print req | |
62 exit(1) | |
63 res=res.read() | |
64 print ptype,res | |
65 if (not oldf) and res.find("<div>We already")==0: | |
66 req='<update year="%s" uun="%s" nationality="%s"/>'%(year,uun,nat) | |
67 r=Request("http://localhost:8080/exist/apps/phd/updateApp.xq", | |
68 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) | |
69 try: | |
70 res=urlopen(r) | |
71 except HTTPError as err: | |
72 print "Error:",err.read() | |
73 print req | |
74 exit(1) |