forked from Mirroring/github-release-notifier
Fix Pylint problems
This commit is contained in:
49
notifier.py
49
notifier.py
@@ -44,7 +44,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
last_config_tag = parser.get("release", project)
|
last_config_tag = parser.get("release", project)
|
||||||
if last_config_tag != last_release["release_tag"]:
|
if last_config_tag != last_release["release_tag"]:
|
||||||
last_release["preview_tag"] = last_config_tag
|
last_release["previous_tag"] = last_config_tag
|
||||||
new_releases.append(last_release)
|
new_releases.append(last_release)
|
||||||
parser.set("release", project, last_release["release_tag"])
|
parser.set("release", project, last_release["release_tag"])
|
||||||
|
|
||||||
@@ -55,42 +55,33 @@ def main():
|
|||||||
content = ""
|
content = ""
|
||||||
|
|
||||||
for new_r in new_releases:
|
for new_r in new_releases:
|
||||||
content += """
|
content += f"""
|
||||||
<li><a href="{}" target="_blank">{}</a>: new release <a href="{}" target="_blank">{}</a> available (old: {}).
|
<li><a href="{new_r["release_url"]}" target="_blank">{new_r["project_name"]}</a>
|
||||||
(published {})</li>
|
: new release
|
||||||
""".format(
|
<a href="{new_r["release_url"]}" target="_blank">{new_r["release_tag"]}</a>
|
||||||
new_r["release_url"],
|
available (old: {new_r["previous_tag"]}).
|
||||||
new_r["project_name"],
|
(published {convert_date(new_r["published_date"])})</li>"""
|
||||||
new_r["release_url"],
|
|
||||||
new_r["release_tag"],
|
|
||||||
new_r["preview_tag"],
|
|
||||||
convert_date(new_r["published_date"]),
|
|
||||||
)
|
|
||||||
for new_p in new_projects:
|
for new_p in new_projects:
|
||||||
content += """
|
content += f"""
|
||||||
<li><a href="{}" target="_blank">{}</a> was added to your configuration. Last release: <a href="{}" target="_blank">{}</a>
|
<li><a href="{new_p["release_url"]}" target="_blank">{new_p["project_name"]}</a>
|
||||||
(published {})</li>""".format(
|
was added to your configuration.
|
||||||
new_p["release_url"],
|
Last release:
|
||||||
new_p["project_name"],
|
<a href="{new_p["release_url"]}" target="_blank">{new_p["release_tag"]}</a>
|
||||||
new_p["release_url"],
|
(published {convert_date(new_p["published_date"])})</li>"""
|
||||||
new_p["release_tag"],
|
|
||||||
convert_date(new_p["published_date"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
# print(content)
|
with open(template_file, "r", encoding="utf-8") as f_template:
|
||||||
|
|
||||||
with open(template_file, "r") as f_template:
|
|
||||||
template = f_template.read()
|
template = f_template.read()
|
||||||
|
|
||||||
send_mail(template.replace("{{content}}", content))
|
send_mail(template.replace("{{content}}", content))
|
||||||
|
|
||||||
with open("conf.ini", "w") as configfile:
|
with open("conf.ini", "w", encoding="utf-8") as configfile:
|
||||||
parser.write(configfile)
|
parser.write(configfile)
|
||||||
|
|
||||||
|
|
||||||
def get_last_release(project):
|
def get_last_release(project):
|
||||||
url = "https://api.github.com/repos/{}/releases/latest".format(project)
|
url = f"https://api.github.com/repos/{project}/releases/latest"
|
||||||
result = requests.get(url)
|
result = requests.get(url, timeout=10)
|
||||||
|
|
||||||
print(project)
|
print(project)
|
||||||
print(url)
|
print(url)
|
||||||
@@ -125,8 +116,8 @@ def send_mail(content):
|
|||||||
server.sendmail(SENDER_EMAIL, RECEIVER_EMAIL, message.as_string())
|
server.sendmail(SENDER_EMAIL, RECEIVER_EMAIL, message.as_string())
|
||||||
|
|
||||||
|
|
||||||
def convert_date(date: str, format="%d %b %Y at %H:%M") -> str:
|
def convert_date(date: str, dest_format="%d %b %Y at %H:%M") -> str:
|
||||||
return datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ").strftime(format)
|
return datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ").strftime(dest_format)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user