Commit 62877658 authored by Jakob Lerch's avatar Jakob Lerch
Browse files

style: apply black

parent b99d15e3
Pipeline #419 passed with stage
in 12 seconds
......@@ -9,19 +9,9 @@ setuptools.setup(
description="Themen des Techniktreffen-Protokolls zwischen Gitlab-Issues und Protokoll übersetzen sowie und Ankündiguns- bzw. Zusammenfassungs-Mail schreiben",
long_description=long_description,
long_description_content_type="text/markdown",
project_urls={
},
classifiers=[
"Programming Language :: Python :: 3",
"Typing :: Typed"
],
project_urls={},
classifiers=["Programming Language :: Python :: 3", "Typing :: Typed"],
python_requires=">=3.9",
install_requires=[
'deepl',
'python-gitlab',
'requests',
'rich',
'typer'
],
packages=setuptools.find_packages()
install_requires=["deepl", "python-gitlab", "requests", "rich", "typer"],
packages=setuptools.find_packages(),
)
......@@ -9,10 +9,12 @@ def init():
json_path = Path(__file__).parent / "config.json"
config = json.loads(json_path.read_text())
glp = GitlabProject(url=config['gitlab']['url'],
token=config['gitlab']['token'],
project_id=int(config['gitlab']['project_id']),
translator_key=config['deepl']['token'])
glp = GitlabProject(
url=config["gitlab"]["url"],
token=config["gitlab"]["token"],
project_id=int(config["gitlab"]["project_id"]),
translator_key=config["deepl"]["token"],
)
return glp
......
......@@ -11,10 +11,12 @@ def init():
config_path = Path(__file__).parent / "config.json"
config = json.loads(config_path.read_text())
glp = GitlabProject(url=config['gitlab']['url'],
token=config['gitlab']['token'],
project_id=config['gitlab']['project_id'],
translator_key=config['deepl']['token'])
glp = GitlabProject(
url=config["gitlab"]["url"],
token=config["gitlab"]["token"],
project_id=config["gitlab"]["project_id"],
translator_key=config["deepl"]["token"],
)
return glp
......
......@@ -13,7 +13,7 @@ def init():
config_path = Path(__file__).parent / "config.json"
config = json.loads(config_path.read_text())
m = mail.Mail(**config['mail'])
m = mail.Mail(**config["mail"])
return m
......
......@@ -5,8 +5,7 @@ from pathlib import Path
from string import Template
import topicmanager.mail as mail
from topicmanager.utils import (get_gitlab_project, issues_to_links,
issues_to_topics)
from topicmanager.utils import get_gitlab_project, issues_to_links, issues_to_topics
from typer import Option, echo, run
......@@ -17,8 +16,7 @@ def main(
mail_sender_address: str = Option(..., envvar="MAIL_SENDER_ADDRESS"),
mail_recipient_address: str = Option(..., envvar="MAIL_RECIPIENT_ADDRESS"),
mail_subject: str = Option(
"Invitation Tech Meeting " + date.today().isoformat(),
envvar="MAIL_SUBJECT"
"Invitation Tech Meeting " + date.today().isoformat(), envvar="MAIL_SUBJECT"
),
mail_template_path: Path = Option(..., envvar="MAIL_TEMPLATE_PATH"),
smtp_server: str = Option(..., envvar="SMTP_SERVER"),
......@@ -26,7 +24,7 @@ def main(
smtp_username: str = Option(..., envvar="SMTP_USERNAME"),
smtp_password: str = Option(..., envvar="SMTP_PASSWORD"),
meeting_time: str = Option(..., envvar="MEETING_TIME"),
meeting_date: str = Option(..., envvar="MEETING_DATE")
meeting_date: str = Option(..., envvar="MEETING_DATE"),
):
if not mail_template_path.is_file():
echo(f"Mail template file {mail_template_path} not found")
......@@ -42,10 +40,7 @@ def main(
template = Template(mail_template_path.read_text())
body = template.substitute(
topics=topics,
links=links,
date=meeting_date,
time=meeting_time
topics=topics, links=links, date=meeting_date, time=meeting_time
)
m = mail.Mail(
......@@ -54,7 +49,7 @@ def main(
smtp_server,
smtp_port,
smtp_username,
smtp_password
smtp_password,
)
m.send_mail(body, mail_subject)
......
from topicmanager import gitlab_project
glp = gitlab_project.GitlabProject(url="",
token="",
project_id=0,
translator_key="")
glp = gitlab_project.GitlabProject(url="", token="", project_id=0, translator_key="")
topics_string = glp.get_issue_titles()
......
......@@ -4,7 +4,7 @@ import deepl
from pathlib import Path
from string import Template
from topicmanager.utils import (get_gitlab_project, apply_proto_mail_template)
from topicmanager.utils import get_gitlab_project, apply_proto_mail_template
import topicmanager.mail as mail
import topicmanager.hedgedoc as hedgedoc
from typer import Option, echo, run
......@@ -25,7 +25,7 @@ def main(
meeting_time: str = Option(..., envvar="MEETING_TIME"),
meeting_date: str = Option(..., envvar="MEETING_DATE"),
hedgedoc_url: str = Option(..., envvar="HEDGEDOC_URL"),
translator_key: str = Option(..., envvar="TRANSLATOR_KEY")
translator_key: str = Option(..., envvar="TRANSLATOR_KEY"),
):
if not mail_template_path.is_file():
echo(f"Mail template file {mail_template_path} not found")
......@@ -42,13 +42,12 @@ def main(
tl = deepl.Translator(translator_key)
protocol_german = hd.read_note()
protocol_english = tl.translate_text(protocol_german,
source_lang="DE",
target_lang="EN")
protocol_english = tl.translate_text(
protocol_german, source_lang="DE", target_lang="EN"
)
body = template.substitute(
protocol_german=protocol_german,
protocol_english=protocol_english
protocol_german=protocol_german, protocol_english=protocol_english
)
m = mail.Mail(
......@@ -57,7 +56,7 @@ def main(
smtp_server,
smtp_port,
smtp_username,
smtp_password
smtp_password,
)
m.send_mail(body, mail_subject)
......
......@@ -2,8 +2,7 @@ import requests
class HedgedocNote:
"""Manages one HedgeDoc note. Is a wrapper for the HTTP-API of HegdeDoc
"""
"""Manages one HedgeDoc note. Is a wrapper for the HTTP-API of HegdeDoc"""
def __init__(self, note_url: str):
"""init
......@@ -19,7 +18,7 @@ class HedgedocNote:
Returns:
string: raw markdown text of the read HedgeDoc note
"""
r = requests.get(self.note_url + '/download')
r = requests.get(self.note_url + "/download")
return r.text
def overwrite_note(self, new_note_content: str):
......
......@@ -13,13 +13,13 @@ def _generate_message_id():
class Mail:
def __init__(
self,
sender_address: str,
recipient_address: str,
smtp_server: str,
smtp_port: int,
smtp_username: str,
smtp_password: str
self,
sender_address: str,
recipient_address: str,
smtp_server: str,
smtp_port: int,
smtp_username: str,
smtp_password: str,
):
self.sender_address = sender_address
self.recipient_address = recipient_address
......@@ -47,23 +47,22 @@ class Mail:
content: str,
subject: str,
recipient_address: Union[str, list[str], None] = None,
reply_to: Optional[str] = None
reply_to: Optional[str] = None,
):
if recipient_address is None:
recipient_address = self.recipient_address
# Create a text/plain message
msg = EmailMessage()
msg.set_content(unicodedata.normalize(
'NFKC', content), cte="quoted-printable")
msg.set_content(unicodedata.normalize("NFKC", content), cte="quoted-printable")
msg['Subject'] = subject
msg['From'] = self.sender_address
msg['To'] = recipient_address
msg['Date'] = email.utils.formatdate(localtime=True)
msg['Message-ID'] = f"<{_generate_message_id()}>"
msg["Subject"] = subject
msg["From"] = self.sender_address
msg["To"] = recipient_address
msg["Date"] = email.utils.formatdate(localtime=True)
msg["Message-ID"] = f"<{_generate_message_id()}>"
if reply_to is not None:
msg['In-Reply-To'] = reply_to
msg["In-Reply-To"] = reply_to
return msg
......
......@@ -41,14 +41,14 @@ def get_gitlab_project(url: str, private_token: str, project_id: int) -> "Projec
return gl.projects.get(project_id)
def issues_to_topics(issues: Iterable['Issue'], heading_level: int = 3) -> str:
def issues_to_topics(issues: Iterable["Issue"], heading_level: int = 3) -> str:
"""
format issues to headings
"""
return "\n".join(f"{'#'*heading_level} [{issue.title}]" for issue in issues)
def issues_to_links(issues: Iterable['Issue']) -> str:
def issues_to_links(issues: Iterable["Issue"]) -> str:
"""
format issues to links
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment