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 database
import os
import json
workspace = database.Workspace( def import_workspace(data):
"CodeBase", workspace = database.Workspace(
"CodeBase Edinburgh, 37a Castle Terrace, Edinburgh, EH1 2EL", data["name"],
"https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1505921023376-PAHUDHVOOKIYF4XQPHOO/5951229048_3e3d50fcb1_o.jpg?format=750w", data["address"],
["https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1636387943314-W9JWMS6ZX4DEZSPUV7T0/Copy+of+Unfiltered_square+%281%29.png?format=500w"], data["main_photo"],
"We've been exploring the world of startups...", data["additional_photos"],
"https://www.thisiscodebase.com", data["description"],
"hannah@thisiscodebase.com", data["website"],
"+44 131 560 2003", data["email"],
"Monday - Friday, 9am - 5pm", data["phone_number"],
"Tramsched members should contact Hannah using the email address listed." data["opening_hours"],
) data["checkin_instructions"]
)
database.set_address_latlong(workspace.address, (55.9471623, -3.203928)) latlong = data["latlong"]
print(database.add_workspace(workspace)) 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.
Please register or to comment