-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.py
204 lines (161 loc) · 8.36 KB
/
build.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from genericpath import exists
import os
import sys
import json
import pathlib
import shutil
def generate_for_entry(deploy_path, uid, entry):
import string
html = []
entry["description"] = entry["description"].replace("\n", "<br>")
# INTRO
intro = string.Template(f"""
<div id="botName">$name</div>
<div id="botAuthor">by <a href="$author_site">$author_name</a> on $upload_date</div>
<div id="botDescription">$description</div>
""").safe_substitute(**entry)
html.append(intro)
# TAGS
html.append(""" <div class="card_bot_tags_bot"><b>tags: </b>""")
tag = string.Template(""" <div class="card_bot_tag">$programming_language</div>""").safe_substitute(**entry)
html.append(tag)
for tag in entry.get('tags'):
tag = string.Template(""" <div class="card_bot_tag">$tag</div>""").safe_substitute(tag=tag)
html.append(tag)
html.append(""" </div>""")
# GH repo card
if entry.get("repository_url", ""):
org = entry.get("repository_url", "").split("/")[-2]
entry["org"] = org
gh = string.Template(
f"""
<div class="div_git_repo">
<b>Repository:</b><br/>
<a href="$repository_url">
<img align="center" src="https://github-readme-stats.vercel.app/api/pin/?username=$org&repo=$repository_name"/>
</a><br/>
<font style='font-size:12px'>* Source code may be subject to copyright, check with author for redistribution.</font>
</div>
"""
).safe_substitute(**entry)
html.append(gh)
# YouTube Video
if entry.get("youtube_video"):
entry["hp"] = entry.get("youtube_height")/entry.get("youtube_width")*100
youtube = string.Template(
"""
<div class="video-container" style="padding-bottom:$hp%">
<iframe class="youtube_embeded" width="" height="" src="$youtube_video" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
"""
).safe_substitute(**entry)
html.append(youtube)
entry["url"] = f"https://repository.botcity.dev/bot-{uid}.html"
upload_date_iso = "/".join(entry.get("upload_date").split("/")[::-1])
entry["upload_date_iso"] = upload_date_iso
share = f"""
<p style="margin-top: 10px">
<b>Share this Bot:</b>
</p>
<div class="div_share">
<!-- AddToAny BEGIN -->
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-copy" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_copy_link"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-linkedin" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_linkedin"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-whatsapp" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_whatsapp"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-twitter" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_twitter"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-telegram" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_telegram"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-mastodon" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_mastodon"></a>
</div>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://repository.botcity.dev/bot-{uid}.html?utm_source=bot-repository&utm_medium=referral-email" data-a2a-title="I liked this bot that I saw in the Bot Repository. Check it out.">
<a class="a2a_button_email"></a>
</div>
<script async src="https://static.addtoany.com/menu/page.js"></script>
<!-- AddToAny END -->
</div>
"""
html.append(share)
page = """
<html xmlns:og="http://opengraphprotocol.org/schema/" >
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-N4HVP5D');</script>
<!-- End Google Tag Manager -->
<meta charset="UTF-8">
<link rel="stylesheet" href="./css/main.css">
<link rel="stylesheet" href="./css/bot.css">
<title>BotRepository - $name</title>
<!-- Essential META Tags -->
<meta property="og:type" content="article" />
<meta property="og:title" content="BotRepository - $name" />
<meta property="og:site_name" content="BotRepository" />
<meta property="og:url" content="$url" />
<meta property="og:image" content="$thumbnail_url" />
<meta property="og:description" content="$description" />
<meta property="article:author" content="$author_name" />
<meta property="article:published_time" content="$upload_date_iso" />
<meta property="og:locale" content="en_US"/>
<!-- Non-Essential, But Required for Analytics -->
<meta name="twitter:site" content="@BotcityDev" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image:alt" content="$name" />
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N4HVP5D"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<!-- HEADER -->
<div data-include="header"></div>
<!-- Main Content -->
<div id="botPanel">$content</div>
<!-- FOOTER -->
<div data-include="footer"></div>
<script src="./js/jquery-3.6.0.min.js"></script>
<script src="./js/ui.js"></script>
<script>
$(function () {
UI.load();
});
</script>
</body>
</html>
"""
page_code = string.Template(page).safe_substitute(content="\n".join(html), **entry)
output_file = os.path.join(deploy_path, f"bot-{uid}.html")
with open(output_file, "w") as f:
f.write(page_code)
def build():
OUTPUT_FOLDER = "site-deploy"
base_path = os.path.dirname(os.path.realpath(__file__))
base_site = os.path.join(base_path, "site")
json_file = os.path.join(base_site, "data", "records.json")
deploy_path = os.path.join(base_path, OUTPUT_FOLDER)
if not os.path.exists(json_file) or not os.path.isfile(json_file):
sys.exit("Could not find site/data/records.json file.")
print("Base Path: ", base_path)
print("Base Site: ", base_site)
print("JSON File: ", json_file)
print("Deploy Path: ", deploy_path)
shutil.rmtree(deploy_path, ignore_errors=True)
shutil.copytree(base_site, deploy_path)
with open(json_file, "r") as f:
database = json.loads(f.read())
for uid, entry in enumerate(database):
generate_for_entry(deploy_path, uid, entry)
print(f"All set. Your new site is available at: {deploy_path}")
build()