-
Notifications
You must be signed in to change notification settings - Fork 0
/
price.py
executable file
·52 lines (40 loc) · 2.02 KB
/
price.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import click
import mechanicalsoup
@click.command()
@click.option('--radius', '-r', default=5, help='Radius der Tankstellen')
@click.option('--city', '-c', required=True, help='Stadt')
@click.option('--type', '-t', required=True, help='Diesel, E10, E5, SuperPlus und die kleingeschriebenen Varianten')
def price(radius, city, type):
types = {
'diesel': 3,
'e10': 5,
'super': 6,
'e5': 7
}
typenumber = types.get(type)
city = city.replace(' ', '+')
url = f'https://www.clever-tanken.de/tankstelle_liste?lat=&lon=&ort={city}&spritsorte={typenumber}&r={radius}'
browser = mechanicalsoup.StatefulBrowser(
soup_config={'features': 'lxml'},
raise_on_404=True
)
browser.open(url)
page = browser.get_current_page()
result_table = page.find_all('div', class_='list-card-container d-flex background-white-gray')
click.secho(f'{"":-^95s}', fg='white', bold=True)
click.secho(f'{"Preis":<6} | {"Tankstelle":<16} | {"Stadt":<23} | {"Straße":<30} | {"Radius":<10}', fg='white', bold=True)
click.secho(f'{"":-^95s}', fg='white', bold=True)
for patrol in result_table:
price = patrol.find(class_='price-text price text-color-ct-blue')
if price == None:
return
price = price.get_text().strip()
patrol_name = patrol.find(class_='fuel-station-location-name').get_text().strip()
patrol_street = patrol.find(class_='fuel-station-location-street').get_text().strip()
patrol_city = patrol.find(class_='fuel-station-location-city').get_text().strip()
patrol_radius = patrol.find(class_='fuel-station-location-distance d-flex justify-content-end').get_text().strip()
maps_url = f'https://www.google.com/maps/place/{patrol_street}+{patrol_city}'
maps_link = f'\u001b]8;;{maps_url}\u001b\\{patrol_street:<30} \u001b]8;;\u001b\\'
click.secho(f'{price:<6} | {patrol_name[0:16]:<16} | {patrol_city:<23} | {maps_link} | {patrol_radius}', fg='white')
if __name__ == '__main__':
price()