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
This commit is contained in:
30
.gitea/workflows/quip.yaml
Normal file
30
.gitea/workflows/quip.yaml
Normal file
@ -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 }}
|
18
dog_facts.py
18
dog_facts.py
@ -5,16 +5,6 @@ from collections import namedtuple as nt
|
|||||||
from munch import DefaultMunch
|
from munch import DefaultMunch
|
||||||
from globals import *
|
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"
|
post_endpoint = f"{bots_endpoint}/api/v1/statuses"
|
||||||
api_url = 'https://dogapi.dog/api/v2/facts'
|
api_url = 'https://dogapi.dog/api/v2/facts'
|
||||||
headers = {
|
headers = {
|
||||||
@ -27,8 +17,10 @@ if response.reason == "OK":
|
|||||||
payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "unlisted"}
|
payload = {"status": f"didja know: \n {dog_fact.attributes.body}\n#RandomDogFacts", "visibility": "unlisted"}
|
||||||
response = post(post_endpoint, headers=headers, json=payload)
|
response = post(post_endpoint, headers=headers, json=payload)
|
||||||
if response.reason == "OK":
|
if response.reason == "OK":
|
||||||
notify(-1, loads(response.text)['uri'])
|
if po_user_token:
|
||||||
|
notify(-1, 'dog facts post url: ' + loads(response.text)['uri'])
|
||||||
else:
|
else:
|
||||||
notify(1, response.reason)
|
notify(1, 'dog facts post error: ' + response.reason)
|
||||||
else:
|
else:
|
||||||
notify(1, response.reason)
|
if po_user_token:
|
||||||
|
notify(1, 'dog facts api call failed: ' + response.reason)
|
||||||
|
12
globals.py
12
globals.py
@ -1,4 +1,13 @@
|
|||||||
from os import getenv
|
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 creds
|
||||||
unsplash_ep = "https://api.unsplash.com/photos/random?query=puppy"
|
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')
|
whitenonsense_token = getenv('WHITENONSENSE_TOKEN')
|
||||||
randomquotes_token = getenv('BOTS_QUOTESBOT_TOKEN')
|
randomquotes_token = getenv('BOTS_QUOTESBOT_TOKEN')
|
||||||
botsy_token = getenv('BOTS_BOTSY_TOKEN')
|
botsy_token = getenv('BOTS_BOTSY_TOKEN')
|
||||||
|
quip_file = getenv('QUIP_FILE')
|
||||||
|
quip_tags = getenv('QUIP_TAGS')
|
||||||
|
quip_token = getenv('QUIP_TOKEN')
|
||||||
|
|
||||||
# Pushover creds
|
# Pushover creds
|
||||||
po_endpoint = getenv('PUSHOVER_ENDPOINT')
|
po_endpoint = getenv('PUSHOVER_ENDPOINT')
|
||||||
|
25
quip.py
Normal file
25
quip.py
Normal file
@ -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)
|
Reference in New Issue
Block a user