-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_data_test.py
57 lines (42 loc) · 1.44 KB
/
load_data_test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys, os
import urllib2
import csv
import django
# directory to outer parkpedia_project
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# url path for csv
csv_parks = os.path.join(BASE_DIR, 'test.csv')
# facilities csv file directory
csv_facilities = os.path.join(BASE_DIR, 'test_facilities.csv')
your_djangoproject_home = BASE_DIR
sys.path.append(your_djangoproject_home)
os.environ['DJANGO_SETTINGS_MODULE'] = 'parkpedia_project.settings'
from parkpedia.models import Park
dataPark = csv.reader(open(csv_parks))
dataFacilities = csv.reader(open(csv_facilities))
django.setup()
# flushes out the database
p = Park.objects.all()
p.delete()
for row in dataPark:
if row[0] != 'ParkID': # Ignore the header row, import everything else
park = Park()
park.parkId = row[0]
park.name = row[1]
park.streetNum = row[3]
park.streetName = row[4]
park.latLon = row[7]
if row[14] == "N":
park.washroom = "No"
if row[14] == "Y":
park.washroom = "Yes"
for row0 in dataFacilities:
if row0[0] != 'ParkID':
if row0[0] == park.parkId:
if park.facilities == "None":
park.facilities = ""
park.facilities = park.facilities + ' | ' + row0[2]
else:
park.save()
break
park.save()