This repository was archived by the owner on Mar 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_readme.py
105 lines (82 loc) · 3.07 KB
/
update_readme.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import requests
from random import choice
from urllib.parse import urlencode
from jinja2 import Environment, FileSystemLoader
# =====================================================================
EMOJIS_TIPO = {
'Música' : '🎵',
'Livro' : '📖',
'Versículo': '✝️',
}
# =====================================================================
def realizar_download_do_json():
FILE_ID = '13XoxjPstWGxQ-o-45E_zWESLdKk5iPk6'
FILE_URL = f'https://drive.google.com/uc?id={FILE_ID}'
response = requests.get(FILE_URL)
with open('./versos.json', 'wb') as versos_file:
versos_file.write( response.content )
def ler_versos_do_arquivo_json():
with open('./versos.json', 'r', encoding="utf-8") as versos_file:
versos = json.load(versos_file)
return versos
def ler_texto_atual():
with open('./README.md', 'r', encoding='utf-8') as readme_file:
texto_atual = readme_file.read()
return texto_atual
def escolher_verso_randomico(versos):
verso = choice(versos)
return verso
def montar_url_readmetypingsvg(verso):
SEPARATOR = ';'
BASE_URL = 'https://readme-typing-svg.demolab.com/'
args = {
"font" : "Fira Code",
"height" : (len(verso.get('linhas', 0)) + 1) * 30,
"width" : 500,
"size" : 20,
"pause" : 100,
"color" : "A9FEF7",
"center" : True,
"vCenter" : True,
"multiline": True,
"duration" : 1500,
"repeat" : True,
"lines" : [],
}
# Inserindo o texto:
for linha in verso.get("linhas"):
linha_limpa = linha.replace(SEPARATOR, '')
args['lines'].append( linha_limpa )
# Inserindo a referência no final:
tipo = verso.get('tipo')
ref = verso.get('referencia')
args['lines'].append(f'{EMOJIS_TIPO.get(tipo)} {ref} {EMOJIS_TIPO.get(tipo)}')
# Convertendo a lista para uma string:
args['lines'] = SEPARATOR.join(args['lines'])
# Gerando URL:
enconded_args = urlencode(args)
full_url = f'{BASE_URL}?separator={SEPARATOR}&{enconded_args}'
return full_url
def renderizar_template(url):
env = Environment(loader=FileSystemLoader("."))
template = env.get_template("template.md")
texto = template.render(url=url)
return texto
def escrever_readme(texto):
with open("./README.md", "w", encoding='utf8') as readme_file:
readme_file.write(texto)
def main():
realizar_download_do_json()
versos = ler_versos_do_arquivo_json()
texto_atual = ler_texto_atual()
for _ in range(5): # Evitando loop infinto e a mesma frase/texto do readme atual
verso = escolher_verso_randomico(versos)
url = montar_url_readmetypingsvg(verso)
texto = renderizar_template(url)
if texto != texto_atual:
break
escrever_readme(texto)
# =====================================================================
if __name__ == "__main__":
main()