diff -r 2209e66bb50b -r 500cd0405c7a script/lib/iri_tweet/export_twitter_alchemy.py --- a/script/lib/iri_tweet/export_twitter_alchemy.py Fri Aug 12 18:17:27 2011 +0200 +++ b/script/lib/iri_tweet/export_twitter_alchemy.py Wed Aug 17 18:32:07 2011 +0200 @@ -5,7 +5,7 @@ from optparse import OptionParser #@UnresolvedImport from sqlalchemy import Table, Column, BigInteger, MetaData from sqlalchemy.orm import sessionmaker -from utils import parse_date, set_logging_options, set_logging, get_filter_query, logger +from utils import parse_date, set_logging_options, set_logging, get_filter_query, get_logger from models import setup_database import datetime import os.path @@ -100,13 +100,17 @@ set_logging(options) - logger.debug("OPTIONS : " + repr(options)) #@UndefinedVariable + get_logger().debug("OPTIONS : " + repr(options)) #@UndefinedVariable if len(sys.argv) == 1 or options.database is None: parser.print_help() sys.exit(1) - engine, metadata = setup_database('sqlite:///'+options.database, echo=((options.verbose-options.quiet)>0), create_all = False) + conn_str = options.database.strip() + if not re.match("^\w+://.+", conn_str): + conn_str = 'sqlite:///' + conn_str + + engine, metadata = setup_database(conn_str, echo=((options.verbose-options.quiet)>0), create_all = False) Session = sessionmaker() conn = engine.connect() @@ -158,7 +162,7 @@ for params in parameters: - logger.debug("PARAMETERS " + repr(params)) #@UndefinedVariable + get_logger().debug("PARAMETERS " + repr(params)) #@UndefinedVariable start_date_str = params.get("start_date",None) end_date_str = params.get("end_date", None) @@ -191,12 +195,12 @@ if content_file and content_file.find("http") == 0: - logger.debug("url : " + content_file) #@UndefinedVariable + get_logger().debug("url : " + content_file) #@UndefinedVariable h = httplib2.Http() resp, content = h.request(content_file) - logger.debug("url response " + repr(resp) + " content " + repr(content)) #@UndefinedVariable + get_logger().debug("url response " + repr(resp) + " content " + repr(content)) #@UndefinedVariable project = anyjson.deserialize(content) root = etree.fromstring(project["ldt"]) @@ -253,7 +257,7 @@ if ensemble_parent is None: - logger.error("Can not process file") #@UndefinedVariable + get_logger().error("Can not process file") #@UndefinedVariable sys.exit() if options.replace: @@ -308,18 +312,18 @@ project["ldt"] = output_data body = anyjson.serialize(project) - logger.debug("write http " + content_file) #@UndefinedVariable - logger.debug("write http " + repr(body)) #@UndefinedVariable + get_logger().debug("write http " + content_file) #@UndefinedVariable + get_logger().debug("write http " + repr(body)) #@UndefinedVariable h = httplib2.Http() resp, content = h.request(content_file, "PUT", headers={'content-type':'application/json'}, body=body) - logger.debug("write http " + repr(resp) + " content " + content) #@UndefinedVariable + get_logger().debug("write http " + repr(resp) + " content " + content) #@UndefinedVariable else: if content_file and os.path.exists(content_file): dest_file_name = content_file else: dest_file_name = options.filename - logger.debug("WRITE : " + dest_file_name) #@UndefinedVariable + get_logger().debug("WRITE : " + dest_file_name) #@UndefinedVariable output = open(dest_file_name, "w") output.write(output_data) output.flush()