insert_universities.py 862 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
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
#!/usr/bin/env python3

"""
Script to insert the country data in the database

IT HAS TO BE RUN INSIDE ./manage.py shell
"""
import csv 
import os

from rex.models.country import Country
from rex.models.university import University 

tmp = os.path.join(os.path.realpath(__file__), '../../assets/destinations_extracted.csv')
destinations_path = os.path.abspath(tmp)

if not os.path.isfile(destinations_path):
    print(destinations_path)
    raise Exception("Missing file containing country data")

with open(destinations_path, 'rt') as f:
    reader = csv.reader(f)

    # will be changed during university.save
    # dumb_country =  Country.objects.get(pk='FR')
    for row in reader:
        if row[0] != 'University':
            u = University(name=row[0], acronym='NULL', localization_lat=float(row[1]), localization_lon=float(row[2]))
            u.save()