# Path: sitegeist/data/schools/models.py
# class School(models.Model):
# 
#     objects = models.GeoManager()
# 
#     nces_id = models.CharField(max_length=12)
#     name = models.CharField(max_length=128)
#     street = models.CharField(max_length=128, blank=True)
#     city = models.CharField(max_length=128, blank=True)
#     state = models.CharField(max_length=2, blank=True)
#     zipcode = models.CharField(max_length=5, blank=True)
#     enrollment = models.IntegerField(blank=True, null=True)
#     locale_code = models.CharField(max_length=2, choices=LOCALES, blank=True)
#     type_code = models.CharField(max_length=1, choices=TYPES, blank=True)
#     level_code = models.CharField(max_length=1, choices=LEVEL_CODES, blank=True)
#     level_low = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     level_high = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     status = models.CharField(max_length=1, choices=STATUSES, blank=True)
# 
#     lon = models.FloatField(blank=True, null=True)
#     lat = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name


import csv
import os
import zipfile
import requests
from django.conf import settings
from sitegeist.data.schools.models import School



DATA_URL = "http://nces.ed.gov/ccd/data/zip/sc091a_csv.zip"


def load():

    filename = DATA_URL.split('/')[-1]
    dir_name = filename.split('.')[0]

    dl_path = os.path.join(settings.SITEGEIST['DATA_CACHE'], 'schools')
    extract_path = os.path.join(dl_path, dir_name)
    zip_path = os.path.join(dl_path, filename)

    if not os.path.exists(dl_path):
        os.mkdir(dl_path)


# Path: sitegeist/data/schools/models.py
# class School(models.Model):
# 
#     objects = models.GeoManager()
# 
#     nces_id = models.CharField(max_length=12)
#     name = models.CharField(max_length=128)
#     street = models.CharField(max_length=128, blank=True)
#     city = models.CharField(max_length=128, blank=True)
#     state = models.CharField(max_length=2, blank=True)
#     zipcode = models.CharField(max_length=5, blank=True)
#     enrollment = models.IntegerField(blank=True, null=True)
#     locale_code = models.CharField(max_length=2, choices=LOCALES, blank=True)
#     type_code = models.CharField(max_length=1, choices=TYPES, blank=True)
#     level_code = models.CharField(max_length=1, choices=LEVEL_CODES, blank=True)
#     level_low = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     level_high = models.CharField(max_length=2, choices=LEVELS, blank=True)
#     status = models.CharField(max_length=1, choices=STATUSES, blank=True)
# 
#     lon = models.FloatField(blank=True, null=True)
#     lat = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name


# Path: sitegeist/data/schools/loading.py
import csv
import os
import zipfile
import requests
from django.conf import settings
from sitegeist.data.schools.models import School




DATA_URL = "http://nces.ed.gov/ccd/data/zip/sc091a_csv.zip"


def load():

    filename = DATA_URL.split('/')[-1]
    dir_name = filename.split('.')[0]

    dl_path = os.path.join(settings.SITEGEIST['DATA_CACHE'], 'schools')
    extract_path = os.path.join(dl_path, dir_name)
    zip_path = os.path.join(dl_path, filename)

    if not os.path.exists(dl_path):
        os.mkdir(dl_path)


    if not os.path.exists(extract_path):