Skip to content

Commit

Permalink
added some more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
DasMoorhuhn committed May 9, 2022
1 parent ff167d9 commit 3bd3560
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python Tankstellen Api Wrapper

Dies ist ein API Wrapper für Tankstellen in Deutschland. Als Quelle wird [TankerKönig](https://creativecommons.tankerkoenig.de/) verwendet.
Dies ist ein API Wrapper für Tankstellen in Deutschland. Als Quelle wird [TankerKönig](https://tankerkoenig.de/) verwendet.

## Getting started
1. API Key: </br>
Expand Down
38 changes: 24 additions & 14 deletions apiHandler.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
import pgeocode
import requests as _requests
from secretHandler import secret as _secret
import pgeocode
from classes import *

class city:
def __init__(self, lat, lng, name, postalCode, communityCode) -> None:
self.lat = lat
self.lng = lng
self.name = name
self.postalCode = postalCode
self.communityCode = communityCode

class api:
def __init__(self, postalCode:int, secret:_secret) -> None:
'''postalCode: Die Postleitzahl\nsecret: Das secret Objekt'''
__geo = pgeocode.Nominatim(country="de")
__geo = pgeocode.Nominatim(country="de") # Dies ist ein fester Wert, da die API nur für Deutschland funktioniert
location = __geo.query_postal_code(codes=postalCode)

self.__city = city(lat=location["latitude"], lng=location["longitude"], name=location["place_name"], postalCode=location["postal_code"], communityCode=location["community_code"])

self.__apiKey = secret.getApiKey()
self.__baseURL = "https://creativecommons.tankerkoenig.de/json"
self.__priceURL = f"{self.__baseURL}/prices.php" #Preisabfrage
self.__listURL = f"{self.__baseURL}/list.php" # Umkreissuche
self.__detailURL = f"{self.__baseURL}/detail.php" # Details zu einer bestimmten Tankstelle
self.__reportURL = f"{self.__baseURL}/complaint.php" # Zum Melden von falschen Angaben

self.__stations = []



def getGasStations(self, raduisInKM:float=10.0, spritType:str="all", onlyInThisPostCode:bool=False, sortedBy:str="postCode"):
'''Max Radius: 25KM\nSpritTypes: e5, e10, diesel, all\nOnlyInThisPostCode: Zeigt nur Tanketsllen mit der passenden Postleitzahl\nSortedBy: price, postCode, distanz'''
req = f"{self.__listURL}?lat={self.__city.lat}&lng={self.__city.lng}&rad={raduisInKM}&sort=dist&type={spritType}&apikey={self.__apiKey}"
response = _requests.api.get(req).json()
if response["ok"] and response["status"] == "ok":
for station in response["stations"]:
self.__stations.append(gasSation(value=station))
listForReturn = []
for station in self.__stations:
station:gasSation
if onlyInThisPostCode:
if station.postCode == self.__city.postalCode:
listForReturn.append(station)
else:
listForReturn.append(station)

def getLatAndLong(self):
print(self.__city.name)
return listForReturn

def getGasStations(self):
def getStaionDeteails(self):
pass
24 changes: 24 additions & 0 deletions classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class gasSation:
def __init__(self, value:dict) -> None:
self.id = value["id"]
self.name = value["name"]
self.brand = value["brand"]
self.street = value["street"]
self.houseNumber = value["houseNumber"]
self.postCode = value["postCode"]
self.place = value["place"]
self.lat = value["lat"]
self.lng = value["lng"]
self.dist = value["dist"]
self.diesel = value["diesel"]
self.e5 = value["e5"]
self.e10 = value["e10"]
self.isOpen = value["isOpen"]

class city:
def __init__(self, lat, lng, name, postalCode, communityCode) -> None:
self.lat = lat
self.lng = lng
self.name = name
self.postalCode = int(postalCode)
self.communityCode = communityCode
8 changes: 7 additions & 1 deletion tankApi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import apiHandler
import secretHandler as sh
from classes import *

secret = sh.secret()
value = secret.loadFromSecret()
if value == 0:
api = apiHandler.api(postalCode=26127, secret=secret)
api.getLatAndLong()
stations = api.getGasStations(onlyInThisPostCode=True, raduisInKM=5, spritType="all")
for station in stations:
station:gasSation
print(station.postCode)
print(station.brand)
print("")
else:
exit("Error reading secret")

0 comments on commit 3bd3560

Please sign in to comment.