Skip to content

Commit

Permalink
Improve HBR
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed Aug 17, 2022
1 parent 563c273 commit 2922f8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
target_ext=["epub"],
overwrite_cover=False,
category="magazines",
enable_on=onlyon_days(list(range(1, 1 + 7)) + list(range(32 - 7, 32)), -5),
enable_on=onlyon_days(list(range(1, 1 + 3)) + list(range(32 - 14, 32)), -5),
),
Recipe(
recipe="joongangdaily",
Expand Down
7 changes: 5 additions & 2 deletions recipes/hbr.recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ def preprocess_raw_html(self, raw_html, _):

# set article date
pub_datetime = soup.find("meta", attrs={"property": "article:published_time"})
mod_datetime = soup.find("meta", attrs={"property": "article:modified_time"})
# Example 2022-06-21T17:35:44Z
post_date = datetime.strptime(pub_datetime["content"], "%Y-%m-%dT%H:%M:%SZ")
mod_date = datetime.strptime(mod_datetime["content"], "%Y-%m-%dT%H:%M:%SZ")
pub_date_ele = soup.find("div", class_="pub-date")
pub_date_ele["data-pub-date"] = pub_datetime["content"]
pub_date_ele["data-mod-date"] = mod_datetime["content"]
post_date_ele = soup.new_tag("span")
post_date_ele["class"] = "article-pub-date"
post_date_ele.append(f"{post_date:%-d %B, %Y}")
Expand All @@ -110,9 +113,9 @@ def preprocess_raw_html(self, raw_html, _):
return str(soup)

def populate_article_metadata(self, article, soup, _):
pub_date_ele = soup.find(attrs={"data-pub-date": True})
mod_date_ele = soup.find(attrs={"data-mod-date": True})
post_date = datetime.strptime(
pub_date_ele["data-pub-date"], "%Y-%m-%dT%H:%M:%SZ"
mod_date_ele["data-mod-date"], "%Y-%m-%dT%H:%M:%SZ"
).replace(tzinfo=timezone.utc)
if (not self.pub_date) or post_date > self.pub_date:
self.pub_date = post_date
Expand Down

0 comments on commit 2922f8e

Please sign in to comment.