~sircmpwn/core.sr.ht

core.sr.ht/srht-update-profiles -rwxr-xr-x 732 bytes
b695e020Drew DeVault Add "internal_anon" path for internal auth tokens 2 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import sys
import os
sys.path.append(os.getcwd())
site = sys.argv[1]
app = __import__(site.replace(".", "").replace("builds","build") + ".app").app.app # disgusting hack
from srht.config import cfg
from srht.database import db, DbSession
db = DbSession(cfg(site, "connection-string"))
db.init()

svc = app.oauth_service
users = svc.User.query.all()
for i, user in enumerate(users):
    print(f"Updating {user.username} ({i+1}/{len(users)})")
    try:
        with app.test_request_context():
            svc.lookup_via_oauth(user.oauth_token,
                    user.oauth_token_expires, user.oauth_token_scopes)
    except Exception as ex:
        print(f"Update failed: {str(ex)}")
    db.session.commit()