Esempio n. 1
0
    def do(self):
        dataNowMtl = urllib.urlopen('http://montreal.bixi.com/data/bikeStations.xml')
        root = etree.parse(dataNowMtl)

        for ele in root.xpath("//stations/station"):
            if ele.xpath("installed")[0].text == "true" and ele.xpath("locked")[0].text == "false":
                try:
                    s = Station.objects.get(station_id = int(ele.xpath("id")[0].text))
                    s.name = ele.xpath("name")[0].text
                    s.latitude = float(ele.xpath("lat")[0].text)
                    s.longitude = float(ele.xpath("long")[0].text)
                except ObjectDoesNotExist:
                    s = Station(station_id = int(ele.xpath("id")[0].text), name = ele.xpath("name")[0].text, latitude = float(ele.xpath("lat")[0].text), longitude = float(ele.xpath("long")[0].text))
                    s.save()
            else:
                try:
                    s = Station.objects.get(station_id = int(ele.xpath("id")[0].text))
                    s.delete()
                except ObjectDoesNotExist:
                    continue  
Esempio n. 2
0
    def handle(self, *args, **options):
        Station.objects.all().delete()
        dataNowMtl = urllib.urlopen('http://montreal.bixi.com/data/bikeStations.xml')

        root = etree.parse(dataNowMtl)
        for ele in root.xpath("//stations/station"):
            if ele.xpath("installed")[0].text == "true" and ele.xpath("locked")[0].text == "false":
                s = Station(station_id = int(ele.xpath("id")[0].text), name = ele.xpath("name")[0].text, latitude = float(ele.xpath("lat")[0].text), longitude = float(ele.xpath("long")[0].text))
                s.save()
        self.stdout.write('Successfully updated station info')
                
        # for poll_id in options['poll_id']:
        #     try:
        #         poll = Poll.objects.get(pk=poll_id)
        #     except Poll.DoesNotExist:
        #         raise CommandError('Poll "%s" does not exist' % poll_id)

        #     poll.opened = False
        #     poll.save()

        #     self.stdout.write('Successfully closed poll "%s"' % poll_id)
Esempio n. 3
0
    def do(self):
        dataNowMtl = urllib.urlopen(
            'http://montreal.bixi.com/data/bikeStations.xml')
        root = etree.parse(dataNowMtl)

        for ele in root.xpath("//stations/station"):
            if ele.xpath("installed")[0].text == "true" and ele.xpath(
                    "locked")[0].text == "false":
                try:
                    s = Station.objects.get(
                        station_id=int(ele.xpath("id")[0].text))
                    s.name = ele.xpath("name")[0].text
                    s.latitude = float(ele.xpath("lat")[0].text)
                    s.longitude = float(ele.xpath("long")[0].text)
                except ObjectDoesNotExist:
                    s = Station(station_id=int(ele.xpath("id")[0].text),
                                name=ele.xpath("name")[0].text,
                                latitude=float(ele.xpath("lat")[0].text),
                                longitude=float(ele.xpath("long")[0].text))
                    s.save()
            else:
                try:
                    s = Station.objects.get(
                        station_id=int(ele.xpath("id")[0].text))
                    s.delete()
                except ObjectDoesNotExist:
                    continue