mirror of
https://github.com/rottenwheel/revuo-weekly.git
synced 2024-11-22 02:53:33 +01:00
refactor: improve code readability and formatting
Unified string quotes and used consistent indentation to enhance the readability of the script. Refactored the creation of issue cover image for better clarity and maintainability. These changes optimize future code reviews and reduce the potential for errors.
This commit is contained in:
parent
f3207b7a7d
commit
e231c4d8c5
73
new_issue.py
73
new_issue.py
@ -7,46 +7,59 @@ import datetime
|
||||
import tempfile
|
||||
import tomllib
|
||||
|
||||
|
||||
def create_issue(issue_number):
|
||||
subprocess.run(['hugo', 'new', f'weekly/issue-{issue_number}/_index.md'])
|
||||
subprocess.run(["hugo", "new", f"weekly/issue-{issue_number}/_index.md"])
|
||||
|
||||
|
||||
def create_issue_image(site_title, issue_number, period_start, period_end):
|
||||
with open('assets/img/cover-template.svg') as f:
|
||||
cover_template = f.read()
|
||||
with open("assets/img/cover-template.svg") as f:
|
||||
cover_template = f.read()
|
||||
|
||||
cover_template = cover_template.replace('__SITE__', site_title)
|
||||
cover_template = cover_template.replace('__ISSUE__', issue_number)
|
||||
cover_template = cover_template.replace('__DATE__', f'{period_start} - {period_end}')
|
||||
cover_template = cover_template.replace("__SITE__", site_title)
|
||||
cover_template = cover_template.replace("__ISSUE__", issue_number)
|
||||
cover_template = cover_template.replace(
|
||||
"__DATE__", f"{period_start} - {period_end}"
|
||||
)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
cover_path = pathlib.Path(tempdir) / 'cover.svg'
|
||||
with open(cover_path, 'w') as f:
|
||||
f.write(cover_template)
|
||||
with tempfile.TemporaryDirectory() as tempdir:
|
||||
cover_path = pathlib.Path(tempdir) / "cover.svg"
|
||||
with open(cover_path, "w") as f:
|
||||
f.write(cover_template)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"inkscape",
|
||||
str(cover_path),
|
||||
"-e",
|
||||
f"content/weekly/issue-{issue_number}/cover.png",
|
||||
]
|
||||
)
|
||||
|
||||
subprocess.run(['inkscape', str(cover_path), '-e', f'content/weekly/issue-{issue_number}/cover.png'])
|
||||
|
||||
|
||||
def get_latest_issue():
|
||||
issues = list(pathlib.Path('content/weekly').iterdir())
|
||||
latest_issue = max(issues, key=lambda x: int(x.name.split('-')[1]))
|
||||
return latest_issue.name.split('-')[1]
|
||||
issues = list(pathlib.Path("content/weekly").iterdir())
|
||||
latest_issue = max(issues, key=lambda x: int(x.name.split("-")[1]))
|
||||
return latest_issue.name.split("-")[1]
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('hugo.toml', "rb") as f:
|
||||
hugo_config = tomllib.load(f)
|
||||
|
||||
parser = argparse.ArgumentParser(description='Create a new issue')
|
||||
parser.add_argument('--issue', type=int, help='Issue number')
|
||||
args = parser.parse_args()
|
||||
if __name__ == "__main__":
|
||||
with open("hugo.toml", "rb") as f:
|
||||
hugo_config = tomllib.load(f)
|
||||
|
||||
if args.issue:
|
||||
new_issue = args.issue
|
||||
else:
|
||||
latest_issue = get_latest_issue()
|
||||
new_issue = int(latest_issue) + 1
|
||||
parser = argparse.ArgumentParser(description="Create a new issue")
|
||||
parser.add_argument("--issue", type=int, help="Issue number")
|
||||
args = parser.parse_args()
|
||||
|
||||
period_start = datetime.datetime.now().strftime('%Y-%m-%d')
|
||||
period_end = (datetime.datetime.now() + datetime.timedelta(days=7)).strftime('%Y-%m-%d')
|
||||
if args.issue:
|
||||
new_issue = args.issue
|
||||
else:
|
||||
latest_issue = get_latest_issue()
|
||||
new_issue = int(latest_issue) + 1
|
||||
|
||||
create_issue(new_issue)
|
||||
|
||||
period_start = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
period_end = (datetime.datetime.now() + datetime.timedelta(days=7)).strftime(
|
||||
"%Y-%m-%d"
|
||||
)
|
||||
|
||||
create_issue(new_issue)
|
||||
|
Loading…
Reference in New Issue
Block a user