-
-
Save dpritchett/45072d257d0dd48c003c to your computer and use it in GitHub Desktop.
cron-scheduled Django task that imports a nightly data feed from a government database and loads it into my own backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand, CommandError | |
import neighborhoods.views | |
from neighborhoods.models import Crime | |
import urllib2, json | |
class Command(BaseCommand): | |
args = 'No arguments yet' | |
help = "Reads yesterday's MPD data into the database" | |
def handle(self, *args, **options): | |
new_crimes = neighborhoods.views.get_crime_in_xml_for_day_offset(offset=2) | |
crimes_list = neighborhoods.views.crime_list_from_xml(new_crimes) | |
for crime in crimes_list: | |
saved_crime = neighborhoods.views.save_mpd_crime_from_dict(crime) | |
neighborhoods.views.add_zip_to_crime(saved_crime) | |
self.stdout.write(str(saved_crime) + "\t ZIP: " + str(saved_crime.zip_code) + "\n") | |
self.stdout.write(str(len(crimes_list)) + ' records processed.\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# m h dom mon dow command | |
@midnight cd /home/daniel/myapps/operation/opsafe && /home/daniel/myapps/operation/bin/python /home/daniel/myapps/operation/opsafe/manage.py nightly_crime_load > /tmp/cronlog.txt 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment