Mercurial > hg > python
comparison update.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,argv | |
3 from urllib2 import Request,urlopen, HTTPError | |
4 from base64 import b64encode | |
5 type='xyzzy' | |
6 l='' | |
7 year='2014' | |
8 | |
9 def cc(names): | |
10 return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split())) | |
11 | |
12 cm={'tf':0, | |
13 'uun':1, | |
14 'surname':2, | |
15 'cat':3, | |
16 'stat':4, | |
17 'email':5, | |
18 'country':6, | |
19 'pgm':7, | |
20 'entry':8, | |
21 'forename':9} | |
22 | |
23 eargs=['uun'] | |
24 eargs.extend(argv[1:]) | |
25 | |
26 while l=='': | |
27 l=stdin.readline().rstrip() | |
28 if l!="\tPG Applications List for ILCC": | |
29 print "Not what I was expecting: %s"%l | |
30 exit(1) | |
31 for l in stdin: | |
32 l=l.rstrip().decode('latin-1'); | |
33 if l=='': | |
34 continue | |
35 if l.find('Count:')==0: | |
36 exit() | |
37 if l.find('Pgm Code')==0: | |
38 continue | |
39 if l.find('Entry')==len(l)-5: | |
40 continue | |
41 if l.find(type)==0: | |
42 continue | |
43 if l=='': | |
44 continue | |
45 try: #tf,uun,name,cat,stat,email,country,pgm,entry | |
46 vals=l.split("\t") | |
47 except ValueError: | |
48 print "Bad input: %s"%l | |
49 continue | |
50 if vals[0]!='': | |
51 type=vals[0] | |
52 try: | |
53 (sn,fn)=vals[2].split(", ") | |
54 except ValueError: | |
55 print "Bad input: %s"%l | |
56 exit | |
57 vals[2]=cc(sn) | |
58 vals.append(cc(fn)) | |
59 attrs=" ".join(map(lambda n:'%s="%s"'%(n,vals[cm[n]]),eargs)) | |
60 req='<update year="%s" %s/>'%(year,attrs) | |
61 print req | |
62 r=Request("http://localhost:8080/exist/apps/phd/updateApp.xq", | |
63 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) | |
64 try: | |
65 res=urlopen(r) | |
66 except HTTPError as err: | |
67 print "Error:",err.read() | |
68 print req | |
69 exit(1) | |
70 print res.read() |