Ejemplo n.º 1
0
# NOTE: Only run this file once!
# This file will setup the database for initial use.
# Specifically, it will insert the default location names into the database
# so that people don't have to find them on their own every time.
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "frc_scout_2015.settings")
import django
django.setup()

from frc_scout.models import Location
from frc_scout.views.loc_list import locations

if __name__ == "__main__":
    for loc_name in locations:
        new_loc = Location(name=loc_name)
        new_loc.save()
        print("Added location: " + loc_name)
Ejemplo n.º 2
0
APP_ID = "frc4030:frcscout.com:v1"

TBA_URL = "http://www.thebluealliance.com/api/v2/events/2016?X-TBA-App-Id=" + APP_ID

tba_locations = None

try:
    tba_locations = requests.get(TBA_URL).json()
except ValueError:
    print("Unable to parse JSON, check your URL.")
    exit(-1)

for tba_location in tba_locations:
    already_existed = False
    try:
        scout_location = Location.objects.get(name=tba_location['name'])
        already_existed = True
    except Location.DoesNotExist:
        scout_location = Location(name=tba_location['name'])

    print(
        str(scout_location) + " -- already existed in our db: " +
        str(already_existed) + " added code " + tba_location['event_code'])

    scout_location.tba_event_code = tba_location['event_code']
    scout_location.venue_address = tba_location['venue_address']
    scout_location.location = tba_location['location']

    scout_location.save()
Ejemplo n.º 3
0
django.setup()

from frc_scout.models import Location

APP_ID = "frc4030:frcscout.com:v1"

TBA_URL = "http://www.thebluealliance.com/api/v2/events/2015?X-TBA-App-Id=" + APP_ID

try:
    tba_locations = requests.get(TBA_URL).json()
except ValueError:
    print("Unable to parse JSON, check your URL.")
    exit(-1)

for tba_location in tba_locations:
    already_existed = False
    try:
        scout_location = Location.objects.get(name=tba_location['name'])
        already_existed = True
    except Location.DoesNotExist:
        scout_location = Location(name=tba_location['name'])

    print(str(scout_location) + " -- already existed in our db: " + str(already_existed) + " added code " + tba_location['event_code'])

    scout_location.tba_event_code = tba_location['event_code']
    scout_location.venue_address = tba_location['venue_address']
    scout_location.location = tba_location['location']

    scout_location.save()