def check_number(self, number): query = "SELECT Reason FROM Whitelist WHERE PhoneNo=:number" args = {"number": number} results = query_db(self.db, query, args, False) if len(results) > 0: return True, results[0][0] else: return False, ""
def check_number(self, number): """ Checks if the number is in the blacklist :parma number: the number to look for :returns: True if found; and a string containing the reason """ query = "SELECT Reason FROM Blacklist WHERE PhoneNo=:number" args = {"number": number} results = query_db(self.db, query, args, False) if len(results) > 0: return True, results[0][0] else: return False, ""
def log_caller(self, callerid, action="Screened", reason=""): """ Logs the given caller into the Call Log table. :param caller: a dict object containing the caller ID info :return: The CallLogID of the new record """ # Add a row sql = """INSERT INTO CallLog( Name, Number, Action, Reason, Date, Time, SystemDateTime) VALUES(?,?,?,?,?,?,?)""" arguments = [callerid['NAME'], callerid['NMBR'], action, reason, datetime.strptime(callerid['DATE'], '%m%d'). strftime('%d-%b'), datetime.strptime(callerid['TIME'], '%H%M'). strftime('%I:%M %p'), (datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:19])] self.db.execute(sql, arguments) self.db.commit() # Return the CallLogID query = "select last_insert_rowid()" result = query_db(self.db, query, (), True) call_no = result[0] if self.config["DEBUG"]: print("> New call log entry #{}".format(call_no)) pprint(arguments) return call_no
def callers_manage(call_no): """ Display the Manage Caller form """ post_count = None # Post changes to the blacklist or whitelist table before rendering if request.method == 'POST': number = request.form['phone_no'].replace('-', '') if request.form['action'] == 'add-permit': caller = {} caller['NMBR'] = number caller['NAME'] = request.form['name'] print(" >> Adding " + caller['NAME'] + " to whitelist") whitelist = Whitelist(get_db(), current_app.config) whitelist.add_caller(caller, request.form['reason']) elif request.form['action'] == 'remove-permit': print(" >> Removing " + number + " from whitelist") whitelist = Whitelist(get_db(), current_app.config) whitelist.remove_number(number) elif request.form['action'] == 'add-block': caller = {} caller['NMBR'] = number caller['NAME'] = request.form['name'] print(" >> Adding " + caller['NAME'] + " to blacklist") blacklist = Blacklist(get_db(), current_app.config) blacklist.add_caller(caller, request.form['reason']) elif request.form['action'] == 'remove-block': print(" >> Removing " + number + " from blacklist") blacklist = Blacklist(get_db(), current_app.config) blacklist.remove_number(number) # Keep track of the number of posts so we can to unwind the history # to bo "back" the original referrer post_count = int(request.form['post_count']) post_count += 1 else: post_count = 0 # Retrieve the caller information for the given call log entry query = """SELECT a.CallLogID, a.Name, a.Number, CASE WHEN b.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Whitelisted, CASE WHEN c.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Blacklisted, CASE WHEN b.PhoneNo IS NOT NULL THEN b.Reason ELSE '' END WhitelistReason, CASE WHEN c.PhoneNo IS NOT NULL THEN c.Reason ELSE '' END BlacklistReason FROM calllog AS a LEFT JOIN whitelist AS b ON a.Number = b.PhoneNo LEFT JOIN blacklist AS c ON a.Number = c.PhoneNo WHERE a.CallLogID=:call_log_id""" arguments = {"call_log_id": call_no} result_set = query_db(get_db(), query, arguments) # Prepare a caller dictionary object for the form caller = {} if len(result_set) > 0: record = result_set[0] number = record[2] caller.update( dict(call_no=record[0], phone_no='{}-{}-{}'.format(number[0:3], number[3:6], number[6:]), name=record[1], whitelisted=record[3], blacklisted=record[4], whitelist_reason=record[5], blacklist_reason=record[6])) else: caller.update( dict(call_no=call_no, phone_no='Number Not Found', name='', whitelisted='N', blacklisted='N', whitelist_reason='', blacklist_reason='')) # Re-render the same page to show the updated content return render_template('callers_manage.html', caller=caller, post_count=post_count)
def get_number(self, number): query = "SELECT * FROM Blacklist WHERE PhoneNo = ?" args = (number, ) results = query_db(self.db, query, args, False) return results