comparison boxi.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
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 from base64 import b64encode
5 import re
6 type='xyzzy'
7 l=''
8 year='2014'
9 tsplit=re.compile('\t\t*')
10
11 def cc(names):
12 return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split()))
13
14 while l=='':
15 l=stdin.readline().rstrip()
16 if l!="\t\tPG Applications List for ILCC+Henry S. Thompson+ht+Informatics_Amended : 456344":
17 print "Not what I was expecting: %s"%l
18 exit(1)
19 for l in stdin:
20 l=l.rstrip().decode('latin-1');
21 if l=='':
22 continue
23 if l.find('Count:')==0:
24 exit()
25 if l.find('Pgm Code')==0:
26 continue
27 if l.find(type)==0:
28 continue
29
30 ff=l.split('\t')
31 if len(ff)==9:
32 (tf,uun,name,cat,stat,email,country,pgm,entry)=ff
33 elif len(ff)==8:
34 (tf,uun,name,cat,stat,email,pgm,entry)=ff
35 country=""
36 else:
37 print "Bad input: %s"%('|'.join(l.split('\t')))
38 continue
39 if tf!='':
40 type=tf
41 #if stat not in ('SD','SP'):
42 # continue
43 (sn,fn)=name.split(", ")
44 surname=cc(sn)
45 forenames=cc(fn)
46 req='<app year="%s" uun="%s" type="%s" surname="%s" forenames="%s" cat="%s" stat="%s" pgm="%s" entry="%s" email="%s" country="%s"/>'%(year,uun,type,surname,forenames,cat,stat,pgm,entry,email,country)
47 #print req.encode('iso-8859-1')
48 #continue
49 r=Request("http://localhost:8080/exist/apps/phd/new-app-maybe.xq",
50 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'})
51 try:
52 res=urlopen(r)
53 except HTTPError as err:
54 print "Error:",err.read()
55 print req
56 exit(1)
57 print res.read()