Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #79

Merged
merged 6 commits into from
Sep 15, 2023
Merged

V2 #79

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading