Skip to content

Instantly share code, notes, and snippets.

@aallan
Created November 29, 2022 10:18
Show Gist options
  • Save aallan/87e574ff78f1b74547b153f1e6dab6a8 to your computer and use it in GitHub Desktop.
Save aallan/87e574ff78f1b74547b153f1e6dab6a8 to your computer and use it in GitHub Desktop.
import rp2
import time
import network
import urequests as requests
# Connect to wireless network
SSID = 'NETWORK NAME'
PASSWORD = 'NETWORK PASSWORD'
rp2.country('GB')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
wlan.config(pm = 0xa11140)
while not wlan.isconnected() and wlan.status() >= 0:
print("Waiting to connect")
time.sleep(1)
if(wlan.isconnected()):
network_config = wlan.ifconfig()
ip = network_config[0]
print("Connected: " + ip)
# Query Mastodon
TOKEN = "YOUR OAUTH TOKEN"
HEADERS = { 'Authorization': 'Bearer %s' % TOKEN }
# NOTE: Your account ID will be returned by the search, but depending on how many are returned
# it might not be in array index [1] so you might have to print it the returned JSON out here.
search = requests.get(url="https://mastodon.social/api/v2/search?q=YOUR_USERNAME", headers=HEADERS)
# print( search.json() )
account_id = search.json()['accounts'][1]['id']
while 1:
account = requests.get(url="https://mastodon.social/api/v1/accounts/%s" % account_id)
followers = account.json().get('followers_count')
print(followers)
time.sleep(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment