Mercurial > odfcast
comparison castclient.py @ 0:4a34f72f036b
Add initial conversion service
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 26 Sep 2014 14:21:21 +0200 |
parents | |
children | c04edbd52967 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a34f72f036b |
---|---|
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import optparse | |
5 import sys | |
6 | |
7 import requests | |
8 | |
9 url = "http://127.0.0.1:5000/convert/" | |
10 | |
11 | |
12 def main(): | |
13 usage = "usage: %prog [options] infile outfile" | |
14 parser = optparse.OptionParser(usage=usage) | |
15 parser.add_option("-f", "--format", default="pdf") | |
16 parser.add_option("-s", "--host", default="localhost") | |
17 parser.add_option("-p", "--port", default="5000") | |
18 (options, args) = parser.parse_args() | |
19 | |
20 if len(args) < 2: | |
21 parser.print_usage() | |
22 sys.exit(1) | |
23 | |
24 url = "http://%s:%s/convert/" % (options.host, options.port) | |
25 infilename = args[0] | |
26 outfilename = args[1] | |
27 format = options.format | |
28 | |
29 files = {'file': open(infilename, 'rb')} | |
30 data = {'format': format} | |
31 | |
32 r = requests.post(url, data=data, files=files) | |
33 | |
34 if r.status_code == 200: | |
35 with open(outfilename, "wb") as f: | |
36 f.write(r.content) | |
37 print "OK" | |
38 else: | |
39 print "An error has occured" | |
40 print r.status_code, r.headers | |
41 sys.exit(2) | |
42 | |
43 | |
44 if __name__ == "__main__": | |
45 main() |