Ejemplo n.º 1
0
from __future__ import absolute_import, print_function

from xml.etree.cElementTree import Element, SubElement, tostring
from xml.etree.ElementTree import _namespace_map

ns = 'http://www.sitemaps.org/schemas/sitemap/0.9'
_namespace_map.setdefault(ns, 'sitemap')

# nsmap_keyargs = {}
# if getattr(etree, 'LXML_VERSION', (0, 0, 0, 0)) >= (1, 3, 7, 0):
#     nsmap_keyargs = {'nsmap': {'sitemap':ns}}

nstags_cache = {}


def nstag(tag):
    return nstags_cache.get(tag) or nstags_cache.setdefault(
        tag, '{%s}%s' % (ns, tag))


def generate_sitemap(links):
    urlset = Element(nstag('urlset'))  #, **nsmap_keyargs) # lxml
    urlset.text = '\n'
    for link in links:
        if isinstance(link, basestring):
            loc = link
            lastmod = changefreq = priority = None
        else:
            loc, lastmod, changefreq, priority = (tuple(link) +
                                                  (None, None, None))[:4]
        url = SubElement(urlset, nstag('url'))
from __future__ import absolute_import, print_function

from xml.etree.cElementTree import Element, SubElement, tostring
from xml.etree.ElementTree import _namespace_map

ns = "http://www.sitemaps.org/schemas/sitemap/0.9"
_namespace_map.setdefault(ns, "sitemap")

# nsmap_keyargs = {}
# if getattr(etree, 'LXML_VERSION', (0, 0, 0, 0)) >= (1, 3, 7, 0):
#     nsmap_keyargs = {'nsmap': {'sitemap':ns}}

nstags_cache = {}


def nstag(tag):
    return nstags_cache.get(tag) or nstags_cache.setdefault(tag, "{%s}%s" % (ns, tag))


def generate_sitemap(links):
    urlset = Element(nstag("urlset"))  # , **nsmap_keyargs) # lxml
    urlset.text = "\n"
    for link in links:
        if isinstance(link, basestring):
            loc = link
            lastmod = changefreq = priority = None
        else:
            loc, lastmod, changefreq, priority = (tuple(link) + (None, None, None))[:4]
        url = SubElement(urlset, nstag("url"))
        url.text = url.tail = "\n"
        SubElement(url, nstag("loc")).text = loc
Ejemplo n.º 3
0
from __future__ import absolute_import, print_function

from xml.etree.cElementTree import Element, SubElement, tostring
from xml.etree.ElementTree import _namespace_map

ns = 'http://www.sitemaps.org/schemas/sitemap/0.9'
_namespace_map.setdefault(ns, 'sitemap')

# nsmap_keyargs = {}
# if getattr(etree, 'LXML_VERSION', (0, 0, 0, 0)) >= (1, 3, 7, 0):
#     nsmap_keyargs = {'nsmap': {'sitemap':ns}}

nstags_cache = {}

def nstag(tag):
    return nstags_cache.get(tag) or nstags_cache.setdefault(tag, '{%s}%s' % (ns, tag))

def generate_sitemap(links):
    urlset = Element(nstag('urlset')) #, **nsmap_keyargs) # lxml
    urlset.text = '\n'
    for link in links:
        if isinstance(link, basestring):
            loc = link
            lastmod = changefreq = priority = None
        else: loc, lastmod, changefreq, priority = (tuple(link) + (None, None, None))[:4]
        url = SubElement(urlset, nstag('url'))
        url.text = url.tail = '\n'
        SubElement(url, nstag('loc')).text = loc
        if lastmod:
            if not isinstance(lastmod, basestring):
                if getattr(lastmod, 'tzinfo', None) is not None:
from __future__ import absolute_import, print_function

import time, rfc822

from xml.etree.cElementTree import Element, SubElement, tostring
from xml.etree.ElementTree import _namespace_map

from pony.templating import Html, StrHtml

ns = 'http://www.w3.org/2005/Atom'
_namespace_map.setdefault(ns, 'atom')

# nsmap_keyargs = {}
# if getattr(etree, 'LXML_VERSION', (0, 0, 0, 0)) >= (1, 3, 7, 0):
#     nsmap_keyargs = {'nsmap': {'atom':ns}}

atomtags_cache = {}


def atomtag(tag):
    return nstags_cache.get(tag) or nstags_cache.setdefault(
        tag, '{%s}%s' % (ns, tag))


def utc(dt):
    if getattr(dt, 'tzinfo', None) is None: return dt
    return dt.replace(tzinfo=None) - dt.utcoffset()


def atom_date(date):
    return utc(date).strftime('%Y-%m-%dT%H:%M:%SZ')
Ejemplo n.º 5
0
from __future__ import absolute_import, print_function

import time, rfc822

from xml.etree.cElementTree import Element, SubElement, tostring
from xml.etree.ElementTree import _namespace_map

from pony.templating import Html, StrHtml

ns = 'http://www.w3.org/2005/Atom'
_namespace_map.setdefault(ns, 'atom')

# nsmap_keyargs = {}
# if getattr(etree, 'LXML_VERSION', (0, 0, 0, 0)) >= (1, 3, 7, 0):
#     nsmap_keyargs = {'nsmap': {'atom':ns}}

atomtags_cache = {}

def atomtag(tag):
    return nstags_cache.get(tag) or nstags_cache.setdefault(tag, '{%s}%s' % (ns, tag))

def utc(dt):
    if getattr(dt, 'tzinfo', None) is None: return dt
    return dt.replace(tzinfo=None) - dt.utcoffset()

def atom_date(date):
    return utc(date).strftime('%Y-%m-%dT%H:%M:%SZ')

def rss2_date(date):
    return rfc822.formatdate(time.mktime(utc(date).timetuple()))