-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsitemap_maker
More file actions
executable file
·39 lines (32 loc) · 910 Bytes
/
sitemap_maker
File metadata and controls
executable file
·39 lines (32 loc) · 910 Bytes
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
#!/usr/bin/env python3
from os.path import abspath, dirname
import configparser
import psycopg2
root_path = abspath(dirname(__file__))
config = configparser.ConfigParser()
config.read(root_path + "/config.ini")
robots = open("static/robots.txt", "w")
robots.write(
r"""User-agent: *
Allow: /
Sitemap: https://labourstudies.ca/sitemap.xml
"""
)
sm = open("static/sitemap.xml", "w")
conn = psycopg2.connect(
database=config["database"]["dbname"], user=config["database"]["dbuser"]
)
sm.write(
r"""<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
"""
)
with conn:
# citations
with conn.cursor() as c:
c.execute(r"""SELECT id FROM citations ORDER BY id DESC""")
for r in c:
sm.write(
"<url><loc>https://labourstudies.ca/citation/%d</loc></url>\n" % (r[0])
)
sm.write("</urlset>")