Url Class¶
A class to store a URL Object.
This class contains several function/methods to handle sitemap urls.
Source code in pysitemaps/__init__.py
class Url:
"""
A class to store a URL Object.
This class contains several function/methods to handle sitemap urls.
"""
def __init__(
self,
loc: str,
lastmod: str = datetime.now().strftime("%Y-%m-%d"),
images_loc: list = [],
) -> None:
"""Intialize Url Object
Args:
loc (str): location of Url (full path with scheme)
lastmod (str, optional): last modification date of Url. Defaults to datetime.now().strftime("%Y-%m-%d").
images_loc (list, optional): List of Images included in the Url. Defaults to [].
"""
self.loc = loc
self.lastmod = lastmod
self.image_locations = images_loc
def add_images(self, images_loc: list = []) -> None:
"""append images to current Url
Args:
images_loc (list, optional): list of images location. Defaults to [].
"""
self.image_locations += images_loc
def as_dict(self) -> dict:
"""return Url as dict object
Returns:
dict: contains loc, lastmod and images keys.
"""
return {
"loc": self.loc,
"lastmod": self.lastmod,
"images": self.image_locations,
}
__init__(loc, lastmod=datetime.now().strftime('%Y-%m-%d'), images_loc=[])
¶
Intialize Url Object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loc |
str
|
location of Url (full path with scheme) |
required |
lastmod |
str
|
last modification date of Url. Defaults to datetime.now().strftime(“%Y-%m-%d”). |
datetime.now().strftime('%Y-%m-%d')
|
images_loc |
list
|
List of Images included in the Url. Defaults to []. |
[]
|
Source code in pysitemaps/__init__.py
def __init__(
self,
loc: str,
lastmod: str = datetime.now().strftime("%Y-%m-%d"),
images_loc: list = [],
) -> None:
"""Intialize Url Object
Args:
loc (str): location of Url (full path with scheme)
lastmod (str, optional): last modification date of Url. Defaults to datetime.now().strftime("%Y-%m-%d").
images_loc (list, optional): List of Images included in the Url. Defaults to [].
"""
self.loc = loc
self.lastmod = lastmod
self.image_locations = images_loc
add_images(images_loc=[])
¶
append images to current Url
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images_loc |
list
|
list of images location. Defaults to []. |
[]
|
Source code in pysitemaps/__init__.py
def add_images(self, images_loc: list = []) -> None:
"""append images to current Url
Args:
images_loc (list, optional): list of images location. Defaults to [].
"""
self.image_locations += images_loc
as_dict()
¶
return Url as dict object
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
contains loc, lastmod and images keys. |
Source code in pysitemaps/__init__.py
def as_dict(self) -> dict:
"""return Url as dict object
Returns:
dict: contains loc, lastmod and images keys.
"""
return {
"loc": self.loc,
"lastmod": self.lastmod,
"images": self.image_locations,
}