mcguirepr89 / BirdNET-Pi

A realtime acoustic bird classification system for the Raspberry Pi 4B, 3B+, and 0W2 built on the TFLite version of BirdNET.
Other
1.23k stars 136 forks source link

Wiki Addition - Post your daily charts to Mastodon #1159

Open Chewie9999 opened 3 months ago

Chewie9999 commented 3 months ago

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 commented 3 months ago

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

magnetron01123 commented 2 months ago

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 commented 2 months ago

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

:(