summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-02-12 12:11:17 +0100
committerFlorian Bruhin <me@the-compiler.org>2012-02-12 12:11:17 +0100
commit842f550f15ef1ba69a04b1190a5a5dcc4c60b4b5 (patch)
treef50acc39c6a8a043ef8d6b0a02cbe55a07f8f536
parent206eb879f8cc8cd281e520e43856647354192cfe (diff)
downloadwebopac-842f550f15ef1ba69a04b1190a5a5dcc4c60b4b5.tar.gz
webopac-842f550f15ef1ba69a04b1190a5a5dcc4c60b4b5.zip
Refactoring, initializing
-rw-r--r--webopac.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/webopac.py b/webopac.py
index 7cd8821..504c525 100644
--- a/webopac.py
+++ b/webopac.py
@@ -6,8 +6,7 @@ import urllib.parse
import lxml.etree
import logging
-def get_webopac_xml(query="foo"):
- baseurl="https://katalog.bibliotheken.winterthur.ch/webOPACClient.sisis/"
+def get_webopac_xml(query="foo", baseurl):
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
@@ -31,19 +30,40 @@ def decode_xml(f):
root = lxml.etree.XML(data)
return(root)
+def initlog(options):
+ """ Initialisation of the log """
+ if (options.loglevel):
+ loglevel = options.loglevel
+ else:
+ loglevel = 'error'
+ numeric_level = getattr(logging, loglevel.upper(), None)
+
+ if not isinstance(numeric_level, int):
+ raise ValueError('Invalid log level: {}'.format(loglevel))
+ logging.basicConfig(level=numeric_level,
+ format='%(asctime)s [%(levelname)s] %(message)s',
+ datefmt='%m/%d/%Y %H:%M:%S')
+ logging.info('Initalized.')
+
def parseopts():
parser = optparse.OptionParser("usage: %prog [options]")
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()
return (options, args)
-
def init():
-
+ (options, args) = parseopts()
+ initlog(options)
+ return (options, args)
def main():
- f = get_webopac_xml("Green day")
+ (options, args) = init()
+
+ f = get_webopac_xml("Green day", baseurl=options.baseurl)
root = decode_xml(f)
print(root)