add new admin routes to trigger database updates

The two routes offer reloading the whole movie database from IMDb, and
reloading all users' IMDb ratings.
These functions (or very similar) were already available using the CLI,
but now they can be triggered remotely by an admin.
This commit is contained in:
ducklet 2021-07-10 19:32:08 +02:00
parent 1805282d41
commit 294e311aff
5 changed files with 196 additions and 14 deletions

View file

@ -37,7 +37,7 @@ log = logging.getLogger(__name__)
async def refresh_user_ratings_from_imdb(stop_on_dupe=True):
with session() as s:
s.headers["Accept-Language"] = "en-GB, en;q=0.5"
s.headers["Accept-Language"] = "en-US, en;q=0.5"
for user in await db.get_all(User):
@ -192,6 +192,7 @@ async def load_ratings(user_id):
ratings, next_url = await parse_page(next_url)
for i, rating in enumerate(ratings):
assert rating.user and rating.movie
if i == 0:
# All rating objects share the same user.