Skip to content

Commit

Permalink
Fix jw parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
booxter committed Nov 22, 2024
1 parent 27c1394 commit d1f99f9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ run-all: run-update-directors run-update-films run-update-offers run-cleanup
run-db-upgrade:
pdm run alembic upgrade head

webapp:
webapp: install
pdm run webapp

email:
email: install
./scripts/email.sh --start-server

swagger:
Expand Down
1 change: 0 additions & 1 deletion src/letsrolld/cmd/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from letsrolld import http


_MAX_RATING = 5
_SEC_WAIT_ON_FAIL = 5
_LAST_CHECKED_FIELD = "last_checked"
_LAST_UPDATED_FIELD = "last_updated"
Expand Down
7 changes: 5 additions & 2 deletions src/letsrolld/film.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
KANOPY = "kanopy"
HOOPLA = "hoopla"
AMAZONPRIME = "amazonprime"
AMAZONPRIMEWITHADS = "amazonprimevideowithads"
AMAZON = "amazon"
YOUTUBE = "youtube"
CRITERION = "criterionchannel"

PHYSICAL = "physical"

# TODO: make these sets?
SERVICES = [
KANOPY,
HOOPLA,
AMAZONPRIME,
AMAZONPRIMEWITHADS,
AMAZON,
YOUTUBE,
CRITERION,
Expand All @@ -37,7 +40,7 @@
STREAM_ALIAS = "STREAM"
ANY_ALIAS = "ANY"

FREE_SERVICES = [KANOPY, HOOPLA, AMAZONPRIME]
FREE_SERVICES = [KANOPY, HOOPLA, AMAZONPRIME, AMAZONPRIMEWITHADS]
STREAM_SERVICES = FREE_SERVICES + [AMAZON, YOUTUBE, CRITERION]
ANY_SERVICES = STREAM_SERVICES + [PHYSICAL]

Expand Down Expand Up @@ -124,7 +127,7 @@ def available_physical(self):
@property
def available_services(self):
services = [
Offer(technical_name=offer.technical_name, url=offer.url)
Offer(technical_name=offer.package.technical_name, url=offer.url)
for offer in self.offers
]
if self.available_physical():
Expand Down
5 changes: 3 additions & 2 deletions src/letsrolld/http.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from http.client import HTTPConnection

Expand Down Expand Up @@ -29,5 +30,5 @@ def get_url(url):
return requests.get(url).text


def get_json(url, json):
return requests.post(url, headers=_HEADERS, json=json)
def get_json(url, data):
return json.loads(requests.post(url, headers=_HEADERS, json=data).text)
6 changes: 6 additions & 0 deletions src/letsrolld/justwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _parse_entry(json):
genres = [node.get("slug") for node in content.get("genres", []) if node]
external_ids = content.get("externalIds")
imdb_id = external_ids.get("imdbId") if external_ids else None
tmdb_id = external_ids.get("tmdbId") if external_ids else None
poster_url_field = content.get("posterUrl")
poster = jw_query._IMAGES_URL + poster_url_field if poster_url_field else None
backdrops = [
Expand All @@ -93,8 +94,13 @@ def _parse_entry(json):
short_description,
genres,
imdb_id,
tmdb_id,
poster,
backdrops,
None, # age_certification
None, # scoring - TODO: is it of interest?
None, # interactions
None, # streaming_charts
offers,
)

Expand Down
4 changes: 2 additions & 2 deletions src/letsrolld/webapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def _execute_section_plan(db, config, seen_films):
if config.max_year:
query = query.filter(models.Film.year <= config.max_year)

query = query.order_by(func.random()).limit(config.max_movies)
return [_get_film(db.session, f) for f in query]
query = query.order_by(func.random())
return [_get_film(db.session, f) for f in query.limit(config.max_movies)]


class ReportResource(Resource):
Expand Down
12 changes: 3 additions & 9 deletions src/letsrolld/webcli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import click
from jinja2 import Environment, PackageLoader

from letsrolld import film as lfilm

from letsrolld_api_client import Client
from letsrolld_api_client.api.default import get_directors

Expand All @@ -12,15 +14,7 @@
from letsrolld_api_client.api.default import get_reports_id


DEFAULT_OFFERS = {
# TODO: use constants for offer names
"criterionchannel",
"amazon",
"kanopy",
"hoopla",
"amazonprime",
"youtube",
}
DEFAULT_OFFERS = set(lfilm.STREAM_SERVICES)


# TODO: make the url configurable
Expand Down

0 comments on commit d1f99f9

Please sign in to comment.