aboutsummaryrefslogtreecommitdiffstats
path: root/extra/sitemap/generate_sitemap_indices.py
blob: bfdc4864102fb4f0e9502ecfa7bfea1377d4d8e8 (plain)
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
#!/usr/bin/env python3

import sys
import glob
import datetime

def index_entity(entity_type, output):

    now = datetime.date.today().isoformat()
    print("""<?xml version="1.0" encoding="UTF-8"?>""", file=output)
    print("""<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">""", file=output)

    for filename in glob.glob(f"sitemap-{entity_type}-*.txt"):
        print("  <sitemap>", file=output)
        print(f"    <loc>https://scholar.archive.org/{filename}</loc>", file=output)
        print(f"    <lastmod>{now}</lastmod>", file=output)
        print("  </sitemap>", file=output)

    print("</sitemapindex>", file=output)

def main():
    with open('sitemap-index-works.xml', 'w') as output:
        index_entity("works", output)
    with open('sitemap-index-access.xml', 'w') as output:
        index_entity("access", output)

if __name__=="__main__":
    main()