コード例 #1
0
def get_changed_ids(start, end):
    try:
        conn = psycopg2.connect(PG_CONNECT)
    except psycopg2.OperationalError as err:
        log("Cannot connect to database: %s" % err)
        sys.exit(-1)

    data = {}
    entities = ('artist', 'label', 'recording', 'release_group', 'release', 'work')
    for entity in entities:
        data[entity] = get_ids_for_entity(conn, queries.queries[entity], start, end)
    return data
コード例 #2
0
#!/usr/bin/python

import sys
import os
from time import ctime
from changedmbidfeed import config
from changedmbidfeed import feed
from changedmbidfeed.log import log

# optparse is retarded and argparse is not support on our target platform, so we'll just it manually

if len(sys.argv) == 1:
    # Continue where we left off last time
    seq, timestamp = feed.read_state_data()
    if not seq:
        log("Cannot continue. Can't read state data file. Start a feed by running with the --create option")
        sys.exit(-1)

    log("Creating changed mbid feed from last replication packet")
    feed.generate_entry(config.OUTPUT_DIR, seq, timestamp)

if len(sys.argv) == 2 and (sys.argv[1] == '-c' or sys.argv[1] == '--create'):
    # check to make sure we dont already have a last updated file
    seq, timestamp = feed.read_state_data()
    if seq:
        log("A %s file already exists. If you would like to start a new feed, remove this file first." % feed.LAST_UPDATED_FILE)
        sys.exit(-1)

    seq, timestamp = feed.get_current_replication_info()
    log("The database has replication sequence %s and timestamp %s" % (seq, timestamp))