"""Update the last time this alert was ran in the database."""
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):
"""Return all the queries for the given 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_alert_queries_for_user(uid):
"""Returns all the queries for the given user id."""
returnrun_sql('select distinct id, urlargs, uqb.frequency from query q, user_query_basket uqb where q.id=uqb.id_query and uqb.id_user=%s and uqb.date_lastrun <= now();',(uid,))
defget_alerts(query,frequency):
"""Returns a dictionary of all the records found for a specific query and frequency along with other informationm"""
r=run_sql('select id_user, id_query, id_basket, frequency, date_lastrun, alert_name, notification, alert_desc, alert_recipient from user_query_basket where id_query=%s and frequency=%s;',(query['id_query'],frequency,))
print"-> adding %s external records (collection \"%s\") into basket %s: %s"%(nrec_to_add,external_collection_results[0],basket_id,external_collection_results[1][0][:nrec_to_add])
ifnrec>nrec_to_add:
print"-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction"%(nrec-nrec_to_add,external_collection_results[0],basket_id,external_collection_results[1][0][nrec_to_add:])
print"-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction"%(nrec,external_collection_results[0],basket_id,external_collection_results[1][0])
print"-> not added %i external records (collection \"%s\") into basket %s: %s due to maximum limit restrictions"%(nrec,external_collection_results[0],basket_id,external_collection_results[1][0])
defget_query(alert_id):
"""Returns the query for that corresponds to this alert id."""
r=run_sql('select urlargs from query where id=%s',(alert_id,))
returnr[0][0]
defemail_notify(alert,records,argstr):
"""Send the notification e-mail for a specific alert."""
ifCFG_WEBALERT_DEBUG_LEVEL>2:
print"+"*80+'\n'
uid=alert[0]
user_info=collect_user_info(uid)
frequency=alert[3]
alert_name=alert[5]
alert_description=alert[7]
alert_recipient_email=alert[8]# set only by admin. Bypasses access-right checks.
filtered_out_recids=[]# only set in debug mode
ifnotalert_recipient_email:
# Filter out records that user (who setup the alert) should
# not see. This does not apply to external records (hosted