Skip to content

Commit

Permalink
Merge pull request #79 from nclsbayona/master
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
nclsbayona authored Sep 15, 2023
2 parents 496b931 + d242c3f commit 5fa22a2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
## For this action you need to have as secrets in your repository

- WAKATIME_API_KEY : Your WakaTime API Key, so the request can be made to the API to get the desired data about your programming activity
- GH_TOKEN: A Github token with repo and user access to publish new readme
- GH_TOKEN: A GitHub token with repository and user access to publish new readme
- NASA_KEY: A NASA Apod API Key, so the request can be made to the API to get the desired data about a picture of the universe

Please use:
```yaml
env:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NASA_KEY: ${{ secrets.NASA_KEY }}
```
when calling the action.
Here, you can see an example of a workflow that uses this action
Expand All @@ -25,4 +27,5 @@ jobs:
env:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NASA_KEY: ${{ secrets.NASA_KEY }}
```
15 changes: 14 additions & 1 deletion directory_file
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,22 @@
</table>

----

</details>

<details>
<summary>Want to see something about our universe? 🔭</summary>

<br />
<h4 align="center">{{ universe_image_name }} - {{ universe_image_copyright }}</h4>
<p align="center">

<img src="{{ universe_image_url }}" alt="{{ universe_image_name }} image" />

</p>

<h5 align="center">{{ universe_image_description }}</h5>

----

<h3 align="center">Contact me! 📇</h3>

Expand Down
33 changes: 27 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from requests.models import Response

# nclsbayona


async def getDrink(format="string") -> Dict[str, str]:
"""Gets a random drink information from The Cocktail DB API"""
try:
Expand Down Expand Up @@ -234,18 +232,36 @@ 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
)
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_url"] = response["url"]
nasa["universe_image_description"] = response["explanation"]

return nasa

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,
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()
waka = await getWakaStats(waka_key=waka_time_api_key, format=format)
print(drink, affirmation, waka)
dictionary: Dict[str, str] = {**drink, **affirmation, **waka}
nasa = await getNasaImage(nasa_key=nasa_api_key)
dictionary: Dict[str, str] = {**drink, **affirmation, **waka, **nasa}
return dictionary
except Exception or KeyboardInterrupt:
return {"error_msj": "Error ocurred"}
Expand All @@ -270,12 +286,14 @@ def run_query(query):
async def updateFile(
path_to_template_file: str = "/directory_file",
waka_time_api_key: str = None,
nasa_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(
waka_time_api_key=waka_time_api_key,
nasa_api_key = nasa_api_key,
format=format,
)
print("The dictionary\n", dictionary)
Expand All @@ -297,19 +315,21 @@ async def updateFile(
committer=committer,
)

print("Readme updated", new_readme)
print("\n\nReadme updated\n", new_readme)
return True
except Exception or KeyboardInterrupt:
print_exc()
return False

async def main(waka_time_api_key, format):
async def main(waka_time_api_key, nasa_api_key, format):
await updateFile(
waka_time_api_key=waka_time_api_key,
nasa_api_key=nasa_api_key,
format=format,
)

waka_api_key = environ["WAKATIME_API_KEY"]
nasa_api_key = environ["NASA_KEY"]
ghtoken = environ["GH_TOKEN"]
format = "html"
if ghtoken is None:
Expand All @@ -334,6 +354,7 @@ async def main(waka_time_api_key, format):
loop.run_until_complete(
main(
waka_time_api_key=waka_api_key,
nasa_api_key=nasa_api_key,
format=format,
)
)
Expand Down

0 comments on commit 5fa22a2

Please sign in to comment.