core.sr.ht/srht-update-profiles

23 lines
732 B
Python
Executable File

#!/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()