jsonToFixture.py 1.46 KB
Newer Older
Michael Lundquist's avatar
Michael Lundquist committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
import json
print("HI")
with open('./openTimes.json') as f:
    x = json.loads(f.read())

"""Yes, this file is totally unnecessary but I didn't have access to the dumpdata command so I did this."""

newList = list()

open_times = list()

for i in x:
    nextSet = {
        "pk": None,
        "model": "api.OpenTime",
        "fields": i
    }
    #{ "model":"api.category", "pk": i[1]["id"], "fields":{ "name": i[1]["name"] } }
    newList.append(nextSet)

"""
#For schedules
    cpy = dict(i)
    open_times += list( i["open_times"] )
    del( cpy["id"] )
    del( cpy["open_times"] )

    nextSet = {
        "pk": i["id"],
        "model": "api.schedule",
        "fields": cpy
    }
    #{ "model":"api.category", "pk": i[1]["id"], "fields":{ "name": i[1]["name"] } }
    newList.append(nextSet)
"""
"""
#for categories
nextSet = { "model":"api.category", "pk": i[1]["id"], "fields":{ "name": i[1]["name"] } }

#for buildings

"""
"""
#FOR LOCATION
    coords = i["coordinate_location"]["coordinates"]
    
    nextSet = { 
        "fields": {
            "building": i["building"],
            "friendly_building": i["friendly_building"],
            "address": i["address"],
            "campus_region": i["campus_region"],
            "coordinate_location":"SRID=4326;POINT (" + str(coords[0]) + " " + str(coords[1]) + ")" ,"on_campus":i["on_campus"],
        },
    "model": "api.location",
    "pk": i["id"] }
    """

with open("./fixtureOut.json", "w") as f:
    json.dump(newList, f)