-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff167d9
commit 3bd3560
Showing
4 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |