def get_formatted_msd_track_title_csv(db_file, filename='./msd_formatted_titles.csv'): """ Remove and reformat all the msd song titles and store it as csvfile. The output csv file is structured as follows : msd_track_id, msd_song_title, msd_new_song_title Inputs : db_file - track_metadata.db file provided by the labrosa filename - filename for the output csvfile ('./msd_formatted_titles.csv' by default) [NOTE] : tested runtime ~ 33.76 minutes """ def double_format(string): s = title_formatter(string) return title_formatter(s) con = init_connection(db_file) query = con.execute("""SELECT track_id, title FROM songs""") results = query.fetchall() con.close() with open(filename, 'w') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=['msd_id', 'msd_title', 'title']) writer.writeheader() cnt = 0 for track_id, track_name in results: print "--%s--" % cnt if track_name: title = double_format(track_name).encode('utf8') writer.writerow({ 'msd_id': track_id, 'msd_title': track_name, 'title': title }) cnt += 1 print "~Done..." return
print("created {} nodes".format(n_nodes)) @print_information def connect_teams_divisions_conferences(df): n_rels = 0 for _, row in df.iterrows(): # get entities t = Team.nodes.get(name=row["team"]) d = Division.nodes.get(name=row["division"]) c = Conference.nodes.get(name=row["conference"]) # create relationships t.division.connect(d) d.conference.connect(c) n_rels += 2 print("created {} relationships".format(n_rels)) if __name__ == "__main__": # read underlying data df = pd.read_csv("./data/teams-divisions-conferences.csv", sep=";") # connect to Neo4J init_connection() # create nodes create_teams(df) create_divisions(df) create_conferences(df) connect_teams_divisions_conferences(df)
import random import sys from os import path import pika sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from config import Config from utils import init_connection config = Config() connection = init_connection(connector=pika, host=config.host, port=config.port) channel = connection.channel() channel.exchange_declare(exchange='result', type='direct') result = channel.queue_declare(exclusive=True) queue_name = result.method.queue channel.queue_bind(exchange='result', queue=queue_name, routing_key='result') print(' [*] Waiting for logs. To exit press CTRL+C') def callback(ch, method, properties, body):
def clear_graph(): init_connection() n_nodes = db.cypher_query("MATCH (n) RETURN count(n)")[0][0][0] n_relations = db.cypher_query("MATCH ()-[r]->() RETURN count(r)")[0][0][0] clear_neo4j_database(db) print("deleted {} nodes and {} relationships".format(n_nodes, n_relations))