Skip to content

Instantly share code, notes, and snippets.

@frankenstein91
Last active February 11, 2021 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankenstein91/01f8f7db9291d6a7e7e1533047129930 to your computer and use it in GitHub Desktop.
Save frankenstein91/01f8f7db9291d6a7e7e1533047129930 to your computer and use it in GitHub Desktop.
mastodontech sppedtest bot
import multiprocessing
import atoot
import asyncio
import speedtest #speedtest-cli
async def mastodon_bot():
instance = ""
access_token = ""
client = await atoot.MastodonAPI.create(instance, access_token=access_token)
resp = await client.verify_account_credentials()
st = speedtest.Speedtest()
Download = st.download() / 1024.0 / 1024.0
Upload = st.upload() / 1024.0 / 1024.0
text = f"#MeinInternet ist heute {format(Download,'.3f')} MBit/s down und {format(Upload,'.3f')} MBit/s up."
await client.create_status(status=text)
await client.close()
if __name__ == '__main__':
multiprocessing.freeze_support()
asyncio.run(mastodon_bot())
@frankenstein91
Copy link
Author

you can install the needed libs with: pip install speedtest-cli atoot

and you can run it with systemd:

[Unit]
Description=This will post the internet speed to mastodon
After=network.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/home/meinUser/speedbot/botPython/bin/python /home/meinUser/speedbot/bot.py
WorkingDirectory=/home/meinUser/speedbot/

[Install]
WantedBy=multi-user.target
[Unit]
Description=Run the speedbot every day and on boot

[Timer]
OnCalendar=*-*-* 01:00:00
Persistent=true
Unit=speedbot.service

[Install]
WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment