-
Notifications
You must be signed in to change notification settings - Fork 1
/
addDB.py
71 lines (49 loc) · 1.77 KB
/
addDB.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import csv
import os
from unicodedata import category
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'assertive_prj.settings')
django.setup()
from main.models import Category,TourSpot,Option
def main():
with open('category.csv' ,encoding='UTF8') as in_file:
data_reader = csv.reader(in_file)
next(data_reader,None)
for row in data_reader:
categories = Category.objects.all()
if len(row)==0: continue
if row not in categories:
Category.objects.create(
name = row[0],
slug = row[0]
)
with open('data.csv' ,encoding='UTF8') as in_file:
data_reader = csv.reader(in_file)
next(data_reader,None)
categories = Category.objects.all()
for row in data_reader:
for op in categories:
if len(row)==0: continue
if row[2]==str(op):
TourSpot.objects.create(
place = row[0],
location = row[1],
category = op,
mapX = row[3],
mapY = row[4],
like = False
)
with open('withTrouble.csv',encoding='UTF8')as in_file:
data_reader = csv.reader(in_file)
next(data_reader,None)
for row in data_reader:
print(row)
if len(row)==0:continue
for col in range(1,len(row)-1):
if len(row[col])==0:continue
Option.objects.create(
tourspot = TourSpot.objects.get(place = row[0]),
name = row[col],
)
if __name__ == "__main__":
main()