summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-02-12 12:15:24 +0100
committerFlorian Bruhin <me@the-compiler.org>2012-02-12 12:15:24 +0100
commitf7c9bbce28202d48a9be6ff190ad93e53bf20868 (patch)
treed0e8cdc13d2d3d62a5cfc48a47a97a308ac73948
parent842f550f15ef1ba69a04b1190a5a5dcc4c60b4b5 (diff)
downloadwebopac-f7c9bbce28202d48a9be6ff190ad93e53bf20868.tar.gz
webopac-f7c9bbce28202d48a9be6ff190ad93e53bf20868.zip
add query argument, get it to run
-rw-r--r--webopac.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/webopac.py b/webopac.py
index 504c525..c992ec4 100644
--- a/webopac.py
+++ b/webopac.py
@@ -5,8 +5,9 @@ import urllib.request
import urllib.parse
import lxml.etree
import logging
+import optparse
-def get_webopac_xml(query="foo", baseurl):
+def get_webopac_xml(query, baseurl):
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
@@ -46,13 +47,17 @@ def initlog(options):
logging.info('Initalized.')
def parseopts():
- parser = optparse.OptionParser("usage: %prog [options]")
+ parser = optparse.OptionParser("usage: %prog [options] query")
parser.add_option('-l', '--log', dest='loglevel', help='Set loglevel',
default=0)
parser.add_option('-b', '--baseurl', dest='baseurl', help='Set baseurl'
' of the page', default='https://katalog.bibliotheken.'
'winterthur.ch/webOPACClient.sisis/')
(options, args) = parser.parse_args()
+ if len(args) == 0:
+ parser.error("Error: You need to provide a query")
+ elif len(args) > 2:
+ parser.error("Too many arguments!")
return (options, args)
def init():
@@ -62,10 +67,8 @@ def init():
def main():
(options, args) = init()
-
- f = get_webopac_xml("Green day", baseurl=options.baseurl)
+ f = get_webopac_xml(args[0], baseurl=options.baseurl)
root = decode_xml(f)
-
print(root)
if __name__ == '__main__':