Skip to content
Snippets Groups Projects
Verified Commit 5e6a688b authored by Robert Metcalf's avatar Robert Metcalf
Browse files

change import database tool to import from JSON

parent 9de2d5c9
No related branches found
No related tags found
1 merge request!8Allow working spaces to be added
import database
import os
import json
workspace = database.Workspace(
"CodeBase",
"CodeBase Edinburgh, 37a Castle Terrace, Edinburgh, EH1 2EL",
"https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1505921023376-PAHUDHVOOKIYF4XQPHOO/5951229048_3e3d50fcb1_o.jpg?format=750w",
["https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1636387943314-W9JWMS6ZX4DEZSPUV7T0/Copy+of+Unfiltered_square+%281%29.png?format=500w"],
"We've been exploring the world of startups...",
"https://www.thisiscodebase.com",
"hannah@thisiscodebase.com",
"+44 131 560 2003",
"Monday - Friday, 9am - 5pm",
"Tramsched members should contact Hannah using the email address listed."
)
def import_workspace(data):
workspace = database.Workspace(
data["name"],
data["address"],
data["main_photo"],
data["additional_photos"],
data["description"],
data["website"],
data["email"],
data["phone_number"],
data["opening_hours"],
data["checkin_instructions"]
)
database.set_address_latlong(workspace.address, (55.9471623, -3.203928))
print(database.add_workspace(workspace))
latlong = data["latlong"]
if latlong != None:
database.set_address_latlong(workspace.address, (latlong[0], latlong[1]))
database.add_workspace(workspace)
file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "workspaces.json")
with open(file, "r", encoding="utf8") as stream:
data = json.load(stream)
for workspace in data:
import_workspace(workspace)
print(f"Imported {len(data)} workspace(s)")
[{
"name": "CodeBase",
"address": "CodeBase Edinburgh, 37a Castle Terrace, Edinburgh, EH1 2EL",
"main_photo": "https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1505921023376-PAHUDHVOOKIYF4XQPHOO/5951229048_3e3d50fcb1_o.jpg?format=750w",
"additional_photos": ["https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1636387943314-W9JWMS6ZX4DEZSPUV7T0/Copy+of+Unfiltered_square+%281%29.png?format=500w"],
"description": "We've been exploring the world of startups...",
"website": "https://www.thisiscodebase.com",
"email": "hannah@thisiscodebase.com",
"phone_number": "+44 131 560 2003",
"opening_hours": "Monday - Friday, 9am - 5pm",
"checkin_instructions": "Tramsched members should contact Hannah using the email address listed.",
"latlong": [55.9471623, -3.203928]
}]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment