-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_sitemap_pl.py
More file actions
50 lines (41 loc) · 1.65 KB
/
Copy pathgenerate_sitemap_pl.py
File metadata and controls
50 lines (41 loc) · 1.65 KB
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
#!/usr/bin/env python3
"""
Generator sitemap.xml dla devroman.pl
Odpowiednik generate_sitemap.py z archiwum programist.matviy.pp.ua
"""
import os
import datetime
from generate_pl import services, geos, cities, BASE_URL
def format_url(loc, priority, lastmod):
return f"""<url>
<loc>{loc}</loc>
<lastmod>{lastmod}</lastmod>
<priority>{priority}</priority>
</url>
"""
def generate_sitemap():
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S+00:00")
urls = []
# Strona główna
urls.append(format_url(f"{BASE_URL}/", "1.00", now))
# FAQ
urls.append(format_url(f"{BASE_URL}/faq.html", "0.80", now))
for service_slug in services:
urls.append(format_url(f"{BASE_URL}/{service_slug}/", "0.90", now))
for geo_slug in geos:
urls.append(format_url(f"{BASE_URL}/{service_slug}/{geo_slug}/", "0.85", now))
for city_slug in cities:
urls.append(format_url(f"{BASE_URL}/{service_slug}/{geo_slug}/{city_slug}/", "0.70", now))
xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
xml += '<urlset\n'
xml += ' xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"\n'
xml += ' xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"\n'
xml += ' xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9\n'
xml += ' https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n'
xml += "".join(urls)
xml += "</urlset>"
with open("sitemap.xml", "w", encoding="utf-8") as f:
f.write(xml)
print(f"[DONE] sitemap.xml wygenerowany. Łącznie URL: {len(urls)}")
if __name__ == "__main__":
generate_sitemap()