initial commit

This commit is contained in:
Mark Eaton
2025-11-15 22:52:33 -05:00
commit 1fee0bd971
4 changed files with 313 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
import httpx
import os
import random
from datetime import datetime, timedelta
from dotenv import load_dotenv
from pprint import pprint
load_dotenv()
def auth():
data = {
"client_id": os.environ["CLIENT_ID"],
"client_secret": os.environ["CLIENT_SECRET"],
"grant_type": "client_credentials",
}
resp = httpx.post("https://lgapi-us.libapps.com/1.2/oauth/token", data=data)
token = resp.json()["access_token"]
return token
def main(token):
params = {"access_token": token, "status": 1}
resp = httpx.get("https://lgapi-us.libapps.com/1.2/guides", params=params)
data = resp.json()
now = datetime.now()
output = []
for item in data:
item["dt"] = datetime.strptime(item["updated"], "%Y-%m-%d %H:%M:%S")
if now - item["dt"] > timedelta(days=365):
output.append(item)
if len(output) < 1:
print("No outdated guides found!")
return None
ri = random.randint(0, len(output) - 1)
card = {
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text1": f"Is this your LibGuide? [{output[ri]['name']}]({output[ri]['url']})",
},
{
"type": "TextBlock",
"text2": "It is a published guide, and it has been more than 1 year since it was last updated!",
},
],
}
pprint(card)
return card
def send(card):
resp = httpx.post(os.environ["TEAMS_URL"], json=card)
resp.raise_for_status()
if __name__ == "__main__":
token = auth()
card = main(token)
if card:
send(card)