Skip to content
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

Wiki Addition - Post your daily charts to Mastodon #1159

Open
Chewie9999 opened this issue Mar 11, 2024 · 3 comments
Open

Wiki Addition - Post your daily charts to Mastodon #1159

Chewie9999 opened this issue Mar 11, 2024 · 3 comments

Comments

@Chewie9999
Copy link

Chewie9999 commented Mar 11, 2024

I have no idea if this is any use to anyone, but I made a quick script to upload the daily Top 10 chart to a bot on my Mastodon server:

  1. It's probably best to create a specific account and flag it as a bot on your mastodon server, so people can mute it specifically, rather than muting your normal account.
  2. Create an API key by going to Development -> New Application, and give it "write:media" and "write:statuses" permissions
  3. Save the "Your access token" string into a file on your Birdnet PI server (under '/home/birdnet/BirdNET-Pi/token.secret)
  4. Install the python Mastodon module: pip3 install Mastodon.py
  5. Save the below code into /home/birdnet/BirdNET-Pi/mastodonpost.py or similar
  6. Make the file executable using chmod +x /home/birdnet/BirdNET-Pi/mastodonpost.py
  7. Use crontab -e to edit the scheduler and run the command every day at 1minute past midnight:
1 0 * * * /home/birdnet/BirdNET-Pi/mastodonpost.py

Python Script mastodonpost.py

#!/bin/python
from mastodon import Mastodon
from datetime import date
from datetime import timedelta

#   Set up Mastodon
mastodon = Mastodon(
    access_token = '/home/birdnet/BirdNET-Pi/token.secret',
    api_base_url = 'https://MASTODONSERVER'
)

# Get current date
today=date.today()
yesterday = today - timedelta(days = 1)
yesterdaystr= yesterday.strftime('%Y-%m-%d')
chartfilename= "/home/birdnet/BirdSongs/Extracted/Charts/Combo-" + yesterdaystr + ".png"
print (yesterdaystr)
print (chartfilename)
# Post message
media = mastodon.media_post(chartfilename, description="Today's top 10 bird chart")
mastodon.status_post("#Birdnet #OtherHashTags",media_ids=media)

Edited: missed important step of installing python mastodon module

@rabede
Copy link

rabede commented Mar 20, 2024

Thank you! @BirdnetPi_Leverkusen@mastodon.social is using it now.

@magnetron01123
Copy link

Cool idea. But unfortunately it doesn't work for me. I have followed the instructions and adapted “api_base_url”.
I also had to adjust the paths slightly.
The error message is:

Traceback (most recent call last):
  File “/home/pi/BirdNET-Pi/mastodonpost.py”, line 2, in <module>
    from mastodon import Mastodon
ImportError: No module named mastodon

Does anyone know what I am doing wrong? Do I need to install another module?
Thank you!

@Chewie9999
Copy link
Author

Traceback (most recent call last):
File “/home/pi/BirdNET-Pi/mastodonpost.py”, line 2, in
from mastodon import Mastodon
ImportError: No module named mastodon


Does anyone know what I am doing wrong? Do I need to install another module? Thank you!

Oops, Sorry, i missed out an important first step:

pip3 install Mastodon.py

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants