Skip to content

Commit

Permalink
feat(new_releases): get releases from input date
Browse files Browse the repository at this point in the history
  • Loading branch information
pruizlezcano committed Aug 5, 2022
1 parent 55ff1c1 commit 9ddcee1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ sphinx:
# formats:
# - pdf

build:
os: ubuntu-22.04
tools:
python: "3.9"

python:
version: 3.9
install:
- requirements: docs/requirements.txt
- {path: ., method: pip}
28 changes: 17 additions & 11 deletions src/comicgeeks/Comic_Geeks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import requests
from bs4 import BeautifulSoup

Expand All @@ -19,7 +21,7 @@ class Comic_Geeks:
def __init__(self, ci_session: str = None) -> None:
self._ci_session: str = self._check_session(ci_session)

def _check_session(self, ci_session: str) -> bool:
def _check_session(self, ci_session: str = None) -> bool:
"""Check if session is valid.
Make a request to the main page and if is redirected to the dashboard, the session is valid.
"""
Expand Down Expand Up @@ -112,13 +114,20 @@ def search_character(self, query: str) -> list[Character]:
data.append(character)
return data

def new_releases(self) -> list[Issue]:
def new_releases(self, date: datetime = "now") -> list[Issue]:
"""Get this week new releases
Args:
date (datetime): Date to get new releases
Returns:
list (Issue): List of issues
"""
url = "https://leagueofcomicgeeks.com/comic/get_comics?list=releases&view=thumbs&format[]=1%2C6&date_type=week&date=now&order=pulls"
if date == "now":
date = datetime.now()
date = f"{date.month}/{date.day}/{date.year}"

url = f"https://leagueofcomicgeeks.com/comic/get_comics?list=releases&view=thumbs&format[]=1%2C6&date_type=week&date={date}&order=pulls"
r = requests.get(url, headers=_headers).json()
if r["count"] == 0:
return []
Expand All @@ -129,20 +138,17 @@ def new_releases(self) -> list[Issue]:
data = []
for comic in comics:
a = comic.find("a")
price = comic.find(class_="price")
if price is not None:
price = price.text.split("·")[1].strip()[1::]
if "£" in price:
price = price[1::]
else:
price = 0
price = (
float(comic.find(class_="price").text.split("·")[1].strip()[1::])
if comic.find(class_="price")
else "Unknown"
)
pulls = comic["data-pulls"]
rating = comic["data-community"]
name = comic.find(class_="title").text.strip()
issue_id = int(a["href"].split("/")[2])
url = a["href"]
store_date = comic.find(class_="date")["data-date"]
price = float(price)
publisher = comic.find(class_="publisher").text.strip()
cover = comic.find("img")["data-src"]
community = {"rating": rating, "pulls": pulls}
Expand Down
2 changes: 1 addition & 1 deletion src/comicgeeks/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def get_characters(content, Character, ci_session):
characters_credits = []
if content:
if content is not None:
characters = content.find_all(class_="row")[1].find_all(class_="row")
for character in characters:
url = character.find("a")["href"]
Expand Down

0 comments on commit 9ddcee1

Please sign in to comment.