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 15, 2023
1 parent c7a9224 commit 71a49f9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from requests import get, post
from requests.models import Response


# nclsbayona
async def getDrink(format="string") -> Dict[str, str]:
"""Gets a random drink information from The Cocktail DB API"""
Expand Down Expand Up @@ -58,6 +59,7 @@ async def getDrink(format="string") -> Dict[str, str]:
return {"error_msj": "An error ocurred please try again"}



async def getAffirmation() -> Dict[str, str]:
"""Gets a translated text from an quote to a random pop character language from funtranslations API"""
try:
Expand Down Expand Up @@ -184,6 +186,7 @@ async def getAffirmation() -> Dict[str, str]:
}



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 @@ -232,16 +235,20 @@ async def getWakaStats(waka_key: str = None, format: str = "string") -> Dict[str
except Exception or KeyboardInterrupt:
return {"error_msj": "An error ocurred please verify your inputs and try again"}



async def getNasaImage(nasa_api_key: str = None) -> Dict[str, str]:
"""Gets the image of the day from NASA Apod API"""
try:
the_response: Response = get(
"https://api.nasa.gov/planetary/apod?api_key="+nasa_api_key
"https://api.nasa.gov/planetary/apod?api_key=" + nasa_api_key
)
response: Dict[str, str] = the_response.json()
nasa: Dict[str, str] = dict()
nasa["universe_image_name"] = response["title"]
nasa["universe_image_copyright"] = f'©️ {response["copyright"]} @ {response["date"]}'.replace('\n','')
nasa[
"universe_image_copyright"
] = f'©️ {response["copyright"]} @ {response["date"]}'.replace('\n','')
nasa["universe_image_url"] = response["url"]
nasa["universe_image_description"] = response["explanation"]

Expand All @@ -250,6 +257,8 @@ async def getNasaImage(nasa_api_key: str = None) -> Dict[str, str]:
except Exception or KeyboardInterrupt:
return {"error_msj": "An error ocurred please try again"}



async def getAll(
waka_time_api_key: str = None,
nasa_api_key: str = None,
Expand All @@ -267,6 +276,7 @@ async def getAll(
return {"error_msj": "Error ocurred"}



if __name__ == "__main__":
try:

Expand All @@ -293,7 +303,7 @@ async def updateFile(
try:
dictionary = await getAll(
waka_time_api_key=waka_time_api_key,
nasa_api_key = nasa_api_key,
nasa_api_key=nasa_api_key,
format=format,
)
print("The dictionary\n", dictionary)
Expand Down

0 comments on commit 71a49f9

Please sign in to comment.