use munchify instead of Munch

This commit is contained in:
Camille Frantz 2025-10-27 08:29:49 -05:00
parent 2d23297cb5
commit c2ceed6a40
Signed by: fyrfli
SSH key fingerprint: SHA256:oxaZT6PRsoNy2x01TIrx3YE6H6p6gdmG2/Ir05d/bjc

View file

@ -5,7 +5,7 @@ import json
import requests import requests
import random import random
from os import getenv from os import getenv
from munch import DefaultMunch as dm, Munch from munch import munchify
from lxml import html from lxml import html
import pprint import pprint
import csv, io import csv, io
@ -25,7 +25,7 @@ headers = { "Content-Type" : "application/json",
"Authorization" : f"Bearer {api_token}", "Authorization" : f"Bearer {api_token}",
"User-Agent" : "fyrfliBOT" } "User-Agent" : "fyrfliBOT" }
status_dict = Munch({"status": "", status_dict = munchify({"status": "",
"in_reply_to_id": "", "in_reply_to_id": "",
"local_only": False, "local_only": False,
"visibility": "mutuals_only", "visibility": "mutuals_only",
@ -39,7 +39,8 @@ randomised_hellos = [
'well hello there', 'well hello there',
'mornin\' mornin\'', 'mornin\' mornin\'',
'g\'day mate', 'g\'day mate',
'allo' 'allo',
'\'sup'
] ]
def get_random_quote(): def get_random_quote():
@ -48,7 +49,7 @@ def get_random_quote():
def process_request(the_post): def process_request(the_post):
print('processing ', the_post.url) print('processing ', the_post.url)
pprint.pprint(json.dumps(the_post), compact=True, indent=2) # pprint.pprint(json.dumps(the_post), compact=True, indent=2)
hellos = ["hey" in the_post.content.lower(),"hey you" in the_post.content.lower(), "hi" in the_post.content.lower(), "hello" in the_post.content.lower()] hellos = ["hey" in the_post.content.lower(),"hey you" in the_post.content.lower(), "hi" in the_post.content.lower(), "hello" in the_post.content.lower()]
request_quote = ["random quote" in the_post.content.lower(), "quote please" in the_post.content.lower()] request_quote = ["random quote" in the_post.content.lower(), "quote please" in the_post.content.lower()]
if any(hellos): if any(hellos):
@ -72,10 +73,10 @@ async def hello(uri):
async for ws in websockets.connect(uri): async for ws in websockets.connect(uri):
try: try:
message = await ws.recv() message = await ws.recv()
decoded = dm.fromDict(json.loads(message)) decoded = munchify(json.loads(message))
print(decoded.event, decoded.payload[1:150]) print(decoded.event, decoded.payload[1:150])
if decoded.event != "delete": if decoded.event != "delete":
the_post = dm.fromDict(json.loads(decoded.payload)) the_post = munchify(json.loads(decoded.payload))
match decoded.event: match decoded.event:
case "delete": case "delete":
print("a delete event for id ", decoded.payload, "\n===>\n") print("a delete event for id ", decoded.payload, "\n===>\n")