From 08a1b5cd9693980c81e1510fa8c303fab73789ae Mon Sep 17 00:00:00 2001 From: Christopher Teutsch Date: Wed, 22 May 2019 10:24:37 +0200 Subject: [PATCH] add comments to cfg generator, use enumerate instead of index pointers --- setup.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index ff8bce6..56c8d79 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3.6 import requests import sys from typing import List @@ -30,8 +31,8 @@ def get_station() -> int: print("Getting suggestions...") results = search_station(search) if results: # empty lists and None are False - for ptr in range(len(results)): - print(str(ptr) + ". " + results[ptr]['value'] + "\t" + results[ptr]['data']) + for i, result in enumerate(results): + print(str(i) + ". " + result['value'] + "\t" + result['data']) choice_ptr = None if len(results) > 1: while choice_ptr is None: @@ -64,13 +65,13 @@ def get_lines(station_id: int) -> List[str]: page = False if page: print("Paging in batches of 20 results.") - for ptr in range(len(results)): - print(str(ptr) + ". " + results[ptr]['name']) - if (ptr % 20 == 0 or ptr == len(results) - 1) and ptr != 0: + for i, result in enumerate(results): + print(str(i) + ". " + result['name']) + if (i % 20 == 0 or i == len(results) - 1) and i != 0: choices += input("Please input your choices as a space-separated list (e.g. '0 2 7 15'):\n") + ' ' else: - for ptr in range(len(results)): - print(str(ptr) + ". " + results[ptr]['name']) + for i, result in enumerate(results): + print(str(i) + ". " + result['name']) choices += input("Please input your choices as a space-separated list (e.g. '0 2 7 15'):\n") + ' ' filt_arr = [] for ptr in choices.split(" "): @@ -93,9 +94,11 @@ def setup() -> None: lines = get_lines(station_id) else: lines = None - cfg = configparser.ConfigParser() + cfg = configparser.ConfigParser(allow_no_value=True) cfg.add_section('crawl') - cfg.add_section('db') + cfg['crawl']['; VRR_ACCOUNTABILITY CONFIGURATION FILE'] = None + cfg['crawl']['; ====================================='] = None + cfg['crawl']['; You may generate a configuration file using ./setup.py'] = None cfg['crawl']['station_id'] = str(station_id) cfg['crawl']['use_long_distance'] = 'yes' cfg['crawl']['use_regional_trains'] = 'yes' @@ -105,6 +108,7 @@ def setup() -> None: cfg['crawl']['use_buses'] = 'yes' cfg['crawl']['use_elevated_trains'] = 'yes' cfg['crawl']['use_lines'] = ",".join(lines) if lines is not None else "" + cfg.add_section('db') cfg['db']['user'] = 'vrr' cfg['db']['pass'] = 'vrr' cfg['db']['host'] = 'localhost'