Skip to content

Commit

Permalink
fix: update to get comics from 1st to last
Browse files Browse the repository at this point in the history
  • Loading branch information
Jh123x committed Mar 18, 2024
1 parent 57dbad3 commit 4a21e39
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
8 changes: 0 additions & 8 deletions docs/2024-03-16_Schwa.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/2024-03-17_Schwa.md

This file was deleted.

8 changes: 8 additions & 0 deletions docs/2024-03-18_Barrel - Part 1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# XKCD Comic for day 2024-03-18

## Barrel - Part 1

![Barrel - Part 1](https://imgs.xkcd.com/comics/barrel_cropped_(1).jpg "Don't we all.")

[Visit the original page](https://xkcd.com/1/)
8 changes: 0 additions & 8 deletions docs/2024-03-18_Schwa.md

This file was deleted.

4 changes: 1 addition & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ All images here belong to [xkcd.com](https://xkcd.com "xkcd.com")

| Date | Title | Link |
| ---- | ----- | ---- |
| 2024-03-16 | Schwa | [Link](./2024-03-16_Schwa "Schwa") |
| 2024-03-18 | Schwa | [Link](./2024-03-18_Schwa "Schwa") |
| 2024-03-17 | Schwa | [Link](./2024-03-17_Schwa "Schwa") |
| 2024-03-18 | Barrel - Part 1 | [Link](./2024-03-18_Barrel - Part 1 "Barrel - Part 1") |
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DATE_FORMAT = "%Y-%m-%d"
TITLE_FORMAT = "{date}_{title}.md"
DATA_URL = "https://xkcd.com/info.0.json"
DATA_URL = "https://xkcd.com/{page_no}/info.0.json"
MARKDOWN_FORMAT = """
# XKCD Comic for day {date}
Expand Down Expand Up @@ -58,7 +58,7 @@ def insert_to_content_page(title: str, date: str, file_name: str):
new_line = generate_content_line(title, date, file_name)
line_set.add(new_line)
lines = list(line_set)
lines.sort(key=lambda x: x.split("|")[0], reverse=True)
lines.sort(key=lambda x: x.split("|")[0])
result.extend(line_set)
with open(CONTENT_DIR, "w") as f:
f.write("\n".join(filter(lambda x: len(x.strip()) > 0, result)))
Expand All @@ -69,9 +69,13 @@ def insert_to_content_page(title: str, date: str, file_name: str):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

day_since_creation = datetime.datetime.now() - datetime.datetime(2024, 3, 17)

# Call the api
with requests.Session() as session:
response = session.get(DATA_URL)
response = session.get(
DATA_URL.format(page_no=day_since_creation.days),
)
if response.status_code >= 400:
logger.critical(
f"Failed to get the data from the API. Status code: {response.status_code}")
Expand Down

0 comments on commit 4a21e39

Please sign in to comment.