Skip to content

Instantly share code, notes, and snippets.

@technillogue
Created March 3, 2022 08:08
Show Gist options
  • Save technillogue/bda678d904369051feb4132557864ab0 to your computer and use it in GitHub Desktop.
Save technillogue/bda678d904369051feb4132557864ab0 to your computer and use it in GitHub Desktop.
import asyncio
import re
import json
import os
import subprocess
from collections import defaultdict
import requests
import asyncpg
async def get_spenders() -> list[asyncpg.Record]:
return await (
await asyncpg.connect(os.getenv("DATABASE_URL") or os.getenv("dev_db"))
).fetch(
"select account, round(sum(amount_pmob/1e12), 4) from imogen_ledger "
"where amount_pmob is not null group by account order by sum(amount_pmob) desc;"
)
fmt = lambda r: "{round} {givenName} {familyName} {aboutEmoji} {about}".format(
**defaultdict(str, r)
)
profiles = {
r["number"]: r["profile"]
for r in json.loads(requests.get("https://imogen.fly.dev/recipients").text)[
"recipients"
]
}
subprocess.run(
"fish -c post",
shell=True,
input="\n".join(
fmt(profile | dict(rec))
for rec in asyncio.run(get_spenders())
if (profile := profiles.get(rec.get("account")))
).encode(),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment