Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nclsbayona authored Sep 13, 2023
1 parent fc9ae4f commit 5501f9b
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,6 @@ async def getAffirmation() -> Dict[str, str]:
return {"text_affirmation": "An error ocurred please try again later"}


async def getWeather(query: str = None, key: str = None) -> Dict[str, str]:
"""Gets the weather information from OPENWEATHER API using a query and a key specified by the user"""
try:
query = environ["THE_CITY"] if query is None else query
key = environ["OPEN_WEATHER_MAP_KEY"] if key is None else key
response = get(
f"https://api.openweathermap.org/data/2.5/weather?q={query}&appid={key}&units=metric"
)
the_response: Dict[str, str] = response.json()
dictionary: Dict[str, str] = dict()
dictionary["city_temperature"] = str(the_response["main"]["temp"])
dictionary["city_min_temperature"] = (
str(the_response["main"]["temp_min"]) + "°C"
)
dictionary["city_max_temperature"] = (
str(the_response["main"]["temp_max"]) + "°C"
)
dictionary["city_termic_sensation"] = (
str(the_response["main"]["feels_like"]) + "°C"
)
dictionary["city_pressure"] = str(the_response["main"]["pressure"]) + "Pa"
dictionary["city_weather"] = the_response["weather"][0]["description"]

return dictionary

except Exception or KeyboardInterrupt:
return {"error_msj": "An error ocurred please verify your inputs and try again"}


async def getWakaStats(waka_key: str = None, format: str = "string") -> Dict[str, str]:
"""Gets WAKATIME API data, and returns in a dictionary some of the information"""
try:
Expand Down Expand Up @@ -258,19 +229,16 @@ async def getWakaStats(waka_key: str = None, format: str = "string") -> Dict[str


async def getAll(
open_weather_query: str = None,
open_weather_key: str = None,
waka_time_api_key: str = None,
format: str = "string",
) -> Dict[str, str]:
"""Gets the information gathered using the rest of the functions"""
try:
drink = await getDrink(format=format)
affirmation = await getAffirmation()
weather = await getWeather(query=open_weather_query, key=open_weather_key)
waka = await getWakaStats(waka_key=waka_time_api_key, format=format)
print(drink, affirmation, weather, waka)
dictionary: Dict[str, str] = {**drink, **affirmation, **weather, **waka}
print(drink, affirmation, waka)
dictionary: Dict[str, str] = {**drink, **affirmation, **waka}
return dictionary
except Exception or KeyboardInterrupt:
return {"error_msj": "Error ocurred"}
Expand All @@ -294,16 +262,12 @@ def run_query(query):

async def updateFile(
path_to_template_file: str = "/directory_file",
open_weather_query: str = None,
open_weather_key: str = None,
waka_time_api_key: str = None,
format: str = "string",
) -> bool:
"""Updates a file with the information gathered using the rest of the functions"""
try:
dictionary = await getAll(
open_weather_query=open_weather_query,
open_weather_key=open_weather_key,
waka_time_api_key=waka_time_api_key,
format=format,
)
Expand Down Expand Up @@ -334,8 +298,6 @@ async def updateFile(

async def main(open_weather_query, open_weather_key, waka_time_api_key, format):
await updateFile(
open_weather_query=open_weather_query,
open_weather_key=open_weather_key,
waka_time_api_key=waka_time_api_key,
format=format,
)
Expand Down

0 comments on commit 5501f9b

Please sign in to comment.