@@ -0,0 +1,2130 @@
+from django.conf import settings%0Afrom railtracker.mapfeed.models import Incident, MapCity, MapLine%0Afrom pprint import pprint%0Aimport twitter, httplib, urllib, base64, json%0A%0A#Functions%0Adef loadIncidents():%0A    city = MapCity.objects.get(city_name=%22Washington D.C.%22).id%0A    lines = MapLine.objects.filter(map=city)%0A    try:%0A        conn.request(%22GET%22, %22/Incidents.svc/json/Incidents?%25s%22 %25 params, %22%22, headers)%0A        response = conn.getresponse()%0A        data = response.read()%0A        conn.close()%0A    except Exception as e:%0A        pprint(%22%5BErrno %7B0%7D%5D %7B1%7D%22.format(e.errno, e.strerror))%0A    decoded_inc = json.loads(data)%0A    pprint(decoded_inc)%0A    #Go through incident list and load into database%0A    for incident in decoded_inc%5B'Incidents'%5D:%0A        obj_date = incident%5B'DateUpdated'%5D.replace('T', ' ')%0A        obj_desc = incident%5B'Description'%5D%0A        num_results = Incident.objects.filter(incident_date=obj_date).filter(description=obj_desc).count()%0A        if num_results %3C 1:%0A            inc_model = Incident(%0A                    description=obj_desc,%0A                    incident_date=obj_date,%0A                    warning=incident%5B'IncidentType'%5D%5B:3%5D%0A            )%0A            pprint(inc_model)%0A            inc_model.save()%0A            pprint(inc_model)%0A            for line in lines:%0A                if line.line_code in incident%5B'LinesAffected'%5D:%0A                    inc_model.lines.add(line)%0A%0Adef loadTweets():%0A    api = twitter.Api(%0A            consumer_key=settings.TWITTER_CONSUMER_KEY,%0A            consumer_secret=settings.TWITTER_CONSUMER_SECRET,%0A            access_token_key=settings.TWITTER_TOKEN,%0A            access_token_secret=settings.TWITTER_TOKEN_SECRET%0A    )%0A    statuses = api.GetUserTimeline(screen_name='MetroRailInfo')%0A    for s in statuses:%0A        if '@' not in s.text:%0A            pprint(s.text)%0A%0A#Vars%0Aheaders = %7B%0A%7D%0A%0Aparams = urllib.urlencode(%7B%0A    'api_key': settings.DC_PRIMARY_KEY%0A%7D)%0A%0Aconn = httplib.HTTPSConnection('api.wmata.com')%0A%0Atest_inc = %7B'Incidents': %5B%7B%0A    'Description': 'This is a test incident.',%0A    'DateUpdated': '2015-02-04 12:59:59',%0A%7D%5D%7D%0A%0A#Calls%0AloadIncidents()%0A#loadTweets()%0A

rename incident script