def insertTrack(track_data, date_current, time_current, location):
    track_data.pop("mediaType", None)
    track_data.pop("message", None)
    track_data.pop("t_type", None)
    cursor = connection.cursor()
    cursor.execute("SELECT * from pahera_modularisedtracks")
    track_list_Data = DictFetchAll.dictfetchall(cursor)
    fName = track_list_Data[0]['json_file_path']
    js_data = {}
    js_data = track_data
    js_data['date'] = date_current
    js_data['time'] = time_current
    json_file = open(fName, 'r+')
    json_data = json.load(json_file)
    json_file.close()
    if json_data :      # To Check if there is a entry o not..!!!
        for post in json_data:
            for post1 in post:      # Looping through countries..!!!
                if post1 == track_data['country']:
                    for post2 in post[track_data['country']]:
                        for j in post2:     # Looping through States..!!!
                            if j == track_data['state']: 
                                for post3 in post2.values():
                                    for i in post3:     # Looping through Cities..!!!
                                        for k in i.keys():
                                            if k == track_data['state_district']:
                                                i[track_data['state_district']].append(track_data)
                                                json_file = open(fName, 'w+')
                                                json_file.write(json.dumps(json_data, sort_keys=True, indent=4, separators=(',', ': ')))
                                                json_file.close()
                                                return
                                else:   # If no record with a particular city..!!!
                                    post3.append({track_data['state_district'] : [ track_data ] } )
                                    json_file = open(fName, 'w+')
                                    json_file.write(json.dumps(json_data, sort_keys=True, indent=4, separators=(',', ': ')))
                                    json_file.close()
                                    return
                    else:   # If no record with a particular State..!!!
                        post[track_data['country']].append( { track_data['state'] : [ { track_data['state_district'] : [ track_data ] } ] } )
                        json_file = open(fName, 'w+')
                        json_file.write(json.dumps(json_data, sort_keys=True, indent=4, separators=(',', ': ')))
                        json_file.close()
                        return
                else:   # If no record with a particular Country..!!!
                    json_data.append({ track_data['country'] : [ { track_data['state'] : [ { track_data['state_dist'] : [ track_data ] } ] } ] } )
                    json_file = open(fName, 'w+')
                    json_file.write(json.dumps(json_data, sort_keys=True, indent=4, separators=(',', ': ')))
                    json_file.close()
                    return
                
    else:   # If no record in the file at all..!!!
        js_file_data = {}
        js_file_data = [ { track_data['country'] : [ { track_data['state'] : [ { track_data['state_district'] : [ js_data ] } ] } ] } ]
        json_file = open(fName, 'w+')
        json_file.write(json.dumps(js_file_data, sort_keys=True, indent=4, separators=(',', ': ')))
        return
def VerifyTheUser(data):
    cursor = connection.cursor()
    email = data['email']
    phone = data['phone']
    cursor.execute("SELECT * from pahera_person WHERE email = %s OR phone_no = %s", [email, phone])
    person_Data = {}
    person_Data = DictFetchAll.dictfetchall(cursor)
    if person_Data:
        if person_Data[0]['email'] == email or person_Data[0]['phone_no'] == phone:
            return False
        else:
            return True
    else:
        return True
def fetch_contacts(person):
    data_new = {}
    dataDB = {"result": []}
    count = {}
    value = 0
    count["count"] = "0"
    cursor = connection.cursor()

    cursor.execute("SELECT * from pahera_trusted_friends WHERE person_id = %s", [person.id])

    friend_Data = {}
    friend_Data = DictFetchAll.dictfetchall(cursor)
    for post in friend_Data:
        value += 1
        post["count"] = value
        dataDB["result"].append(post)
        count["count"] = value
    scriptpath = os.path.dirname("./static/JSON/temp/")
    fName = os.path.join(scriptpath, "MyContacts.json")
    WritingToJson.writeJSON2(dataDB, fName)