def main( source_media_cloud_api_url, dest_media_cloud_api_url, source_api_key, dest_api_key, db_label ): conn = mc_database.connect_to_database( db_label ) cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) print "fetching feed downloads from postgresql" cursor.execute( "SELECT downloads_id from downloads where type='feed' and state in ( 'success', 'feed_error') order by downloads_id" ) feed_downloads = cursor.fetchall() feed_downloads_processed = 0 print "converting downloads_ids to int " feed_downloads_ids = [ fd['downloads_id'] for fd in feed_downloads ] print len( feed_downloads_ids ), "downloads to export " print "exporting feed downloads with API" for feed_downloads_id in feed_downloads_ids: export_feed_download( feed_downloads_id, source_media_cloud_api_url, source_api_key, dest_media_cloud_api_url, dest_api_key ) feed_downloads_processed+= 1 if feed_downloads_processed % 10 == 0: print "Processed " + str( feed_downloads_processed ) + " downloads out of " + str( len( feed_downloads_ids ) ) print "last download ", feed_downloads_id
def main(): parser = argparse.ArgumentParser( description= 'Import media and feeds listing from the production machine into the local database.' ) parser.add_argument('--api-key', required=True) args = parser.parse_args() api_key = args.api_key if not yesno( 'This will erase all data in the current media cloud database. Are you sure you want to continue?' ): exit() mc = mediacloud.api.MediaCloud(api_key, all_fields=True) conn = mc_database.connect_to_database() print "truncating tables" truncate_tables(conn) update_db_sequences(conn) print "obtaining tag sets" all_tag_sets = get_tag_sets(mc) print "importing tag sets" add_tag_sets_to_database(conn, all_tag_sets) print "obtaining media" all_media = get_media(mc) print "importing media" add_media_to_database(conn, all_media) print "importing feeds from media" add_feeds_from_media_to_database(conn, mc, all_media) print "updating sequences" update_db_sequences(conn)
def main(): parser = argparse.ArgumentParser(description='Import media and feeds listing from the production machine into the local database.') parser.add_argument( '--api-key', required=True ) args = parser.parse_args() api_key = args.api_key if not yesno('This will erase all data in the current media cloud database. Are you sure you want to continue?'): exit() mc = mediacloud.api.MediaCloud(api_key, all_fields=True) conn = mc_database.connect_to_database() print "truncating tables" truncate_tables( conn ) update_db_sequences(conn) print "obtaining tag sets" all_tag_sets = get_tag_sets( mc ) print "importing tag sets" add_tag_sets_to_database( conn, all_tag_sets ) print "obtaining media" all_media = get_media( mc ) print "importing media" add_media_to_database( conn, all_media ) print "importing feeds from media" add_feeds_from_media_to_database( conn, mc, all_media ) print "updating sequences" update_db_sequences(conn)