-
Notifications
You must be signed in to change notification settings - Fork 23
/
groups.py
33 lines (26 loc) · 828 Bytes
/
groups.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
import asyncio
import json
import os
from config import password, username
from spond import spond
if not os.path.exists("./exports"):
os.makedirs("./exports")
async def main():
s = spond.Spond(username=username, password=password)
groups = await s.get_groups()
for group in groups:
name = group["name"]
data = json.dumps(group, indent=4, sort_keys=True)
keepcharacters = (" ", ".", "_")
filename = os.path.join(
"./exports",
"".join(c for c in name if c.isalnum() or c in keepcharacters).rstrip()
+ ".json",
)
print(filename)
with open(filename, "w") as out_file:
out_file.write(data)
await s.clientsession.close()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.run(main())