Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 98 additions & 12 deletions manual_testing/mastodon_manual_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,93 @@
import sys, os
import time
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from abstractions import Post
from abstractions import AdoptablePet
from social_posters.mastodon import PosterMastodon

def postExceed500CharsLimitWithAdoptionLink():
pet = AdoptablePet("Brian",
"Labrador Retriever",
"White Labrador",
"Quahog",
"I am a writer! Post exceeds limit with adoption link"*1000,
"http://www.davidgorman.com/4quartets/",
"https://static.wikia.nocookie.net/familyguy/images/c/c2/FamilyGuy_Single_BrianWriter_R7.jpg/revision/latest?cb=20230807152447",
11,
"Male",
None,
None
)
return pet

def postExceed500CharsLimitWithoutAdoptionLink():
pet = AdoptablePet("Vinny",
"Unknown",
"Unknown",
"Quahog",
"I am 1/16th cat! Post exceeds word limit without adoption link."*1000,
None,
"https://static.wikia.nocookie.net/familyguyfanon/images/e/ec/Vinny_Griffin.png/revision/latest?cb=20161129110103",
None,
"Male",
None,
None
)
return pet


def postWithin500CharsLimitWithAdoptionLink():
pet = AdoptablePet("Ernie",
"Chicken",
"Unknown",
"Quahog",
"cluck. Post within word limit with adoption link.",
"https://poets.org/poem/having-coke-you",
"https://static.wikia.nocookie.net/villains/images/2/2e/Giant_chicken_animation.png/revision/latest?cb=20220615120124",
None,
"Male",
None,
None
)
return pet

def postWithin500CharsLimitWithoutAdoptionLink():
pet = AdoptablePet("Pouncy",
"Cat",
"Unknown",
"Quahog",
"Meow. Post within 500 limit without adoption link",
None,
"https://static.wikia.nocookie.net/villains/images/7/76/Pouncey.webp/revision/latest?cb=20220403224856",
None,
"Male",
None,
None
)
return pet

def postUnicode():
pet = AdoptablePet("Vinny",
"Unknown",
"Unknown",
"Quahog",
"🐶❤️ 可爱的小狗 Friendly \"lap cat\" @ shelter #AdoptMe",
None,
"https://static.wikia.nocookie.net/familyguyfanon/images/e/ec/Vinny_Griffin.png/revision/latest?cb=20161129110103",
None,
"Male",
None,
None
)
return pet

testingCases = [
postExceed500CharsLimitWithAdoptionLink,
postExceed500CharsLimitWithoutAdoptionLink,
postWithin500CharsLimitWithAdoptionLink,
postWithin500CharsLimitWithoutAdoptionLink,
postUnicode
]

def main():
poster = PosterMastodon()
Expand All @@ -15,19 +98,22 @@ def main():

print("Authenticated to Mastodon!")

post = Post(
text="Test post",
image_url="https://static.wikia.nocookie.net/familyguy/images/c/c2/FamilyGuy_Single_BrianWriter_R7.jpg/revision/latest?cb=20230807152447",
alt_text="Cute animal",
tags=["Test", "Mastodon"],
)
for pet in testingCases:
pet_instance = pet()

post = poster.format_post(pet_instance)
target_url = pet_instance.adoption_url
if target_url and (target_url not in post.text):
print("Adoption link not posted!")

result = poster.publish(post)

result = poster.publish(post)
if result.success:
print(f"Posted successfully! URL: {result.post_url}")
else:
print(f"Post failed: {result.error_message}")
time.sleep(1)

if result.success:
print(f"Posted successfully! URL: {result.post_url}")
else:
print(f"Post failed: {result.error_message}")

if __name__ == "__main__":
main()
36 changes: 11 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ api-display-purposes==0.0.3
attrs==25.4.0
beautifulsoup4==4.14.3
blurhash==1.1.5
certifi==2026.2.25
certifi
chardet==3.0.4
charset-normalizer==3.4.4
charset-normalizer
clarifai==2.6.2
configparser==3.8.1
decorator==4.0.2
decorator
EasyProcess==1.1
emoji==1.7.0
future==1.0.0
Expand All @@ -20,33 +20,19 @@ httpx==0.28.1
idna==2.10
instapy==0.6.16
jsonschema==2.6.0
Mastodon.py==2.1.4
Mastodon.py
MeaningCloud-python==2.0.0
outcome==1.3.0.post0
plyer==2.1.0
protobuf==3.20.3
PySocks==1.7.1
pytest==9.0.3
certifi==2026.4.22
charset-normalizer==3.4.7
decorator==5.2.1
idna
Mastodon.py==2.2.1
python-dateutil==2.9.0.post0
python-magic==0.4.27
python-telegram-bot==22.6
PyVirtualDisplay==3.0
PyYAML==6.0.3
regex==2026.2.28
requests==2.32.5
selenium==4.41.0
semantic-version==2.10.0
setuptools==82.0.0
setuptools-rust==1.12.0
requests==2.33.1
six==1.17.0
sniffio==1.3.1
sortedcontainers==2.4.0
soupsieve==2.8.3
tqdm==4.67.3
trio==0.33.0
trio-websocket==0.12.2
typing_extensions==4.15.0
urllib3==2.6.3
webdriverdownloader==1.1.0.4
websocket-client==1.9.0
wsproto==1.3.2
pytest
37 changes: 36 additions & 1 deletion social_posters/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import requests
from mastodon import Mastodon

from abstractions import Post, PostResult, SocialPoster
from abstractions import Post, PostResult, SocialPoster, AdoptablePet
from abstractions import CITY_NAME, CITY_STATE

MASTODON_CHARACTER_LIMIT = 500
TRUNCATION_SUFFIX = "..."
Expand Down Expand Up @@ -109,3 +110,37 @@ def _download_image(self, image_url: str) -> str:
if chunk:
tmp.write(chunk)
return tmp.name

# rearrange so that link is at top
# need to test
def format_post(self, pet:AdoptablePet) -> Post:
"""
Create a Post from an AdoptablePet.

Override this method to customize post formatting for specific platforms.
"""
text = f"Meet {pet.name}! This adorable {pet.breed} {pet.species} is looking for a forever home in {pet.location}."

if pet.adoption_url:
text += f" Adopt {pet.name}: {pet.adoption_url}"

if pet.description:
text += f"\n\n{pet.description}"

city = ""
if pet.location != f"{CITY_NAME}, {CITY_STATE}":
city = pet.location.split(",")[0].capitalize()

return Post(
text=text,
image_url=pet.image_url,
link=pet.adoption_url,
alt_text=f"Photo of {pet.name}, a {pet.breed} {pet.species} available for adoption",
tags=[
"adoptdontshop",
"rescue",
city,
pet.species,
pet.breed.lower().replace(" ", ""),
],
)
Loading