comparison bobi.py @ 1:0a3abe59e364

updated from more recent versions on origen
author Henry Thompson <ht@markup.co.uk>
date Mon, 09 Mar 2020 16:45:20 +0000
parents fee51ab07d09
children
comparison
equal deleted inserted replaced
0:fee51ab07d09 1:0a3abe59e364
1 #!/bin/python 1 #!/bin/python
2 from sys import stdin 2 from sys import stdin
3 from urllib2 import Request,urlopen, HTTPError 3 from urllib2 import Request,urlopen, HTTPError, URLError
4 4
5 l='' 5 l=''
6 year='2015' 6 year='2016'
7 uuns={} 7 uuns={}
8 8
9 def cc(names): 9 def cc(names):
10 return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split())) 10 return ' '.join(map(lambda n:n[0]+n[1:].lower(),names.split()))
11 11
50 else: 50 else:
51 ptype='B' 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) 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') 53 #print req.encode('iso-8859-1')
54 #continue 54 #continue
55 r=Request("http://localhost:8080/exist/apps/phd/new-app-maybe.xq", 55 r=Request("http://troutbeck.inf.ed.ac.uk:8080/exist/apps/phd/new-app-maybe.xq",
56 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) 56 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'})
57 try: 57 try:
58 res=urlopen(r) 58 res=urlopen(r)
59 except HTTPError as err: 59 host="troutbeck.inf.ed.ac.uk"
60 print "Error:",err.read() 60 except URLError as err1:
61 print req 61 r=Request("http://localhost:8080/exist/apps/phd/new-app-maybe.xq",
62 exit(1) 62 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'})
63 try:
64 res=urlopen(r)
65 host="localhost"
66 except URLError as err:
67 print "Failed, no way to database server:",err1.read(),err.read()
68 exit(1)
63 res=res.read() 69 res=res.read()
64 print ptype,res 70 print ptype,res
65 if (not oldf) and res.find("<div>We already")==0: 71 if (not oldf) and res.find("<div>We already")==0:
66 req='<update year="%s" uun="%s" nationality="%s"/>'%(year,uun,nat) 72 req='<update year="%s" uun="%s" nationality="%s"/>'%(year,uun,nat)
67 r=Request("http://localhost:8080/exist/apps/phd/updateApp.xq", 73 r=Request("http://%s:8080/exist/apps/phd/updateApp.xq"%host,
68 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'}) 74 req.encode('utf-8'),headers={'Content-Type':'application/xml;charset=UTF-8'})
69 try: 75 try:
70 res=urlopen(r) 76 res=urlopen(r)
71 except HTTPError as err: 77 except HTTPError as err:
72 print "Error:",err.read() 78 print "Error:",err.read()