-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
180 lines (161 loc) · 6.84 KB
/
main.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import importlib
import os
import shlex
import shutil
import subprocess
from pathlib import Path
import httpx
import pdoc
import yaml
from bs4 import BeautifulSoup
from mako.lookup import TemplateLookup
from selenium_driver_updater import DriverUpdater
from yarl import URL
import markdown_vars
from src import terminal
from src.settings import stg
FOLDER = stg("folder")
def main():
# DriverUpdater.install(
# path = "./src",
# driver_name = DriverUpdater.chromedriver,
# upgrade = True,
# check_driver_is_up_to_date = True,
# )
# terminal.update()
importlib.reload(markdown_vars)
Vars = markdown_vars.Vars
yml = stg(None, "rejected.yaml")
flag = yml["flag"]
sites = yml["sites"]
mdb = """<h1 align="center" style="font-weight: bold">
LIST OF REJECTED SITES
</h1>
A site will not be accepted if it:
- does not have a list of all comics
- has duplicate links
- has external links redirecting to other sites
- has no search capability
- is geo-blocked
- is protected by an anti-DDoS mechanism except for DDoS Guard
- is torrent and/or download only; and
- serves paid content
| Site | Reason/s |
|:---:|:---:|"""
op = []
for k, v in sites.items():
j = []
for i in v:
j.append(flag[i])
op.append([f'<a target="_blank" href="{k}">{URL(k).host}</a>', ", ".join(j)])
with open("docs/_rejected.md", "w") as f:
md = []
for i in op:
md.append(f'| {" | ".join(i)} |')
f.write("{}\n{}".format(mdb, '\n'.join(md)))
with open("license.yaml", "r") as f:
license = yaml.load(f.read(), yaml.FullLoader)
if (copyright := []) == []:
c = license["cholder"]
for u, (r, y) in ((*u.keys(), *r.items()) for u in c for s in u.values() for r in s):
copyright.append(
f"by [Github Account [{u}](https://github.com/{u}) Owner, {y}] as part of project [{r}](https://github.com/{u}/{r})"
)
if len(copyright) > 1:
copyright[-2] += f", and {copyright[-1]}"
del copyright[-1]
cholder = f"""Copyright for portions of project [{Vars.project_name}](https://github.com/{Vars.organization}/{Vars.project_name}) are held {', '.join(copyright)}.\n
All other copyright for project [{Vars.project_name}](https://github.com/{Vars.organization}/{Vars.project_name}) are held by [Github Account [{Vars.user}](https://github.com/{Vars.user}) Owner, 2021]."""
else:
cholder = f"Copyright (c) 2021 Github Account [{Vars.project_name}](https://github.com/{Vars.user}) Owner"
Vars.conditions = ("" if license["conditions"][0] is None else "\n" + "\n\n".join(license["conditions"]) + "\n")
Vars.cholder = cholder
pdoc.tpl_lookup = TemplateLookup(
cache_args=dict(cached=True, cache_type='memory'),
input_encoding='utf-8',
directories=["./template/"],
)
os.mkdir(FOLDER)
_html = pdoc.Module(FOLDER, context=pdoc.Context()).html()
os.rmdir(FOLDER)
for tpl in list(Path(".").rglob("_*.md")):
spl = str(tpl).split("/")
file = os.path.join(*spl[:-1], spl[-1][1:].split(".")[0])
RM = spl[-1][1:].split(".")[0] == "README"
with open(tpl, "r") as fin, open(f'../{FOLDER}/{file}.md', "w") as fout, open(os.path.join(*spl[:-1], 'index.html') if RM else f'{file}.html', "w") as hout:
tpl_str = fin.read()
for var in tuple(i for i in dir(Vars) if not i.startswith("__")):
tpl_str = tpl_str.replace(f"${{{var}}}", str(getattr(Vars, var)))
fout.write(tpl_str)
soup = BeautifulSoup(_html, "html.parser")
headers = {"accept": "application/vnd.github.v3+json"}
data = {
"text": tpl_str
}
# print(tpl_str)
md = str(
httpx.post("https://api.github.com/markdown", headers=headers, json=data).content,
encoding="utf-8"
)
md_repl = [
[
'[ ]',
'<input type="checkbox" disabled="">'
],
[
'[x]',
'<input type="checkbox" disabled="" checked="">'
],
[
'<link href="/github-markdown-css/github-css.css" rel="stylesheet"/>',
''
],
[
".md",
".html"
]
]
for o, n in md_repl:
md = md.replace(o, n)
repl = [
[
"const url = '../doc-search.html#' + encodeURIComponent(query);",
"const url = 'doc-search.html#' + encodeURIComponent(query);"
],
[
str(soup.select_one('article#content')),
f'<article id="content">{md}</article>'
],
[
"user-content-",
""
]
]
html = _html
for o, n in repl:
html = html.replace(o, n)
soup = BeautifulSoup(html, "html.parser")
toc = soup.select_one("h2 a#table-of-contents")
logo = soup.select_one("img#logo")
if logo:
logo["style"] = "display: block; margin: auto;"
if RM:
html = str(soup).replace(str(soup.select_one(".toc")), f'{str(soup.select_one(".toc"))}<div class="toc"><ul><li><h3><a href="#table-of-contents">Table of Contents</a></h3>{str(toc.find_next("ul"))}</li></ul>')
quote = r"""
<blockquote style='background:hsla(0 0% 100% / 5%);padding:0 20px 5px 20px;margin:30px 0 0;'>
<span style='font-size:150px;line-height:70px;margin-left:-20px;opacity:0.2'>❝</span>
<p style='font-size:15px;margin-top:-50px'><b><i>...but I don't think you'll write code valuable enough for them</i></b> (Content creators and/or owners) <b><i>to do that</i></b> (file a DMCA strike against MangDL)</p>
<p">- <a href='https://github.com/justfoolingaround'>KR</a></p>
</blockquote>
<blockquote style='background:hsla(0 0% 100% / 5%);padding:0 20px 5px 20px;margin:30px 0 0;'>
<span style='font-size:150px;line-height:70px;margin-left:-20px;opacity:0.2'>❝</span>
<p style='font-size:15px;margin-top:-50px'><b><i><del>whi_ne has good organization</del></i></b> [skills] <b><i><del>and bad code</del></i></b></p>
<p">- <a href='https://github.com/ArjixWasTaken'>Arjix</a></p>
</blockquote>"""
html = html.replace(str(soup.select_one("#quotes")), quote)
hout.write(html)
shutil.rmtree("./docs/docs")
subprocess.call(shlex.split(f"pdoc --html --template-dir template -o docs --force ../MangDL/mangdl"))
shutil.move('./docs/mangdl', './docs/docs')
if __name__ == "__main__":
main()