-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
69 lines (53 loc) · 1.7 KB
/
generate.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
import jinja2
import pathlib
from yaml import load, Loader
import markdown
import requests
import gnupg
from datetime import datetime,timezone
identities = pathlib.Path("identities")
with (identities / "conf.yaml").open() as f:
conf = load(f, Loader=Loader)
def getsign(message):
gpg = gnupg.GPG()
sign = gpg.sign(message)
return sign.data
def genmisc():
miscpath = identities / "misc"
misc = []
for mdir in miscpath.iterdir():
with (mdir / "content.md").open() as f:
content = markdown.markdown(
f.read().strip(), extensions=["markdown.extensions.extra"]
)
with (mdir / "title").open() as f:
title = f.read().strip()
misc.append({"content": content, "title": title})
return misc
def getbtcblock():
btcdata = requests.get("https://blockchain.info/latestblock").json()
return {
"hash": btcdata["hash"],
"height": btcdata["height"],
"url": "https://www.blockchain.com/btc/block/{}".format(btcdata["hash"]),
}
def placeurl():
with (identities / "url").open("w") as f:
f.write(conf['url'])
def gentemplate():
with open("index.html.j2") as f:
template = f.read()
jtemplate = jinja2.Template(template)
return jtemplate.render(
conf=conf, btchash=getbtcblock(), misc=genmisc(), date=datetime.now(timezone.utc).strftime("%X %x %Z")
)
def main():
html = gentemplate()
html = "-->\n{}\n<!--".format(html).encode("utf8")
signed_html = getsign(html).decode("utf8")
out_html = "<!--\n{}\n-->".format(signed_html)
with open("out/index.html", "w") as f:
f.write(out_html)
placeurl()
if __name__ == "__main__":
main()