-
Notifications
You must be signed in to change notification settings - Fork 4
Use main Mastodon account and fix workflow install #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
patrickZWY
wants to merge
14
commits into
master
Choose a base branch
from
mastodon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
eef8078
add optional comment for masto
patrickZWY d7b10d3
start mastodon
patrickZWY caa1ecf
second
patrickZWY fb831ed
first
patrickZWY 1244b8f
first
patrickZWY ec0e052
first
patrickZWY 1393c64
Add Mastodon posting workflow
prajwalbang 0028fa3
Improve Mastodon auth diagnostics
prajwalbang 171940e
Trim Mastodon post length
prajwalbang 7348d8c
Resolve merge conflict in requirements.txt
prajwalbang cb33029
debug and mastondon update
patrickZWY 14619d6
Merge branch 'mastodon' of github.com:codeforboston/CutePetsBoston in…
patrickZWY 7f69e11
Use main Mastodon token in workflow
prajwalbang 267769a
Limit Mastodon workflow dependencies
prajwalbang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Mastodon Post | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - mastodon | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| post-to-mastodon: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install --break-system-packages requests==2.32.5 Mastodon.py==2.1.4 | ||
|
|
||
| - name: Post to Mastodon | ||
| env: | ||
| CUTEPETSBOSTON_RESCUEGROUPS_API_KEY: ${{ secrets.CUTEPETSBOSTON_RESCUEGROUPS_API_KEY }} | ||
| MASTODON_TOKEN: ${{ secrets.MASTODON_TOKEN }} | ||
| POSTER_PLATFORMS: mastodon | ||
| run: python ./main.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #curl -X POST "https://mastodon.social/api/v1/statuses" \ | ||
| # -H "Authorization: Bearer h_o6jBz37M5322Mb8a1PYNTA9ALjfKL15_XMY2dYwAs" \ | ||
| # -H "Content-Type: application/json" \ | ||
| # -d '{"status": "Hello from my dev app! 🚀"}' | ||
|
|
||
| # RESET TOKEN LATER!!! | ||
|
|
||
| import sys | ||
| import os | ||
| import random | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) | ||
|
|
||
| from adoption_sources import SourceRescueGroups | ||
| from social_posters.mastodon import PosterMastodon | ||
|
|
||
| def main(): | ||
| poster = PosterMastodon() | ||
|
|
||
| if not poster.authenticate(): | ||
| print("Authentication failed!") | ||
| exit(1) | ||
|
|
||
| print("Authenticated to Mastodon!") | ||
|
|
||
| source = SourceRescueGroups() | ||
| pets = list(source.fetch_pets()) | ||
| print(f"Fetched {len(pets)} pets") | ||
|
|
||
| with_images = [p for p in pets if p.image_url] | ||
| if not with_images: | ||
| print("No pets with images found.") | ||
| exit(1) | ||
|
|
||
| pet = random.choice(with_images) | ||
| print(f"Selected: {pet.name}") | ||
|
|
||
| post = poster.format_post(pet) | ||
| print(f"\nPost preview:\n{post.text}") | ||
| print(f"\nTags: {post.tags}") | ||
|
|
||
| result = poster.publish(post) | ||
|
|
||
| if result.success: | ||
| print(f"\nPosted successfully! URL: {result.post_url}") | ||
| else: | ||
| print(f"\nPost failed: {result.error_message}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from mastodon import Mastodon | ||
| import os | ||
| from datetime import datetime | ||
|
|
||
| client = Mastodon( | ||
| access_token=os.environ.get("MASTODON_TOKEN") or os.environ["MASTODON_TEST_TOKEN"], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to |
||
| api_base_url=os.environ.get("MASTODON_API_BASE_URL", "https://mastodon.social"), | ||
| ) | ||
|
|
||
| client.account_verify_credentials() | ||
| client.status_post(f"Simple Test at {datetime.now()}") | ||
| print("Success") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,52 @@ | ||
| anyio==4.12.1 | ||
| api-display-purposes==0.0.3 | ||
| attrs==25.4.0 | ||
| beautifulsoup4==4.14.3 | ||
| blurhash==1.1.5 | ||
| certifi==2026.2.25 | ||
| chardet==3.0.4 | ||
| charset-normalizer==3.4.4 | ||
| instagrapi>=2.3.0 | ||
| clarifai==2.6.2 | ||
| configparser==3.8.1 | ||
| decorator==5.2.1 | ||
| EasyProcess==1.1 | ||
| emoji==1.7.0 | ||
| requests>=2.28.0 | ||
| setuptools>=70.0 | ||
| future==1.0.0 | ||
| googleapis-common-protos==1.72.0 | ||
| grpcio==1.78.0 | ||
| h11==0.16.0 | ||
| httpcore==1.0.9 | ||
| httpx==0.28.1 | ||
| idna==2.10 | ||
| instapy==0.6.16 | ||
| jsonschema==2.6.0 | ||
| Mastodon.py==2.1.4 | ||
| MeaningCloud-python==2.0.0 | ||
| outcome==1.3.0.post0 | ||
| plyer==2.1.0 | ||
| protobuf==3.20.3 | ||
| PySocks==1.7.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 | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,23 @@ | ||
| """Social media poster implementations implementing the SocialPoster interface.""" | ||
|
|
||
| from social_posters.debug import PosterDebug | ||
| __all__ = ["PosterBluesky", "PosterDebug", "PosterMastodon", "PosterInstagram"] | ||
|
|
||
| __all__ = ["PosterBluesky", "PosterDebug", "PosterInstagram"] | ||
|
|
||
| def __getattr__(name): | ||
| if name == "PosterBluesky": | ||
| from social_posters.bluesky import PosterBluesky | ||
|
|
||
| return PosterBluesky | ||
| if name == "PosterDebug": | ||
| from social_posters.debug import PosterDebug | ||
|
|
||
| return PosterDebug | ||
| if name == "PosterInstagram": | ||
| from social_posters.instagram import PosterInstagram | ||
|
|
||
| return PosterInstagram | ||
| if name == "PosterMastodon": | ||
| from social_posters.mastodon import PosterMastodon | ||
|
|
||
| return PosterMastodon | ||
| raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now with dedicated prod and dev workflows? do we want to allow these branch specific ones?