From 990c918c7ae3a0d5c8cb9618b6ef878de3d57434 Mon Sep 17 00:00:00 2001 From: Camille Frantz Date: Mon, 9 Jun 2025 14:41:59 -0500 Subject: [PATCH] modified white nonsense bot code to be used with any text file with a list of sayings; added notify function to globals and made pushover optional --- .gitea/workflows/quip.yaml | 30 ++++++++++++++++++++++++++++++ dog_facts.py | 20 ++++++-------------- globals.py | 12 ++++++++++++ quip.py | 25 +++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 .gitea/workflows/quip.yaml create mode 100644 quip.py diff --git a/.gitea/workflows/quip.yaml b/.gitea/workflows/quip.yaml new file mode 100644 index 0000000..f01514f --- /dev/null +++ b/.gitea/workflows/quip.yaml @@ -0,0 +1,30 @@ +name: QuipBot +on: + # push + # workflow_dispatch: + schedule: + - cron: '18 */8 * * *' +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 + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run quip.py + run: + python quip.py + env: + BOTS_ENDPOINT: ${{ secrets.BOTS_ENDPOINT }} + PUSHOVER_ENDPOINT: ${{ secrets.PUSHOVER_ENDPOINT }} + PUSHOVER_USER_TOKEN: ${{ secrets.PUSHOVER_USER_TOKEN }} + PUSHOVER_BOTS_TOKEN: ${{ secrets.PUSHOVER_BOTS_TOKEN }} + QUIP_FILE: ${{ secrets.QUIP_FILE }} + QUIP_TOKEN: ${{ secrets.QUIP_TOKEN }} + QUIP_TAGS: ${{ secrets.QUIP_TAGS }} diff --git a/dog_facts.py b/dog_facts.py index aca0528..395a58b 100644 --- a/dog_facts.py +++ b/dog_facts.py @@ -5,16 +5,6 @@ from collections import namedtuple as nt from munch import DefaultMunch 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 = { @@ -27,8 +17,10 @@ if response.reason == "OK": payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "unlisted"} response = post(post_endpoint, headers=headers, json=payload) if response.reason == "OK": - notify(-1, loads(response.text)['uri']) - else: - notify(1, response.reason) + if po_user_token: + notify(-1, 'dog facts post url: ' + loads(response.text)['uri']) + else: + notify(1, 'dog facts post error: ' + response.reason) else: - notify(1, response.reason) + if po_user_token: + notify(1, 'dog facts api call failed: ' + response.reason) diff --git a/globals.py b/globals.py index 66dc3c9..ea2264a 100644 --- a/globals.py +++ b/globals.py @@ -1,4 +1,13 @@ from os import getenv +from requests import post + +def notify(priority, message): + r = post("https://api.pushover.net/1/messages.json", data = { + "token": po_bots_token, + "user": po_user_token, + "message": message, + "priority": priority + }) # Unsplash creds unsplash_ep = "https://api.unsplash.com/photos/random?query=puppy" @@ -15,6 +24,9 @@ newsfeed_token = getenv('BOTS_NEWSFEED_TOKEN') whitenonsense_token = getenv('WHITENONSENSE_TOKEN') randomquotes_token = getenv('BOTS_QUOTESBOT_TOKEN') botsy_token = getenv('BOTS_BOTSY_TOKEN') +quip_file = getenv('QUIP_FILE') +quip_tags = getenv('QUIP_TAGS') +quip_token = getenv('QUIP_TOKEN') # Pushover creds po_endpoint = getenv('PUSHOVER_ENDPOINT') diff --git a/quip.py b/quip.py new file mode 100644 index 0000000..3df0f91 --- /dev/null +++ b/quip.py @@ -0,0 +1,25 @@ +from requests import get, post +from os import getenv +from random import randint +import csv,io +from json import loads +from globals import * + +post_endpoint = bots_endpoint + '/api/v1/statuses' + +response = get(quip_file) +if response.reason == "OK": + choices = response.text.split('\n') + choice = choices[randint(0, len(choices) - 1)] + headers = {"Authorization": "Bearer " + quip_token} + payload = {"status": f"{choice} \n\n {quip_tags} #Bot", + "visibility": "public"} + result = post(post_endpoint, headers=headers, data=payload) + if result.reason == "OK": + if po_user_token: + notify(-1, 'quip bot post url: ' + loads(result.text)['url']) + else: + notify(0, 'quip bot post failed: ' + result.status_code + ' - ' + result.reason) +else: + if po_user_token: + notify(1, 'quip file read failed: ' + response.status_code + ' - ' + response.reason)