Example #1
0
def create_sitemap():
    sm = Sitemap(changefreq="daily")
    sm.add("http://" + config.base_url, lastmod="today")

    db = dataset.connect("sqlite:///leyes.db")
    res = db.query("SELECT * FROM proyectos ORDER BY timestamp DESC")
    for i in res:
        url = "http://" + config.base_url + "p/" + i['short_url']
        lastmod = str(datetime.datetime.fromtimestamp(int(i['timestamp'])))
        lastmod = lastmod.split(" ")[0]
        sm.add(url, lastmod=lastmod)

    for i in glob.glob(os.path.join(config.base_folder, "congresista/*")):
        i = os.path.basename(i)
        url = "http://" + config.base_url + "congresista/" + i + "/index.html"
        sm.add(url, lastmod="today")

    out = codecs.open("sitemap.xml", "w", "utf-8")
    sm.write(out)
    out.close()
Example #2
0
def build_sitemap():
    from redberry.models import RedPost, RedCategory
    from apesmit import Sitemap
    sm = Sitemap(changefreq='weekly')

    for post in RedPost.all_published():
        sm.add(url_for('redberry.show_post', slug=post.slug, _external=True),
               lastmod=post.updated_at.date())

    for category in RedCategory.query.all():
        sm.add(url_for('redberry.show_category',
                       category_slug=category.slug,
                       _external=True),
               lastmod=category.updated_at.date())

    with open(os.path.join(REDBERRY_ROOT, 'static', 'redberry', 'sitemap.xml'),
              'w') as f:
        sm.write(f)

    flash("Sitemap created.", 'success')
    return redirect(url_for('redberry.home'))