1- import os
2- import re
3- import glob
41import getpass
2+ import glob
53import hashlib
4+ import os
5+ import re
66from datetime import datetime
77
88import pygit2
99from github import Github
10- from github .Repository import Repository
1110from github .GithubException import BadCredentialsException , GithubException
12-
11+ from github . Repository import Repository
1312from textual .app import App , ComposeResult
13+ from textual .containers import Horizontal , Vertical
1414from textual .events import Event
15- from textual .containers import Vertical , Horizontal
16- from textual .widgets import (
17- Static ,
18- Button ,
19- Input ,
20- TextArea ,
21- Select ,
22- ListView ,
23- ListItem ,
24- )
15+ from textual .widgets import (Button , Input , ListItem , ListView , Select , Static ,
16+ TextArea )
2517
2618
2719class MemberApp (App ):
@@ -63,7 +55,9 @@ def on_mount(self) -> None:
6355 self .list_container .mount (self .list_view )
6456 self .list_container .mount (self .quit_list_button )
6557
66- md_files = glob .glob (os .path .join (self .REPO_PATH , "blog" , "members" , "*.md" ))
58+ md_files = glob .glob (
59+ os .path .join (self .REPO_PATH , "blog" , "members" , "*.md" )
60+ )
6761 for f in md_files :
6862 basename = os .path .basename (f )
6963 self .list_view .append (ListItem (Static (basename )))
@@ -99,7 +93,9 @@ def on_mount(self) -> None:
9993 self .form_container .mount (self .name_input )
10094 self .form_container .mount (self .email_input )
10195
102- self .form_container .mount (Static ("Redes Sociales" , classes = "subheader" ))
96+ self .form_container .mount (
97+ Static ("Redes Sociales" , classes = "subheader" )
98+ )
10399 self .form_container .mount (self .social_container )
104100 self .form_container .mount (self .add_social_button )
105101
@@ -182,9 +178,9 @@ def load_file_into_form(self, filename: str) -> None:
182178 with open (path_md , "r" , encoding = "utf-8" ) as fh :
183179 content = fh .read ()
184180 except Exception as e :
185- self .exit (f"Error loading file { filename } : { e } " )
186- return
187-
181+ self .exit (f"Error loading file { filename } : { e } " )
182+ return
183+
188184 self .clear_form ()
189185
190186 # Extract YAML frontmatter
@@ -193,6 +189,7 @@ def load_file_into_form(self, filename: str) -> None:
193189 if yaml_match :
194190 try :
195191 import yaml
192+
196193 yaml_data = yaml .safe_load (yaml_match .group (1 ))
197194 except Exception :
198195 yaml_data = {}
@@ -210,10 +207,15 @@ def load_file_into_form(self, filename: str) -> None:
210207 self .email_input .value = gravatar_match .group (1 ).strip ()
211208
212209 # Extract social links from raw HTML block
213- social_block = re .search (r"```\{raw\} html\n(.*?)```" , content , re .DOTALL )
210+ social_block = re .search (
211+ r"```\{raw\} html\n(.*?)```" , content , re .DOTALL
212+ )
214213 if social_block :
215214 social_html = social_block .group (1 )
216- social_link_pattern = re .compile (r'<a[^>]*href="([^"]+)"[^>]*>\s*<iconify-icon[^>]*icon="simple-icons:([^"]+)"' , re .DOTALL )
215+ social_link_pattern = re .compile (
216+ r'<a[^>]*href="([^"]+)"[^>]*>\s*<iconify-icon[^>]*icon="simple-icons:([^"]+)"' ,
217+ re .DOTALL ,
218+ )
217219 for match in social_link_pattern .finditer (social_html ):
218220 url = match .group (1 )
219221 platform = match .group (2 )
@@ -237,19 +239,39 @@ def load_file_into_form(self, filename: str) -> None:
237239 self .homepage_input .value = homepage_match .group (1 ).strip ()
238240
239241 # Extract markdown sections under headers
240- sobre_mi_match = re .search (r"## Sobre mí\n(.*?)(?=^### |\Z)" , content , re .DOTALL | re .MULTILINE )
242+ sobre_mi_match = re .search (
243+ r"## Sobre mí\n(.*?)(?=^### |\Z)" ,
244+ content ,
245+ re .DOTALL | re .MULTILINE ,
246+ )
241247 if sobre_mi_match :
242248 self .about_me_area .text = sobre_mi_match .group (1 ).strip ()
243- who_match = re .search (r"### ¿Quién eres y a qué te dedicas\?\n(.*?)(?=^### |\Z)" , content , re .DOTALL | re .MULTILINE )
249+ who_match = re .search (
250+ r"### ¿Quién eres y a qué te dedicas\?\n(.*?)(?=^### |\Z)" ,
251+ content ,
252+ re .DOTALL | re .MULTILINE ,
253+ )
244254 if who_match :
245255 self .who_area .text = who_match .group (1 ).strip ()
246- python_match = re .search (r"### ¿Cómo programas en Python\?\n(.*?)(?=^### |\Z)" , content , re .DOTALL | re .MULTILINE )
256+ python_match = re .search (
257+ r"### ¿Cómo programas en Python\?\n(.*?)(?=^### |\Z)" ,
258+ content ,
259+ re .DOTALL | re .MULTILINE ,
260+ )
247261 if python_match :
248262 self .python_area .text = python_match .group (1 ).strip ()
249- contrib_match = re .search (r"### ¿Tienes algún aporte a la comunidad de Python\?\n(.*?)(?=^### |\Z)" , content , re .DOTALL | re .MULTILINE )
263+ contrib_match = re .search (
264+ r"### ¿Tienes algún aporte a la comunidad de Python\?\n(.*?)(?=^### |\Z)" ,
265+ content ,
266+ re .DOTALL | re .MULTILINE ,
267+ )
250268 if contrib_match :
251269 self .contributions_area .text = contrib_match .group (1 ).strip ()
252- avail_match = re .search (r"### ¿Estás disponible para hacer mentoring, consultorías, charlas\?\n(.*?)(?=^### |\Z)" , content , re .DOTALL | re .MULTILINE )
270+ avail_match = re .search (
271+ r"### ¿Estás disponible para hacer mentoring, consultorías, charlas\?\n(.*?)(?=^### |\Z)" ,
272+ content ,
273+ re .DOTALL | re .MULTILINE ,
274+ )
253275 if avail_match :
254276 self .availability_area .text = avail_match .group (1 ).strip ()
255277
@@ -377,7 +399,9 @@ def save_member(self) -> None:
377399 alias_for_name = name .lower ().replace (" " , "_" )
378400
379401 sha_hash = hashlib .sha1 (
380- (alias_for_name + email + datetime .now ().isoformat ()).encode ("utf-8" )
402+ (alias_for_name + email + datetime .now ().isoformat ()).encode (
403+ "utf-8"
404+ )
381405 ).hexdigest ()[:8 ]
382406 name_file = f"{ alias_for_name } -{ sha_hash } "
383407
@@ -410,8 +434,12 @@ def save_member(self) -> None:
410434 md_lines .append ('<ul class="social-media profile">' )
411435 for plat , url in socials :
412436 md_lines .append (" <li>" )
413- md_lines .append (f' <a class="external reference" href="{ url } ">' )
414- md_lines .append (f' <iconify-icon icon="simple-icons:{ plat } " style="font-size:2em"></iconify-icon>' )
437+ md_lines .append (
438+ f' <a class="external reference" href="{ url } ">'
439+ )
440+ md_lines .append (
441+ f' <iconify-icon icon="simple-icons:{ plat } " style="font-size:2em"></iconify-icon>'
442+ )
415443 md_lines .append (" </a>" )
416444 md_lines .append (" </li>" )
417445 md_lines .append ("</ul>" )
@@ -449,21 +477,27 @@ def save_member(self) -> None:
449477 md_lines .append ("" )
450478
451479 if contributions :
452- md_lines .append ("### ¿Tienes algún aporte a la comunidad de Python?" )
480+ md_lines .append (
481+ "### ¿Tienes algún aporte a la comunidad de Python?"
482+ )
453483 md_lines .append ("" )
454484 md_lines .append (contributions )
455485 md_lines .append ("" )
456486
457487 if availability :
458- md_lines .append ("### ¿Estás disponible para hacer mentoring, consultorías, charlas?" )
488+ md_lines .append (
489+ "### ¿Estás disponible para hacer mentoring, consultorías, charlas?"
490+ )
459491 md_lines .append ("" )
460492 md_lines .append (availability )
461493 md_lines .append ("" )
462494
463495 md_content = "\n " .join (md_lines )
464496
465497 # Write file
466- file_path = os .path .join (self .REPO_PATH , "blog" , "members" , f"{ name_file } .md" )
498+ file_path = os .path .join (
499+ self .REPO_PATH , "blog" , "members" , f"{ name_file } .md"
500+ )
467501 os .makedirs (os .path .dirname (file_path ), exist_ok = True )
468502 with open (file_path , "w" , encoding = "utf-8" ) as f :
469503 f .write (md_content )
@@ -473,11 +507,15 @@ def save_member(self) -> None:
473507 rel_path = os .path .relpath (file_path , self .REPO_PATH )
474508 repo .index .add (rel_path )
475509 repo .index .write ()
476- author_sig = pygit2 .Signature (name or "Unknown" , email or "unknown@email" )
510+ author_sig = pygit2 .Signature (
511+ name or "Unknown" , email or "unknown@email"
512+ )
477513 tree_id = repo .index .write_tree ()
478514 parents = [] if repo .head_is_unborn else [repo .head .target ]
479515 commit_msg = f"Added { name_file } .md"
480- repo .create_commit ("HEAD" , author_sig , author_sig , commit_msg , tree_id , parents )
516+ repo .create_commit (
517+ "HEAD" , author_sig , author_sig , commit_msg , tree_id , parents
518+ )
481519
482520 callbacks = pygit2 .callbacks .RemoteCallbacks (
483521 credentials = pygit2 .UserPass (self .token , "x-oauth-basic" )
@@ -518,7 +556,9 @@ def get_repo() -> tuple[str, Repository]:
518556 print ("Acceso no autorizado. Por favor, verifique su token de acceso." )
519557 exit (1 )
520558 except GithubException :
521- print ("Repositorio no encontrado. Por favor, verifique su token de acceso." )
559+ print (
560+ "Repositorio no encontrado. Por favor, verifique su token de acceso."
561+ )
522562 exit (1 )
523563
524564
0 commit comments