-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_art_map.py
34 lines (30 loc) · 1.03 KB
/
populate_art_map.py
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
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vancouver_art.settings')
import django
django.setup()
from django.conf import settings
from art_map.models import ArtPiece
import json
def populate():
file_name = os.path.join(settings.BASE_DIR, 'static/public_art.json')
json_file = open(file_name)
json_content = json_file.read()
json_data = json.loads(json_content)
for i in range(len(json_data[1]['features'])):
add_piece(json_data[1]['features'][i]['properties']['TitleOfWork'],
json_data[1]['features'][i]['properties']['DescriptionOfwork'],
json_data[1]['features'][i]['properties']['PhotoURL'],
json_data[1]['features'][i]['properties']['Latitude'],
json_data[1]['features'][i]['properties']['Longitude'])
json_file.close()
def add_piece(title, description, photo, lat, lon):
p = ArtPiece(title=title,
description=description,
photoURL=photo,
lat=lat,
lon=lon)
p.save()
return p
if __name__ == '__main__':
print "Starting art_map population script..."
populate()