コード例 #1
0
    def handle(self, *args, **options):
        self.stdout.write(self.help)

        if options['download']:
            self.stdout.write('Download all routes')
            dumps = download_rzd_trains(max_days_range=90)
        else:
            dumps = JsonDump.objects.filter(status='downloaded')
            self.stdout.write('Current downloaded routes: {}'.format(
                len(dumps)))

        if options['parse']:
            self.stdout.write('Parse dumps')
            for dump in dumps:
                self.stdout.write('  < Parse dump {}'.format(dump.filename))

                parser = RzdParser(dump.get_data(), dump.trip)
                for way, routes in parser.parse():
                    routes = list(routes)
                    print(
                        '        Parsed way: {}, routes: {}, save? {}'.format(
                            way, len(routes), not options['no_save']))
                    if not options['no_save']:
                        Updater(routes).update()

                self.stdout.write(
                    '  > Total: parsed {} ways, {} routes, saved? {}\n'.format(
                        parser.ways_count, parser.routes_count,
                        not options['no_save']))
                if not options['no_save']:
                    dump.status = 'parsed'
                    dump.save()
コード例 #2
0
ファイル: views.py プロジェクト: nerevar/htravel
def add_test_trips(request):
    # TODO: починить
    response_text = ''
    for filename in crawler.get_latest_dumps():
        with open(filename) as f:
            data = json.load(f)
        parser = RzdParser(data)
        for way, routes in parser.parse():
            Updater(routes).add()

        response_text += 'Saved {} ways, {} routes from file: {} <br/>'.format(
            parser.ways_count, parser.routes_count, filename)

    return HttpResponse(response_text)
コード例 #3
0
ファイル: views.py プロジェクト: nerevar/htravel
def add_test_second_trip(request):
    response_text = ''
    for filename in [
            './robot/dumps/rzd/moscow/spb/2018-04-20-2018-04-22/2018-04-09--11-13-52-044707.json'
    ]:
        with open(filename) as f:
            data = json.load(f)
        trip = Trip.trips.get_by_cities('moscow', 'spb')
        parser = RzdParser(data, trip)

        for way, routes in parser.parse():
            Updater(routes).update()

        response_text += 'Saved {} ways, {} routes from file: {} <br/>'.format(
            parser.ways_count, parser.routes_count, filename)

    return HttpResponse(response_text)
コード例 #4
0
ファイル: views.py プロジェクト: nerevar/htravel
def download_test_routes(request):
    # TODO: починить
    response_text = ''
    way = Way.filtered.get_by_cities('moscow', 'spb')

    c = RzdTrainsCrawler(way, datetime(2018, 4, 20), datetime(2018, 4, 22))
    data = c.download()
    c.save_to_file()
    c.save_to_db()

    parser = RzdParser(data)
    for way, routes in parser.parse():
        Updater(routes).add()

    response_text += 'Saved {} ways, {} routes <br/>'.format(
        parser.ways_count, parser.routes_count)

    return HttpResponse(response_text)
コード例 #5
0
 def fetch(self):
     updater = Updater()
     updater.fetch()
コード例 #6
0
 def update(self):
     updater = Updater()
     return updater.update()