Mercurial > hg > python
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bobi.py Mon Mar 09 14:58:04 2020 +0000 @@ -0,0 +1,74 @@ +#!/bin/python +from sys import stdin +from urllib2 import Request,urlopen, HTTPError + +l='' +year='2015' +uuns={} + +def cc(names): + return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split())) + +while l=='': + l=stdin.readline().rstrip() +oldf=l.find("ILCC PGR live applications: ")==0 +if ((not oldf) and + l.find("EUCLID Admissions core applicant data - applications for next session")!=0 and + l.find("HST PGR applicants incl Beihang")!=0): + print "Not what I was expecting: %s"%l + exit(1) +while l.find('UUN\t')<0: + l=stdin.readline().rstrip() +for l in stdin: + l=l.rstrip().decode('latin-1'); + if l=='': + continue + + ff=l.split('\t') + if oldf: + if len(ff)==9: + (uun,surname,forenames,cat,stat,dec,entry,email,country)=ff + pgrm='PRPHDLNGCC1F' + nat='Unknown' + else: + print "Bad old-style input: %s"%('|'.join(l.split('\t'))) + continue + else: + if len(ff)==11: + (nat,stat,pgrm,dec,surname,forenames,entry,cat,uun,email,country)=ff + else: + print "Bad new-style input: %s"%('|'.join(l.split('\t'))) + continue + if uun in uuns: + print "!!! Careful !!!: %s seen before today with status %s, now %s"%(uun,uuns[uun],stat) + else: + uuns[uun]=stat + surname=cc(surname) + forenames=cc(forenames) + if pgrm=='PRPHDLNGCC1F': + ptype='I' + else: + ptype='B' + 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) + #print req.encode('iso-8859-1') + #continue + r=Request("http://localhost:8080/exist/apps/phd/new-app-maybe.xq", + req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) + try: + res=urlopen(r) + except HTTPError as err: + print "Error:",err.read() + print req + exit(1) + res=res.read() + print ptype,res + if (not oldf) and res.find("<div>We already")==0: + req='<update year="%s" uun="%s" nationality="%s"/>'%(year,uun,nat) + r=Request("http://localhost:8080/exist/apps/phd/updateApp.xq", + req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) + try: + res=urlopen(r) + except HTTPError as err: + print "Error:",err.read() + print req + exit(1)