street_num=street_num, street=street_name, town=town, postcode=row[3] ) with open("Employees.csv") as file: csv_file = csv.reader(file) next(csv_file) # skiping header for row in csv_file: team = eval(f"Team.{row[3].lower()}") employees[row[0]] = Employee( _id="Employee/" + row[0], name=row[1], title=row[2], address=addresses[row[0]], contact_number=contact_numbers[row[0]], team = team ) managers[row[0]] = row[4] for emp_id, man_id in managers.items(): if man_id: employees[emp_id].manager = employees[man_id] # For Terminus X, use the following # client = WOQLClient("https://cloud.terminusdb.com/<Your Team>/") # client.connect(db="demo_workshop", team="<Your Team>", use_token=True) client = WOQLClient("http://127.0.0.1:6363/") client.connect(db="getting_started") client.insert_document(list(employees.values()), commit_msg="Adding 4 Employees")
schema = [ { '@type' : 'Class', '@id' : 'IndexRecord', '@key' : { '@type' : 'ValueHash' }, 'index' : 'xsd:string', 'date' : 'xsd:date', 'open' : 'xsd:decimal', 'high' : 'xsd:decimal', 'low' : 'xsd:decimal', 'close' : 'xsd:decimal', 'adjusted_close' : 'xsd:decimal', 'volume' : 'xsd:decimal' } ] client.insert_document(schema, graph_type="schema", commit_msg = "Adding initial schema") else: # TerminusX #client.connect(account=team,db=db,jwt_token=key) client.connect(account=team,db=db,user=user,key=key) def load_file(f): with open(f, newline='') as csvfile: # extract header... next(csvfile) ticker_rows = csv.reader(csvfile, delimiter=',') chunk_size = 1000 objects = [] chunk = 0
brewery = Brewery() brewery.name = row['name'] brewery.type_of = Brewery_Type[row['brewery_type']] brewery.address_of = address brewery.phone = str(row['phone']) brewery.website_url = row['website_url'] breweries.append(brewery) return breweries if __name__ == "__main__": db_id = "Brewery" url = "https://raw.githubusercontent.com/openbrewerydb/openbrewerydb/master/breweries.csv" client = WOQLClient("http://127.0.0.1:6363") client.connect() try: client.create_database(db_id, team="admin", label="Open Brewery Graph", description="Create a graph with brewery data") except Exception: client.set_db(db_id) client.insert_document(my_schema.to_dict(), graph_type="schema", commit_msg="I am checking in the schema") csv_info(url) insert_data(client, url) results = client.get_all_documents(graph_type="instance", count=10) print("\nRESULTS\n", list(results))