## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
##read config variables
#include "config.wml"
#include "configbis.wml"
<protect>## $Id$ </protect>
<protect>## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.</protect>
"""Alert engine implementation."""
## rest of the Python code goes below
__version__="$Id$"
try:
fromcgiimportparse_qs
fromreimportsearch
fromtimeimportlocaltime,strftime,mktime
importsmtplib
fromconfigimport*
fromsearch_engineimportperform_request_search
fromdbqueryimportrun_sql
fromhtmlparserimport*
exceptImportError,e:
print"Error: %s"%e
importsys
sys.exit(1)
MAXIDS=50
FROMADDR='CDS Alert Service <%s>'%supportemail
ALERTURL=weburl+'/youralerts.py/list'
# 0 = production, nothing on the console, email sent
# 1 = messages on the console, email sent
# 2 = messages on the console, but no email sent
# 3 = many messages on the console, no email sent
DEBUGLEVEL=3
defupdate_date_lastrun(alert):
returnrun_sql('update user_query_basket set date_lastrun=%s where id_user=%s and id_query=%s and id_basket=%s;',(strftime("%Y-%m-%d"),alert[0],alert[1],alert[2],))
defget_alert_queries(frequency):
returnrun_sql('select distinct id, urlargs from query q, user_query_basket uqb where q.id=uqb.id_query and uqb.frequency=%s and uqb.date_lastrun <= now();',(frequency,))
defget_alerts(query,frequency):
r=run_sql('select id_user, id_query, id_basket, frequency, date_lastrun, alert_name, notification from user_query_basket where id_query=%s and frequency=%s;',(query['id_query'],frequency,))