forked from AyudaEnPython/AyudaEnPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (57 loc) · 1.79 KB
/
main.py
File metadata and controls
79 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from dataclasses import dataclass
from datetime import date
from jinja2 import Template
from typing import List
LOGO = "_readme/logo.txt"
MENSAJE = "_readme/saludar.py"
DESCRIPCION = "_readme/descripcion.txt"
REPOS = "_readme/repos.csv"
REGLAS = "_readme/reglas.md"
readme = Template('''\

[](https://github.com/AyudaEnPython/AyudaEnPython/actions/workflows/main.yml)
{{logo}}
## Descripción
{{descripcion}}
```python
{{mensaje}}
```
---
## Nuestros Repositorios
{% for repo in repos %}
* [{{repo.name}}]({{repo.url}}):
{{repo.description}}
{% endfor %}
> _*NOTA*_: Conforme se vayan agregando más repositorios, esta lista se irá
> actualizando.
---
## Reglas de la Comunidad
{{reglas}}
'''
)
def read_file(filename: str) -> str:
with open(filename, "r", encoding="utf-8") as f:
return f.read()
def read_repo_data(filename: str, class_: object, sep: str = ";") -> List[str]:
with open(filename, "r") as f:
data = [line.split(sep) for line in f.read().splitlines()]
print(data)
return [class_(*line) for line in data[1:]]
@dataclass
class Repo:
name: str
description: str
def __post_init__(self) -> None:
self.url = "https://github.com/AyudaEnPython/{}".format(self.name)
def main():
with open("README.md", "w", encoding="utf-8") as f:
f.write(readme.render(
year=date.today().year,
logo=read_file(LOGO),
mensaje=read_file(MENSAJE),
descripcion=read_file(DESCRIPCION),
reglas=read_file(REGLAS),
repos=read_repo_data(REPOS, Repo),
))
if __name__ == "__main__":
main()