Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mBaratta96 committed Aug 6, 2023
1 parent 52ea247 commit 0e4d3d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions letterboxd_stats/web_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,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 0e4d3d3

Please sign in to comment.