#!/usr/bin/python # -*- coding: utf-8 -*- # --------------------------------------------------------------------------- # # # # List of URL # # Copyright (C) diSabler # # # # This program 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 3 of the License, or # # (at your option) any later version. # # # # This program 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 this program. If nоt, see . # # # # --------------------------------------------------------------------------- # import time,cgi,urllib2 def cur_execute_fetchall_sqlite3(*params): conn = sqlite3.connect(sqlite_base) if 'split_part' in list(params)[0]: conn.create_function('split_part', 3, sqlite3_split_part) if 'row_number' in list(params)[0]: global sqlite3_row_number_last_x sqlite3_row_number_last_x = 0 conn.create_function('row_number', 0, sqlite3_row_number) try: cur = conn.cursor() except: return None par = None try: params = list(params) params[0] = params[0].replace('%s','?').replace(' ilike ',' like ').replace(' update ',' `update` ').replace(' repeat ',' `repeat` ').replace(' option ',' `option` ').replace(' count ',' `count` ').replace(' match ',' `match` ') params = tuple(params) cur.execute(*params) try: par = cur.fetchall() except Exception, par: par = None if halt_on_exception: raise except Exception, par: par = None conn.rollback() if halt_on_exception: raise conn.close() return par def cur_execute_fetchall_mysql(*params): conn = mysqldb.connect(database=base_name, user=base_user, host=base_host, password=base_pass, port=base_port) try: cur = conn.cursor() except: return None par = None try: params = list(params) params[0] = params[0].replace(' ilike ',' like ').replace(' update ',' `update` ').replace(' repeat ',' `repeat` ').replace(' option ',' `option` ').replace(' count ',' `count` ').replace(' match ',' `match` ').replace('split_part(','substring_index(') params = tuple(params) cur.execute(*params) try: par = cur.fetchall() except Exception, par: par = None if halt_on_exception: raise except Exception, par: par = None conn.rollback() if halt_on_exception: raise conn.close() return par def cur_execute_fetchall(*params): if base_type == 'sqlite3': return cur_execute_fetchall_sqlite3(*params) elif base_type == 'mysql': return cur_execute_fetchall_mysql(*params) global conn try: cur = conn.cursor() except: return None if base_type == 'pgsql': psycopg2.extensions.register_type(psycopg2.extensions.UNICODE, cur) par = None try: cur.execute(*params) try: par = cur.fetchall() except Exception, par: if database_debug: try: par = str(par) except: par = unicode(par) else: par = None if halt_on_exception: raise except Exception, par: if database_debug: try: par = str(par) except: par = unicode(par) pprint(par,'red') else: par = None conn.rollback() if halt_on_exception: raise cur.close() return par html_head = ''' List of URL
%s
''' html_end = '''

%s ''' max_link_size = 64 url_count_limit = 100 database_debug = False halt_on_exception = False execfile('config.py') if base_type == 'pgsql': import psycopg2 import psycopg2.extensions conn = psycopg2.connect(database=base_name, user=base_user, host=base_host, password=base_pass, port=base_port) elif base_type == 'mysql': import mysql.connector as mysqldb elif base_type == 'sqlite3': import sqlite3 if base_type in ['mysql','sqlite3']: class psycopg2(): def InterfaceError(): return None form = cgi.FieldStorage() try: room = form.getvalue('room').decode('utf8') except: room = ' ' roomz = [t[0] for t in cur_execute_fetchall('select room from url group by room order by room;')] roomz = [' '] + roomz if not roomz: print 'Error! Stored URL not found!' if not room or room not in roomz: room = roomz[0] try: nick = form.getvalue('nick').decode('utf8') except: nick = ' ' nickz = [t[0] for t in cur_execute_fetchall('select nick from url group by nick order by nick;')] nickz = [' '] + nickz if not nickz: print 'Error! Stored URL not found!' if not nick or nick not in nickz: nick = nickz[0] try: min_date = cur_execute_fetchall('select time from url order by time limit 1;')[0][0] except: min_date = int(time.time()) try: now_date = cur_execute_fetchall('select time from url order by -time limit 1;')[0][0] except: now_date = int(time.time()) min_date = '%04d-%02d-%02d' % time.localtime(min_date)[:3] max_date = '%04d-%02d-%02d' % time.localtime(now_date)[:3] try: sel_date = form.getvalue('calendar') if not sel_date: raise now_date = sel_date except: sel_date = '' now_date = ''#max_date drop_list = '''
Choice room/nick and/or Choice date
''' drop_opt = '