Created
November 11, 2012 23:56
-
-
Save ryanmcgrath/4056785 to your computer and use it in GitHub Desktop.
Scrapes area names from CL. They seem to be on the ball with that stuff.
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 import setup_environ | |
from django.contrib.localflavor.us.us_states import STATE_CHOICES | |
from pyquery import PyQuery as pq | |
import settings, time | |
setup_environ(settings) | |
from myproject.writers.models import Location | |
for choice in STATE_CHOICES: | |
try: | |
print '\nFetching %s' % choice[1] | |
list = pq(url = 'http://geo.craigslist.org/iso/us/%s' % choice[0]).find('#list') | |
areas = [pq(a).text().title() for a in list.find('a')] | |
for area in areas: | |
print 'Adding %s, %s' % (area, choice[1]) | |
Location.objects.create(city = area, state = choice[0]) | |
except: | |
print 'Shit done fucked up somewhere, looks like this fucking %s do not exit broseph' % choice[1] | |
print '"Done". Sleeping for 10 seconds...' | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment