# -*- coding: utf-8 -*- import mysql.connector import time from dbconfig import Config # dbconfig is for dbconfig.py config = Config.dbinfo().copy() # Initialization def importDTPM(paralist, indexname, hashpath, pageTitle, page): db = mysql.connector.Connect(**config) cursor = db.cursor() v_path = hashpath[-4:] # Get the latest revision id of this page rev_id = page.latestRevision() print v_path print rev_id tb_name = "tb_in_" + indexname query_str = "INSERT INTO `%s` " % (tb_name) field_str = "(" value_str = "(" field_str += "pg_name,v_path" value_str += "'%s','%s'" % (pageTitle, v_path) cnt = 0 for p in paralist: field_str += "," + p[0] value_str += "," + "'" + p[1] + "'" cnt += 1
# -*- coding: utf-8 -*- import mysql.connector import time from dbconfig import Config # dbconfig is for dbconfig.py config = Config.dbinfo().copy() # Initialization def importDTPM(paralist, indexname, hashpath, pageTitle, page): db = mysql.connector.Connect(**config) cursor = db.cursor() v_path = hashpath[-4:] # Get the latest revision id of this page rev_id = page.latestRevision() print v_path print rev_id tb_name = "tb_in_" + indexname query_str = "INSERT INTO `%s` "%(tb_name) field_str = "(" value_str = "(" field_str += "pg_name,v_path" value_str += "'%s','%s'"%(pageTitle,v_path) cnt = 0 for p in paralist: field_str += "," + p[0] value_str += "," + "'" + p[1] + "'" cnt += 1 # Get current local time
help="don't configure the default schema") parser.add_option("-s", "--schema", dest="schema", default='discogs', help="default schema") parser.add_option("-c", "--config", dest="cfgfile", default=None, help="configuration file") options, args = parser.parse_args() if options.cfgfile is None: root = os.path.realpath(os.path.dirname(__file__)) config = Config(os.path.join(root, 'postgresql.conf')) else: config = Config(options.cfgfile) args = ['psql'] args.append('-U') args.append(config.get('DATABASE', 'user')) if config.has_option('DATABASE', 'host'): args.append('-h') args.append(config.get('DATABASE', 'host')) if config.has_option('DATABASE', 'port'): args.append('-p') args.append(config.get('DATABASE', 'port')) args.append(config.get('DATABASE', 'name')) if not options.public:
# import headers from exporter.py in parent dir sys.path.insert(1, os.path.join(sys.path[0], '..')) from exporter import csv_headers def load_csv(filename, db): print("Importing data from {}".format(filename)) base, fname = os.path.split(filename) table, ext = fname.split('.', 1) if ext.startswith('csv'): q = sql.SQL("COPY {} ({}) FROM STDIN WITH CSV HEADER").format( sql.Identifier(table), sql.SQL(', ').join(map(sql.Identifier, csv_headers[table]))) if ext == 'csv': fp = open(filename) elif ext == 'csv.bz2': fp = bz2.BZ2File(filename) cursor = db.cursor() cursor.copy_expert(q, fp) db.commit() root = os.path.realpath(os.path.dirname(__file__)) config = Config(os.path.join(root, 'postgresql.conf')) db = connect_db(config) for filename in sys.argv[1:]: load_csv(os.path.abspath(filename), db)
from psycopg2 import sql from dbconfig import connect_db, Config, columns def load_csv(filename, db): print("Importing data from {}".format(filename)) base, fname = os.path.split(filename) table, ext = fname.split('.', 1) if ext.startswith('csv'): q = sql.SQL("COPY {} ({}) FROM STDIN WITH CSV HEADER").format( sql.Identifier(table), sql.SQL(', ').join(map(sql.Identifier, columns[table]))) if ext == 'csv': fp = open(filename) elif ext == 'csv.bz2': fp = bz2.BZ2File(filename) cursor = db.cursor() cursor.copy_expert(q, fp) db.commit() root = os.path.realpath(os.path.dirname(__file__)) config = Config(os.path.join(root, 'discogs.conf')) db = connect_db(config) for filename in sys.argv[1:]: load_csv(os.path.abspath(filename), db)
from psycopg2 import sql from dbconfig import connect_db, Config, columns def load_csv(filename, db): print("Importing data from {}".format(filename)) base, fname = os.path.split(filename) table, ext = fname.split('.', 1) if ext.startswith('csv'): q = sql.SQL("COPY {} ({}) FROM STDIN WITH CSV HEADER").format( sql.Identifier(table), sql.SQL(', ').join(map(sql.Identifier, columns[table]))) if ext == 'csv': fp = open(filename) elif ext == 'csv.bz2': fp = bz2.BZ2File(filename) cursor = db.cursor() cursor.copy_expert(q, fp) db.commit() config = Config(os.path.dirname(__file__) + '/discogs.conf') db = connect_db(config) for filename in sys.argv[1:]: load_csv(os.path.abspath(filename), db)
default=False, help="don't configure the default schema") parser.add_option("-s", "--schema", dest="schema", default='discogs', help="default schema") parser.add_option("-c", "--config", dest="cfgfile", default=None, help="configuration file") options, args = parser.parse_args() if options.cfgfile is None: config = Config(os.path.dirname(__file__) + '/discogs.conf') else: config = Config(options.cfgfile) args = ['psql'] args.append('-U') args.append(config.get('DATABASE', 'user')) if config.has_option('DATABASE', 'host'): args.append('-h') args.append(config.get('DATABASE', 'host')) if config.has_option('DATABASE', 'port'): args.append('-p') args.append(config.get('DATABASE', 'port')) args.append(config.get('DATABASE', 'name')) if not options.public: