def handle(self, **options):
        for url in URLS:
            data = json.loads(urllib2.urlopen(url).read())
            for area in data:
                center = self.find_center(area['ons_code'])
                for result in area['results']:
                    try:
                        item = GeoItem.objects.get(
                            item_type='guardian-article', url=result['url'])
                    except GeoItem.DoesNotExist:
                        item = GeoItem(item_type='guardian-article',
                                       url=result['url'])

                    item.description = result['description']
                    item.image_url = result.get('imageUrl', None)
                    item.url = result.get('url', None)

                    if result.get('lat'):
                        item.location = Point(
                            map(float, (result['lng'], result['lat'])))
                    else:
                        item.location = Point((center.x, center.y))

                    item.save()

                    if 'attachments' in result:
                        for attachment in result['attachments']:
                            try:
                                a = Attachment.objects.get(
                                    geoitem=item, url=attachment['url'])
                            except Attachment.DoesNotExist:
                                a = Attachment(geoitem=item,
                                               url=attachment['url'])
                            a.caption = attachment['caption']
                            a.save()
Beispiel #2
0
 def handle(self, **options):
     for url in URLS:
         data =  json.loads(urllib2.urlopen(url).read())
         for area in data:
             center = self.find_center(area['ons_code'])
             for result in area['results']:
                 try:
                     item = GeoItem.objects.get(item_type='guardian-article', url=result['url'])
                 except GeoItem.DoesNotExist:
                     item = GeoItem(item_type='guardian-article', url=result['url'])
                 
                 item.description = result['description']
                 item.image_url = result.get('imageUrl', None)
                 item.url = result.get('url', None)
                 
                 if result.get('lat'):
                     item.location = Point(map(float, (result['lng'], result['lat'])))
                 else:
                     item.location = Point((center.x, center.y))
                 
                 item.save()
                 
                 if 'attachments' in result:
                     for attachment in result['attachments']:
                         try:
                             a = Attachment.objects.get(geoitem=item, url=attachment['url'])
                         except Attachment.DoesNotExist:
                             a = Attachment(geoitem=item, url=attachment['url'])
                         a.caption = attachment['caption']
                         a.save()
 def handle(self, **options):
     for zoom, grid_size in settings.GRID_SIZES:
         g = Grid(zoom, grid_size)
         for box in g:
             url = BASE_URL + "&north=%s&south=%s&east=%s&west=%s" % (
                 box.east, box.west, box.north, box.south)
             print url
             data = json.loads(urllib2.urlopen(url).read())
             print str(data)[:150]
             for page in data['geonames']:
                 location = Point(map(float, (page['lng'], page['lat'])))
                 try:
                     item = GeoItem.objects.get(item_type='wikipeida',
                                                title=page['title'])
                 except GeoItem.DoesNotExist:
                     item = GeoItem(item_type='wikipeida',
                                    title=page['title'])
                 item.location = location
                 item.image_url = page.get('thumbnailImg', None)
                 item.url = "http://" + page['wikipediaUrl']
                 item.description = page['summary']
                 item.save()
 def handle(self, **options):
     for zoom, grid_size in settings.GRID_SIZES:
         g = Grid(zoom, grid_size)
         for box in g:
             url = BASE_URL + "&north=%s&south=%s&east=%s&west=%s" % (box.east, box.west, box.north, box.south)
             print url
             data = json.loads(urllib2.urlopen(url).read())
             print str(data)[:150]
             for page in data["geonames"]:
                 location = Point(map(float, (page["lng"], page["lat"])))
                 try:
                     item = GeoItem.objects.get(item_type="wikipeida", title=page["title"])
                 except GeoItem.DoesNotExist:
                     item = GeoItem(item_type="wikipeida", title=page["title"])
                 item.location = location
                 item.image_url = page.get("thumbnailImg", None)
                 item.url = "http://" + page["wikipediaUrl"]
                 item.description = page["summary"]
                 item.save()