-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.py
executable file
·46 lines (41 loc) · 1.53 KB
/
scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python3
import serial
import requests
def main():
print("Present an NFC tag to query for fediverse association")
try:
ser = serial.Serial("/dev/ttyACM0")
ser.write(4) # send EOT to make sure card application is running, doesn't work find out why
while True:
line = ser.readline().decode()
print(line)
id = line.partition(":")[2].strip().replace(":","")
if id:
print(id)
accts = getAccount(id)
print(accts)
if len(accts):
for account in accts:
print("Found account: {} identifying itself on the fediverse as BornHack badge 2023 id {}".format(account, id))
getLastPost(accts[0])
else:
print("No accounts identifies as BornHack badge 2023 id: {} on the fediverse".format(id))
except IOError:
print("serial error")
def getAccount(id):
servers = [
"fosstodon.org"
, "mastodon.social"
]
accounts = []
for server in servers:
# https://docs.joinmastodon.org/methods/search/
search_res = requests.get("https://{}/api/v2/search?q={}&type=accounts".format(server, id)).json()
#print(search_res)
for account in search_res["accounts"]:
accounts.append("@{} ({})".format(account["acct"], account["display_name"]))
return accounts
def getLastPost(account):
pass
if __name__ == "__main__":
main()