-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_readme.py
executable file
·63 lines (50 loc) · 1.89 KB
/
generate_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
from os import listdir
from os.path import isfile, join
import pytablewriter
from io import StringIO
from itertools import zip_longest
from math import ceil
import datetime
from logger import log
def format_paths(format, site):
mypath = f"./{site}/{format}/decks/"
onlyfiles = sorted(
[f"[{f[:-3].replace('_', ' ')}]({mypath}{f})" for f in listdir(mypath) if isfile(join(mypath, f))])
return onlyfiles
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
def generate_table(title, files):
res = StringIO()
writer = pytablewriter.MarkdownTableWriter()
writer.stream = res
writer.table_name = title
# writer.header_list = #list(link_dictionary.keys())
val = 1
while (ceil(len(files) / val) > 5):
val += 1
writer.value_matrix = list(zip_longest(*list(chunks(files, val))))
writer.write_table()
return res
def create(format, site):
files = format_paths(format, site)
q = generate_table(f"{format}\n", files)
return q.getvalue()
def output():
everything = "# Stock Decklists\n#### Based on mtggoldfish\n\n"
for format in ["Standard", "Historic", "Pioneer", "Modern", "Legacy"]:
everything += "\n" + create(format, 'mtggoldfish')
everything += f"\n\n#### Last Updated at {datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')}"
with open("README.md", "w") as fp:
fp.write(everything)
# everything = "# Stock Decklists\n#### Based on mtgtop8\n\n"
# for format in ["Standard", "Historic", "Pioneer", "Modern", "Legacy"]:
# everything += "\n" + create(format, 'mtgtop8')
#
# everything += f"\n\n#### Last Updated at {datetime.datetime.now().strftime('%I:%M%p on %B %d, %Y')}"
# with open("mtgtop8.md", "w") as fp:
# fp.write(everything)
if __name__ == "__main__":
log("Generating readme.")
output()