Import signatures with wrong format

This commit is contained in:
Ivanq 2021-04-02 16:20:56 +03:00
parent 799c3a7f52
commit cbe2dd8830
32 changed files with 121 additions and 46 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ _site
.jekyll-cache
.jekyll-metadata
vendor
__pycache__/

View File

@ -0,0 +1,2 @@
name: Rupert Falcon Kavanagh ( Claverhouse )
link: mailto:claverhouse@tutanota.de

2
_data/signed/Dench.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Denis Avksentev
link: https://dribbble.com/Dench

View File

@ -0,0 +1,2 @@
name: Echedey López Romero
link: https://git.disroot.org/ELR

View File

@ -0,0 +1,2 @@
name: Kaced Sofiane
link: mailto:kaced.sofiane@gmail.com

View File

@ -0,0 +1,2 @@
name: jagadees, india.
link: https://neritam.com

View File

@ -0,0 +1,2 @@
name: Joe Serpe
link: https://simplemachines.it

View File

@ -0,0 +1,2 @@
name: 郝歌
link: https://blog.hiddenharmonies.org/

View File

@ -0,0 +1,2 @@
name: Mike Safonov
link: https://github.com/MikeSafonov

2
_data/signed/MrClon.yaml Normal file
View File

@ -0,0 +1,2 @@
name: MrClon
link: https://lor.sh/@MrClon

2
_data/signed/PetrB.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Petr Beliaev
link: https://github.com/User330639

View File

@ -0,0 +1,2 @@
name: Dominic Westreicher
link: mailto:d.westreicher@gmail.com

View File

@ -0,0 +1,2 @@
name: Nei S.
link: https://nei.su

2
_data/signed/ewm.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Eryk Michalak (ewm)
link: https://ewm.codeberg.page/

2
_data/signed/hulten.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Marco van Hulten (FSF associate member)
link: http://marcovan.hulten.org/

View File

@ -0,0 +1,2 @@
name: if7
link: https://libreboot.org/

2
_data/signed/jakot.yaml Normal file
View File

@ -0,0 +1,2 @@
name: jakot
link: https://gitlab.com/jakot

2
_data/signed/jangid.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Pankaj Jangid (Emacs Developer)
link: https://codeisgreat.org/

2
_data/signed/jao.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Jose A Ortega Ruiz (FSF Associate Member, GNU MDK)
link: https://codeberg.org/jao

View File

@ -0,0 +1,2 @@
name: Martin Krischik
link: https://github.com/krischik

View File

@ -0,0 +1,2 @@
name: kriztolized
link: mailto:kriztolized@gmail.com

View File

@ -0,0 +1,2 @@
name: Leonardo Ascione
link: https://github.com/leonardfactory

View File

@ -0,0 +1,2 @@
name: Evgeniy B.
link: https://github.com/lospirit

2
_data/signed/manul.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Tinko Svrakov
link: mailto:manul91@abv.bg

2
_data/signed/mcash.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Matthew Cashman
link: mailto:cashman@mit.edu

View File

@ -0,0 +1,2 @@
name: Neil Haskins
link: https://neilhaskins.ca

2
_data/signed/nf.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Nathan Follens (GNOME Foundation member)
link: https://l10n.gnome.org/users/nathan/

2
_data/signed/shtrih.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Dmitry M
link: https://github.com/shtrih

2
_data/signed/sideus.yaml Normal file
View File

@ -0,0 +1,2 @@
name: Kyal Smith, South Africa
link: mailto:kyal.smith@gmail.com

60
_importer.py Normal file
View File

@ -0,0 +1,60 @@
import os
def save_signature(name, link, author):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write(f"name: {name.strip()}\nlink: {link.strip()}\n")
def parse_and_import_signature(content, author):
if os.path.isfile(f"_data/signed/{author}.yaml"):
return
content_lines = [line.strip() for line in content.replace("`", "").strip().split("\n") if line.strip()]
imported = False
for i in range(len(content_lines) - 1):
if content_lines[i].lower().startswith("name:") and content_lines[i + 1].lower().startswith("link:"):
save_signature(content_lines[i][5:], content_lines[i + 1][5:], author)
imported = True
# Apparently most people can't follow a two-line template, e.g. miss 'name:'
# or 'link:' or use 'site:' instead of 'link:' or use 'mailto:' instead of
# 'link: mailto:', etc., so we have to guess in what way their
# interpretation is wrong, and try to make the format at least somewhat
# correct.
if not imported and len(content_lines) == 2:
name, link = content_lines
if name.lower().startswith("name:"):
name = name[5:]
if link.lower().startswith("link:"):
link = link[5:]
elif link.lower().startswith("site:"):
link = link[5:]
elif link.lower().startswith("mail:"):
link = "mailto:" + link[5:].strip()
elif link.lower().startswith("email:"):
link = "mailto:" + link[6:].strip()
elif link.lower().startswith("mailto:"):
link = "mailto:" + link[7:].strip()
# Demangle email
if "@" in link or "(at)" in link or "[at]" in link:
link = link.replace("[at]", "@")
link = link.replace("(at)", "@")
link = link.replace(" at ", "@")
link = link.replace("[dot]", ".")
link = link.replace("(dot)", ".")
link = link.replace(" dot ", ".")
link = link.replace(" ", "")
# Add protocol to links without it
if "@" in link:
if not link.startswith("mailto:"):
link = f"mailto:{link}"
elif link.startswith("www.") or link.endswith(".com"):
link = f"https://{link}"
if "/" in link or "@" in link:
save_signature(name, link, author)

View File

@ -1,5 +1,5 @@
import subprocess
import os
from _importer import parse_and_import_signature
parts = subprocess.run(["gh", "issue", "view", "837", "-c"], capture_output=True).stdout.split(b"\n--\n")
@ -11,25 +11,4 @@ for info, content in zip(parts[::2], parts[1::2]):
info_dict[key] = value
author = info_dict["author"]
content_lines = [line.strip() for line in content.decode().replace("`", "").strip().split("\n") if line.strip()]
imported = False
for i in range(len(content_lines) - 1):
if content_lines[i].lower().startswith("name:") and content_lines[i + 1].lower().startswith("link:"):
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write("name:" + content_lines[i][5:] + "\nlink:" + content_lines[i + 1][5:] + "\n")
imported = True
if not imported and len(content_lines) == 2:
name, link = content_lines
if name.lower().startswith("name:"):
name = name[5:]
name = name.strip()
if link.lower().startswith("link:"):
link = link[5:]
link = link.strip()
if "/" in link or "@" in link:
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write(f"name: {name}\nlink: {link}\n")
parse_and_import_signature(content.decode(), author)

View File

@ -1,5 +1,5 @@
import requests
import os
from _importer import parse_and_import_signature
page = 1
@ -10,26 +10,5 @@ while True:
for comment in comments:
author = comment["user"]["login"]
content = comment["body"]
content_lines = [line.strip() for line in content.replace("`", "").strip().split("\n") if line.strip()]
imported = False
for i in range(len(content_lines) - 1):
if content_lines[i].lower().startswith("name:") and content_lines[i + 1].lower().startswith("link:"):
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write("name:" + content_lines[i][5:] + "\nlink:" + content_lines[i + 1][5:] + "\n")
imported = True
if not imported and len(content_lines) == 2:
name, link = content_lines
if name.lower().startswith("name:"):
name = name[5:]
name = name.strip()
if link.lower().startswith("link:"):
link = link[5:]
link = link.strip()
if "/" in link or "@" in link:
if not os.path.isfile(f"_data/signed/{author}.yaml"):
with open(f"_data/signed/{author}.yaml", "w") as f:
f.write(f"name: {name}\nlink: {link}\n")
parse_and_import_signature(content, author)
page += 1