Skip to content

Instantly share code, notes, and snippets.

@ryanmcgrath
Created November 11, 2012 23:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmcgrath/4056785 to your computer and use it in GitHub Desktop.
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.
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