My main DB is db, the DB with the scheduler tables is db_sc.
# -*- coding: utf-8 -*-
def e_db():
today = datetime.datetime.today()
file_name = '%s_%s_%s_%s_%s:%s.csv' % (request.application, today.day, today.month, today.year, today.hour, today.minute)
file_url = '%s/static/z_backup/csv/%s' % (request.folder, file_name)
db.export_to_csv_file(open(file_url, 'wb'))
subject = 'Backup CSV %s' % request.application
message = 'Il backup CSV di %s è stato salvato in %s.' % (request.application, file_url)
'''email_sent = mail.send(
to = '
m...@domain.com',
subject = subject,
reply_to = '
m...@domain.com',
message = message)'''
db.commit()
def sitemap_txt_auto():
import os
from gluon.myregex import regex_expose
# Statics URLs
exclusions = ['make_slugs','get_fabbisogno','e_db','get_cart','get_product_cart','test_query','carrellon','ordine_verifican','order_sendn','brands', 'cart_qty', 'cart_weight', 'carrello', 'ordine_verifica', 'ordine_modifica_indirizzo', 'order_send', 'e_deb', 'fuzz', 'googleaf365ee20ab65216', 'insert_product_enquiry', 'insert_service_enquiry', 'prodotto', 'attivita_fattoria_didattica', 'test', 'edit', 'user','unsubscribe','sitemap_txt','download', 'call', 'data', 'upload', 'browse', 'delete']
ctldir = os.path.join(request.folder,"controllers")
ctls=os.listdir(ctldir)
if 'appadmin.py' in ctls: ctls.remove('appadmin.py')
if 'manage.py' in ctls: ctls.remove('manage.py')
if 'admin.py' in ctls: ctls.remove('admin.py')
if 'prod.py' in ctls: ctls.remove('prod.py')
if 'default.py.1' in ctls: ctls.remove('default.py.1')
sitemap='
https://www.sitedomain.com'
for ctl in ctls:
if ctl.endswith(".bak") == False:
filename = os.path.join(ctldir,ctl)
data = open(filename, 'r').read()
functions = regex_expose.findall(data)
for f in functions:
if not any(f in s for s in exclusions): # if function is not in exclustions
sitemap += '\r\n'
sitemap += '
https://www.sitedomain.com/%s' % (f)
# Dynamic URLs
# News
news = db(db.news.on_line == True).select(db.news.ALL)
for item in news:
sitemap += '\r\n'
sitemap += '
https://www.sitedomain.com/news?id=%s' % (str(
item.id))
# Products
products = db(db.products.on_line == True).select(db.products.ALL)
for item in products:
sitemap += '\r\n'
sitemap += '
https://www.sitedomain.com/prodotti?product_id=' + (str(
item.id)) + '&product_slug=' + item.product_slug
# Categories
sitemap += '\r\n'
sitemap += '
https://www.sitedomain.com
/prodotti?category_id=0'
categories = db().select(db.products_categories.ALL)
for item in categories:
sitemap += '\r\n'
sitemap += '
https://www.
sitedomain.com
/prodotti?category_id=%s' % (str(
item.id))
# Servizi
services = db().select(db.services.ALL)
for item in services:
sitemap += '\r\n'
sitemap += '
https://www.sitedomain.com/attivita_fattoria_didattica?id=%s' % (str(
item.id))
file = open('%s/static/sitemap.txt' %request.folder, 'w')
file.write(sitemap)
file.close()
file = open('%s/static/sitemaps/sitemap.txt' %request.folder, 'w')
file.write(sitemap)
file.close()
"""email_sent = mail.send(
to = '
m...@domain.com',
subject = 'Sitemap',
reply_to = '
m...@domain.com',
message = 'La sitemap è stata generata con successo.')"""
db.commit()
from gluon.scheduler import Scheduler
Scheduler(db_sc,dict(e_db=e_db, sitemap_txt_auto=sitemap_txt_auto))