Skip to content

Commit b8b51dc

Browse files
committed
added diverse features
1 parent f697f28 commit b8b51dc

File tree

5 files changed

+754
-99
lines changed

5 files changed

+754
-99
lines changed

examples/sitemap.xml

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<?xml-stylesheet type="text/xsl" href="//seowings.org/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
3-
<!--sitemap avialble at https://www.seowings.org/-->
4-
<node_urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2+
<?xml-stylesheet type="text/xsl" href="https://www.seowings.org/main-sitemap.xsl"?>
3+
<!--sitemap avialble at https://www.seowings.org/sitemap.xml -->
4+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
55
<url>
6-
<loc>a.html</loc>
7-
<node_lastmod>2022</node_lastmod>
6+
<loc>https://www.seowings.org/a.html</loc>
7+
<lastmod>2022-12-25</lastmod>
88
<image:image>
9-
<image:loc>abc.png</image:loc>
9+
<image:loc>https://www.seowings.org/a1.png</image:loc>
1010
</image:image>
1111
</url>
1212
<url>
13-
<loc>b.html</loc>
14-
<node_lastmod>2021</node_lastmod>
13+
<loc>https://www.seowings.org/b.html</loc>
14+
<lastmod>2023-05-01</lastmod>
1515
<image:image>
16-
<image:loc>def.png</image:loc>
17-
</image:image>
18-
</url>
19-
<url>
20-
<loc>b.html</loc>
21-
<node_lastmod>2021</node_lastmod>
22-
<image:image>
23-
<image:loc>c.png</image:loc>
16+
<image:loc>https://www.seowings.org/b1.png</image:loc>
2417
</image:image>
2518
<image:image>
26-
<image:loc>b.png</image:loc>
19+
<image:loc>https://www.seowings.org/b2.png</image:loc>
2720
</image:image>
2821
</url>
29-
</node_urlset>
30-
<!--XML Sitemap generated by pythonic-sitemap-->
22+
</urlset>
23+
<!--XML Sitemap generated by pysitemaps-->

examples/tutorial.py

+100-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,103 @@
1-
from pysitemaps import Sitemap, Url
1+
from pysitemaps import Sitemap, Url, XmlDocument
2+
from pprint import pprint
23

3-
if __name__ == "__main__":
44

5-
smp = Sitemap()
6-
smp.add_url(Url("a.html", "2022", ["abc.png"]))
7-
smp.add_url(Url("b.html", "2021", ["def.png"]))
8-
smp.add_url(Url("b.html", "2021", ["c.png", "b.png"]))
9-
smp.process()
5+
def demo_read_sitemap():
6+
smp = Sitemap(
7+
website_name="seowings.org",
8+
)
9+
smp.read("sitemap.xml")
10+
pprint(smp.as_dict())
11+
12+
13+
def demo_create_sitemap():
14+
smp = Sitemap(
15+
website_name="https://www.seowings.org/",
16+
file_path="sitemap.xml",
17+
xsl_file="https://www.seowings.org/main-sitemap.xsl",
18+
)
19+
smp.append(
20+
Url(
21+
loc="https://www.seowings.org/a.html",
22+
lastmod="2022-12-25",
23+
images_loc=["https://www.seowings.org/a1.png"],
24+
)
25+
)
26+
smp.append(
27+
{
28+
"loc": "https://www.seowings.org/b.html",
29+
"lastmod": "2023-05-01",
30+
"images_loc": [
31+
"https://www.seowings.org/b1.png",
32+
"https://www.seowings.org/b2.png",
33+
],
34+
}
35+
)
1036
smp.write()
37+
pprint(smp.as_dict())
38+
39+
40+
def demo_locate_sitemap():
41+
smp = Sitemap(website_name="https://www.seowings.org/")
42+
smp.fetch(include_urls=False)
43+
print(smp.as_dict())
44+
45+
46+
def demo_fetch_sitemap():
47+
smp = Sitemap(website_name="https://www.seowings.org/")
48+
smp.fetch(include_urls=True)
49+
print(smp.as_dict())
50+
51+
52+
def demo_fetch_index_sitemap():
53+
smp = Sitemap(website_name="https://www.dw.com/")
54+
smp.fetch(include_urls=False)
55+
print(smp.as_dict())
56+
57+
58+
def demo_create_xml_doc():
59+
from datetime import datetime
60+
61+
news_sitemap = XmlDocument(
62+
"sitemap-news.xml",
63+
lastmod=datetime.now().strftime("%Y-%m-%d"),
64+
include_urls=False,
65+
)
66+
news_sitemap.add_object(Url("b.html", "2023-05-02", ["img1.png", "img2.png"]))
67+
news_sitemap.add_url(
68+
loc="c.html", lastmod="2023-01-02", images_loc=["img4.png", "img5.png"]
69+
)
70+
news_sitemap.add_from_text(
71+
"""
72+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
73+
<url>
74+
<loc>z.html</loc>
75+
<lastmod>2022</lastmod>
76+
<image:image>
77+
<image:loc>z.png</image:loc>
78+
</image:image>
79+
</url>
80+
<url>
81+
<loc>dz.html</loc>
82+
<lastmod>2022</lastmod>
83+
<image:image>
84+
<image:loc>z.png</image:loc>
85+
</image:image>
86+
<image:image>
87+
<image:loc>a.png</image:loc>
88+
</image:image>
89+
</url>
90+
</urlset>
91+
"""
92+
)
93+
94+
print(news_sitemap.as_dict())
95+
96+
97+
if __name__ == "__main__":
98+
demo_create_sitemap()
99+
demo_read_sitemap()
100+
demo_locate_sitemap()
101+
demo_fetch_sitemap()
102+
demo_fetch_index_sitemap()
103+
demo_create_xml_doc()

0 commit comments

Comments
 (0)