fix updating user ratings from IMDb

We need to use the existing user from the DB to avoid overwriting the
user's secret or other details.
We also can't assert the user will stay the same, because at least
their name is allowed to change.
This commit is contained in:
ducklet 2021-08-06 12:56:01 +02:00
parent b8fab34418
commit b2caaa8bc3

View file

@ -45,7 +45,7 @@ async def refresh_user_ratings_from_imdb(stop_on_dupe=True):
log.info("⚡️ Loading data for %s ...", user.name)
async for rating, is_updated in load_ratings(user.imdb_id):
assert rating.user == user
assert rating.user.id == user.id
if stop_on_dupe and not is_updated:
break
@ -156,7 +156,10 @@ async def parse_page(url) -> Tuple[list[Rating], Optional[str]]:
meta = soup.find("meta", property="pageId")
headline = soup.h1
assert meta is not None and headline is not None
user = User(imdb_id=meta["content"], name="")
imdb_id = meta["content"]
user = await db.get(User, imdb_id=imdb_id) or User(
imdb_id=imdb_id, name="", secret=""
)
if match := find_name(headline.string):
user.name = match["name"]