Skip to content
This repository was archived by the owner on Oct 29, 2022. It is now read-only.

Commit 825e5e3

Browse files
committed
format with black and isort
1 parent 0cc8f69 commit 825e5e3

File tree

5 files changed

+40
-39
lines changed

5 files changed

+40
-39
lines changed

automation/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import automation.newsletter as newsletter
1+
import automation.engine as engine
22
import automation.issues as issues
3-
import automation.engine as engine
3+
import automation.newsletter as newsletter

automation/archive.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
import os
33
import pathlib
44
from datetime import datetime, timedelta
5-
from issues import get_issues_from_github
6-
from engine import engine
5+
76
from jinja2 import Environment, FileSystemLoader
87

8+
from engine import engine
9+
from issues import get_issues_from_github
10+
911
# Get the date of the next friday
1012

1113

12-
def create_post(*, filename: str | pathlib.Path, template:str, **metadata) -> int:
14+
def create_post(*, filename: str | pathlib.Path, template: str, **metadata) -> int:
1315
"""Creates a markdown document for this week for render_engine to process"""
1416
filename = pathlib.Path("app/content").joinpath(pathlib.Path(filename))
1517
template = engine.get_template(template)
1618
return filename.write_text(template.render(metadata))
1719

1820

19-
def get_show_file(
20-
directory: pathlib.Path,
21-
date:datetime.datetime
22-
) -> pathlib.Path:
21+
def get_show_file(directory: pathlib.Path, date: datetime.datetime) -> pathlib.Path:
2322
"""Get the file for a show on a given date"""
2423
show_date = date.strftime("%Y-%m-%d")
25-
show_file = pathlib.Path(directory).joinpath(show_date).with_suffix(".md")
24+
show_file = pathlib.Path(directory).joinpath(show_date).with_suffix(".md")
2625
return show_file
27-

automation/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from jinja2 import Environment, FileSystemLoader
22

3-
engine = Environment(loader=FileSystemLoader(['templates', 'automation/templates']))
3+
engine = Environment(loader=FileSystemLoader(["templates", "automation/templates"]))

automation/issues.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
from collections import defaultdict
2-
from markdown_it.tree import SyntaxTreeNode
3-
from markdown_it import MarkdownIt
41
import datetime
5-
import httpx
6-
from typing import Generator
72
import re
3+
from collections import defaultdict
4+
from typing import Generator
5+
6+
import httpx
7+
from markdown_it import MarkdownIt
8+
from markdown_it.tree import SyntaxTreeNode
89

910

1011
def get_issue(issue_id: str) -> dict[str, str]:
1112
"""Returns the issue with the given id"""
12-
url = f"https://api.github.com/repos/kjaymiller/Python-Community-News/issues/{issue_id}" # TODO: remove hardcoded issue url
13+
url = f"https://api.github.com/repos/kjaymiller/Python-Community-News/issues/{issue_id}" # TODO: remove hardcoded issue url
1314
request = httpx.get(url)
1415
return request.json()
1516

17+
1618
def get_issues(labels, since_date: datetime.datetime | None) -> list:
1719
"""Returns the issues filed in the last week"""
1820
url = "https://api.github.com/repos/kjaymiller/Python-Community-News/issues"
@@ -30,8 +32,8 @@ def parse_issue_markdown(text) -> dict:
3032
issue_object = defaultdict(list)
3133
for n in node.children:
3234
if n.type == "heading":
33-
issue_key = (n.children[0].content)
34-
elif content:= n.children[0].content == "_No response_":
35+
issue_key = n.children[0].content
36+
elif content := n.children[0].content == "_No response_":
3537
continue
3638
else:
3739
issue_object[issue_key].append(n.children[0].content)
@@ -47,5 +49,5 @@ def get_content_issues(body, issues_tag: str) -> Generator[dict[str, str], None,
4749
if issues_tag not in md:
4850
raise ValueError(f"{issues_tag} is required in the issue")
4951

50-
issues = re.findall(r'\d+', md[issues_tag][0])
51-
return issues
52+
issues = re.findall(r"\d+", md[issues_tag][0])
53+
return issues

automation/newsletter.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
from typing import Generator
2-
import httpx
3-
import os
41
import datetime
2+
import os
53
import pathlib
4+
from typing import Generator
5+
66
import frontmatter
7+
import httpx
78

89
hour = str
910
minute = str
10-
buttondown_api_key = os.getenv('BUTTONDOWN_API_KEY')
11-
header = {'Authorization': f'Token {buttondown_api_key}'}
11+
buttondown_api_key = os.getenv("BUTTONDOWN_API_KEY")
12+
header = {"Authorization": f"Token {buttondown_api_key}"}
1213

1314
schedule_email_url = "https://api.buttondown.email/v1/scheduled-emails"
1415

1516

16-
1717
def get_publish_time(
18-
date:datetime.datetime,
19-
time:datetime.time,
18+
date: datetime.datetime,
19+
time: datetime.time,
2020
) -> datetime.datetime:
2121
"""Helper for getting the date and time for when to schedule the email"""
2222
return datetime.datetime.combine(date, time)
@@ -29,27 +29,28 @@ def build_email_from_content(
2929
Uses frontmatter to get the subject and returns a partial of the body to be used to schedule the email.
3030
"""
3131
content = frontmatter.load(filepath)
32-
subject = content.metadata.get('subject')
33-
body={
32+
subject = content.metadata.get("subject")
33+
body = {
3434
"email_type": "public",
3535
"body": content.content,
3636
"subject": subject,
3737
}
3838
return body
3939

40+
4041
def schedule_email_from_post(
4142
body: dict[str, str],
4243
publish_date: datetime.datetime,
43-
) -> httpx.Response:
44+
) -> httpx.Response:
4445
"""
4546
Returns the status code of the request.
4647
The the `publish_date` time are required to schedule the email.
47-
"""
48-
48+
"""
49+
4950
body.update({"publish_date": publish_date.isoformat()})
5051
request = httpx.post(
51-
schedule_email_url,
52-
headers=header,
53-
json=body,
52+
schedule_email_url,
53+
headers=header,
54+
json=body,
5455
)
55-
return request
56+
return request

0 commit comments

Comments
 (0)