import warnings

import networkx as nx
import pandas as pd
import json

Users= []
G = nx.classes.graph.Graph()
def userfetch():
    with open("users.json", "r") as json_file:
        df_nodes = json.load(json_file)
    for row in df_nodes:
       userreputation = "L4-Reputation_" + str(row['reputation'])
       print(row['reputation'])
       G.add_node(userreputation)
       userId= "L5-Users_" + row['id']
       ids = [userId.split('_')[1]]
       Users.append(ids)
       print(row['id'])
       G.add_node(userId)
       G.add_edge(userId, userreputation, key="reputation")

def travelfetch():
    with open("csvjson.json", "r") as json_file:
        df_nodes = json.load(json_file)

    startedby= []
    for row in df_nodes:
           startedby= row['startedBy']
           finishedby = row['finishedBy']
           print("     ")
            # print(row['startedBy'][0:2])
           for row1 in startedby:
               #NewNode = "L1-StartingPoints_" + row1['user']
               #print(NewNode)
               Latitude= row1['coordinate']['latitude']
               Longitude= row1['coordinate']['longitude']

               NewNode = "L1-StartingPoints_" + str(Latitude)+ ",  " + str(Longitude)
               G.add_node(NewNode)
               print(row1['coordinate']['latitude'])
               print(row1['coordinate']['longitude'])
               NewNode1 = "L2-time_" + row1['user']
               Moment = row1['moment']
               G.add_node(NewNode1)
               print(row1['moment'])
               G.add_edge(NewNode, NewNode1, key= "startingtime")
               print("   ")

           for row2 in finishedby:
               NewNode = "L3-Destinations_" + row2['user']
               print(NewNode)
               Latitude= row2['coordinate']['latitude']
               Longitude= row2['coordinate']['longitude']
               G.add_node(NewNode)
               print(row2['coordinate']['latitude'])
               print(row2['coordinate']['longitude'])
               print(row2['moment'])
               NewNode1 = "L2-time_" + row2['user']
               Moment = row2['moment']
               G.add_node(NewNode1)
               G.add_edge(NewNode, NewNode1, key= "endtime")

               print("   ")








def matchinggraph():
    travelfetch()
    userfetch()

    print(nx.info(G))
    nx.write_gpickle(G, "/home/zarah/Downloads/multigraph1.gpickle")

matchinggraph()

print(Users)