add comments to cfg generator, use enumerate instead of index pointers

This commit is contained in:
Christopher Teutsch 2019-05-22 10:24:37 +02:00
parent 081b23e702
commit 08a1b5cd96
Signed by: iwonder
GPG Key ID: 0EE33D788D50130D

View File

@ -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'