Skip to content

Commit

Permalink
Merge pull request #53 from mBaratta96/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mBaratta96 authored Aug 6, 2023
2 parents e5893d6 + c038e3a commit 9913e7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions letterboxd_stats/web_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def _get_tmdb_id_from_web(link: str, is_diary: bool):

def get_tmdb_id(link: str, is_diary=False):
tmdb_id_cache = shelve.open(cache_path, writeback=False, protocol=5)
if link in tmdb_id_cache:
id = tmdb_id_cache[link]
key = link.split("/")[-1]
if key in tmdb_id_cache:
id = tmdb_id_cache[key]
else:
try:
id = _get_tmdb_id_from_web(link, is_diary)
tmdb_id_cache[link] = id
tmdb_id_cache[key] = id
except ValueError as e:
print(e)
id = None
Expand All @@ -140,15 +141,14 @@ def search_film(title: str, allow_selection=False):
movie_list = search_page.xpath("//div[@class='film-detail-content']")
if len(movie_list) == 0:
raise ValueError(f"No film found with search query {title}")
titles = [movie.xpath("./h2/span/a")[0].text.rstrip() for movie in movie_list]
years = [
f"({year[0].text}) " if len(year := movie.xpath("./h2/span//small/a")) > 0 else "" for movie in movie_list
]
directors = [director[0].text if len(director := movie.xpath("./p/a")) > 0 else "" for movie in movie_list]
links = [movie.xpath("./h2/span/a")[0].get("href") for movie in movie_list]
title_years_directors_links = {
f"{title} {year}- {director}": link for title, year, director, link in zip(titles, years, directors, links)
}
title_years_directors_links = {}
for movie in movie_list:
title = movie.xpath("./h2/span/a")[0].text.rstrip()
director = director[0].text if len(director := movie.xpath("./p/a")) > 0 else ""
year = f"({year[0].text}) " if len(year := movie.xpath("./h2/span//small/a")) > 0 else ""
link = movie.xpath("./h2/span/a")[0].get("href")
title_years_directors_links[f"{title} {year}- {director}"] = link

selected_film = cli.select_value(list(title_years_directors_links.keys()), "Select your film")
title_url = title_years_directors_links[selected_film].split("/")[-2]
else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "letterboxd_stats"
version = "0.2.6"
version = "0.2.7"
authors = [{ name = "mBaratta96" }]
description = "Get information about your Letterboxd activity."
readme = "README.md"
Expand Down

0 comments on commit 9913e7c

Please sign in to comment.