dogfacts and workflow
This commit is contained in:
24
.gitea/workflows/dog_facts.yaml
Normal file
24
.gitea/workflows/dog_facts.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
name: DogFacts
|
||||||
|
# on:
|
||||||
|
# schedule:
|
||||||
|
# - cron: '35 */4 * * *'
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v3
|
||||||
|
with:
|
||||||
|
python-version: "3.13"
|
||||||
|
- name: Install dependencies
|
||||||
|
working-directory: ./quotes
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
|
- name: Run dog_facts.py
|
||||||
|
run:
|
||||||
|
python dog_facts.py
|
||||||
|
env:
|
||||||
|
BOTS_DOGFACTS_TOKEN: ${{ secrets.BOTS_BOTSY_TOKEN }}
|
||||||
|
BOTS_ENDPOINT: ${{ secrets.BOTS_ENDPOINT }}
|
31
dog_facts.py
Normal file
31
dog_facts.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from requests import get, post
|
||||||
|
from json import loads
|
||||||
|
from os import getenv
|
||||||
|
from collections import namedtuple as nt
|
||||||
|
from globals import *
|
||||||
|
|
||||||
|
|
||||||
|
def notify(priority, message):
|
||||||
|
r = post("https://api.pushover.net/1/messages.json", data = {
|
||||||
|
"token": po_bots_token,
|
||||||
|
"user": po_user_token,
|
||||||
|
"message": "dog facts: " + message,
|
||||||
|
"priority": priority
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
post_endpoint = f"{bots_endpoint}/api/v1/statuses"
|
||||||
|
api_url = 'https://dogapi.dog/api/v2/facts'
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {dogfacts_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = get(api_url)
|
||||||
|
if response.reason == "OK":
|
||||||
|
dog_fact = loads(response.text, object_hook=lambda d: nt('DogFact', d.keys())(*d.values()))
|
||||||
|
payload = {"status": f"didja know: \n {dog_fact.data[0].attributes.body}\n#RandomDogFacts", "visibility": "public"}
|
||||||
|
response = post(post_endpoint, headers=headers, json=payload)
|
||||||
|
if response.reason == "OK":
|
||||||
|
notify(-1, loads(response.text)['uri'])
|
||||||
|
else:
|
||||||
|
notify(1, response.reason)
|
Reference in New Issue
Block a user