Esempio n. 1
0
def get_stops():
    ''' The initial query to set up the stop db '''
    all_stops = DB_Stop.query.all()
    all_ids = [stop.id for stop in all_stops]
    url = "http://www.swu.de/fileadmin/gtfs/stops.txt"
    req = requests.get(url)
    req.encoding = "utf-8"
    text = req.text.split("\n")[1:]
    for line in text:  # start in line 35 to exlclude stops in Poland
        if len(line) > 1:
            Stop = VBB_Stop(line)
            if Stop.stop_id not in all_ids and int(Stop.ismainstation) != 0:
                feedback = Stop.is_in_osm()
                if feedback > 0:
                    print_success(Stop.name + ": " + str(feedback))
                else:
                    print_failure(Stop.name + ":  0")
                new_stop = DB_Stop(
                    name=Stop.name,
                    lat=Stop.lat,
                    lon=Stop.lon,
                    matches=feedback,
                    vbb_id=Stop.stop_id
                )
                db.session.add(new_stop)
                db.session.commit()
Esempio n. 2
0
def logview(logfile):
    with open(logfile, "r") as infile:
        t = infile.readlines()
    for line in t:
        if "root" in line:
            line = line.replace("\n", "")
            if "in_osm" in line:
                print_info(line)
            elif "recheck" in line:
                parts = line.split("[recheck]")[1].split(";")
                old = int(parts[1].split(":")[1])
                new = int(parts[2].split(":")[1])
                if new > old:
                    print_success(line)
                else:
                    print_failure(line)
Esempio n. 3
0
def logview(logfile):
    with open(logfile, "r") as infile:
        t = infile.readlines()
    for line in t:
        if "root" in line:
            line = line.replace("\n", "")
            if "in_osm" in line:
                print_info(line)
            elif "recheck" in line:
                parts = line.split("[recheck]")[1].split(";")
                old = int(parts[1].split(":")[1])
                new = int(parts[2].split(":")[1])
                if new > old:
                    print_success(line)
                else:
                    print_failure(line)
Esempio n. 4
0
def get_trains():
    ''' The initial query to set up the train db '''
    url = "http://datenfragen.de/openvbb/GTFS_VBB_Okt2012/routes.txt"
    req = requests.get(url)
    text = req.text.split("\n")
    for line in text:
        Train = Bvg_line(line)
        if Train.operator in ["BVG", "DB"]:
            feedback = Train.is_in_osm()
            if feedback:
                print_success(feedback)
            else:
                print_failure(Train.line_number + " is not in OSM")
            db_rep = DB_Train()
            db.session.add(db_rep)
            db.session.commit()
Esempio n. 5
0
def recheck(id, from_cm_line=False):
    ''' Rerun the checks for a stop and update the db'''
    stop = Stop.query.filter_by(id=id).first()
    old_matches = stop.matches
    stop.matches = stop.is_in_osm()
    stop.last_run = datetime.datetime.now().replace(microsecond=0)
    db.session.commit()
    if not from_cm_line:
        logging.info(
            "[recheck] Name: %-5s; Old: %-3i; New: %-3i; IP: %-3s" %
            (stop.name, old_matches, stop.matches, request.remote_addr))
        return redirect(url_for("pagination", number=1, city=stop.county))
    else:
        if stop.matches > 0:
            print_success("%s now matches %i stops" %
                          (stop.name, stop.matches))
        else:
            print_failure("%s does not match any stops..." % (stop.name))
        return stop.matches
Esempio n. 6
0
def recheck(id, from_cm_line=False):
    ''' Rerun the checks for a stop and update the db'''
    stop = DB_Stop.query.filter_by(id=id).first()
    old_matches = stop.matches
    stop.matches = VBB_Stop(stop.to_vbb_syntax(), stop.exception).is_in_osm()
    stop.last_run = datetime.datetime.now().replace(microsecond=0)
    db.session.commit()
    if not from_cm_line:
        logging.info("[recheck] Name: %-5s; Old: %-3i; New: %-3i; IP: %-3s" % (stop.name,
                                                                       old_matches,
                                                                       stop.matches,
                                                                       request.remote_addr))
        return redirect(url_for("pagination", number=1, city=stop.landkreis))
    else:
        if stop.matches > 0:
            print_success("%s now matches %i stops" % (stop.name,
                                                       stop.matches))
        else:
            print_failure("%s does not match any stops..." % (stop.name))
        return stop.matches
Esempio n. 7
0
def get_stops():
    ''' The initial query to set up the stop db '''
    all_stops = Stop.query.all()
    all_ids = [stop.id for stop in all_stops]
    url = config.stops_txt_url
    req = requests.get(url)
    req.encoding = 'utf-8'
    text = req.text.split('\n')
    reader = csv.DictReader(text, delimiter=',', quotechar='"')
    counter = 0
    for line in reader:
        stop = Stop(line)
        if stop.isStation and stop.id not in all_ids:
            stop.matches = stop.is_in_osm()
            if stop.matches > 0:
                print_success(stop.name + ": " + str(stop.matches))
            else:
                print_failure(stop.name + ":  0")
            stop.last_run = datetime.datetime.now().replace(microsecond=0)
            db.session.add(stop)
            counter += 1
            if counter % 20 == 0:
                db.session.commit()
Esempio n. 8
0
def get_stops():
    ''' The initial query to set up the stop db '''
    all_stops = Stop.query.all()
    all_ids = [stop.id for stop in all_stops]
    url = config.stops_txt_url
    req = requests.get(url)
    req.encoding = 'utf-8'
    text = req.text.split('\n')
    reader = csv.DictReader(text, delimiter=',', quotechar='"')
    counter = 0
    for line in reader:
        stop = Stop(line)
        if stop.isStation and stop.id not in all_ids:
            stop.matches = stop.is_in_osm()
            if stop.matches > 0:
                print_success(stop.name + ": " + str(stop.matches))
            else:
                print_failure(stop.name + ":  0")
            stop.last_run = datetime.datetime.now().replace(microsecond=0)
            db.session.add(stop)
            counter += 1
            if counter % 20 == 0:
                db.session.commit()