logotron_genesis.kv 1
logotron_genesis.kv 2
logotron_genesis.kv 3
logotron_genesis.kv 4 import ConfigParser, sys
logotron_genesis.kv 5 import psycopg2, psycopg2.extras
logotron_genesis.kv 6 import psycopg2.extensions
logotron_genesis.kv 7 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
logotron_genesis.kv 8 psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
logotron_genesis.kv 9 import time
logotron_genesis.kv 10 import datetime
logotron_genesis.kv 11 from datetime import timedelta
logotron_genesis.kv 12 import sys
logotron_genesis.kv 13 reload(sys)
logotron_genesis.kv 14 sys.setdefaultencoding('utf8')
logotron_genesis.kv 15 import os
logotron_genesis.kv 16 import threading
logotron_genesis.kv 17 import re
logotron_genesis.kv 18 from datetime import datetime
logotron_genesis.kv 19 from urlparse import urljoin
raw_line_export.kv 20 from flask import Flask, request, session, url_for, redirect, Response, \
logotron_genesis.kv 21 render_template, abort, g, flash, _app_ctx_stack, make_response, \
logotron_genesis.kv 22 jsonify
logotron_genesis.kv 23 from flask import Flask
logotron_genesis.kv 24 from flask.ext.cache import Cache
logotron_genesis.kv 25
logotron_genesis.kv 26
logotron_genesis.kv 27
logotron_genesis.kv 28
logotron_genesis.kv 29 if len(sys.argv[1:]) != 1:
logotron_genesis.kv 30
logotron_genesis.kv 31 print sys.argv[0] + " CONFIG"
logotron_genesis.kv 32 exit(0)
logotron_genesis.kv 33
logotron_genesis.kv 34
logotron_genesis.kv 35 config_path = os.path.abspath(sys.argv[1])
logotron_genesis.kv 36 cfg = ConfigParser.ConfigParser()
logotron_genesis.kv 37 cfg.readfp(open(config_path))
logotron_genesis.kv 38
logotron_genesis.kv 39 try:
logotron_genesis.kv 40
logotron_genesis.kv 41 Nick = cfg.get("irc", "nick")
logotron_genesis.kv 42 Channels = [x.strip() for x in cfg.get("irc", "chans").split(',')]
logotron_genesis.kv 43 Bots = [x.strip() for x in cfg.get("logotron", "bots").split(',')]
logotron_genesis.kv 44 Bots.append(Nick)
logotron_genesis.kv 45
logotron_genesis.kv 46 DB_Name = cfg.get("db", "db_name")
logotron_genesis.kv 47 DB_User = cfg.get("db", "db_user")
raw_line_export.kv 48 DB_DEBUG = int(cfg.get("db", "db_debug"))
logotron_genesis.kv 49
logotron_genesis.kv 50 Base_URL = cfg.get("logotron", "base_url")
logotron_genesis.kv 51 Era = int(cfg.get("logotron", "era"))
raw_line_export.kv 52 DEBUG = int(cfg.get("logotron", "www_dbg"))
raw_line_export.kv 53 Max_Raw_Ln = int(cfg.get("logotron", "max_raw"))
logotron_genesis.kv 54
logotron_genesis.kv 55 WWW_Port = int(cfg.get("logotron", "www_port"))
logotron_genesis.kv 56
logotron_genesis.kv 57 except Exception as e:
logotron_genesis.kv 58 print "Invalid config: ", e
logotron_genesis.kv 59 exit(1)
logotron_genesis.kv 60
logotron_genesis.kv 61
logotron_genesis.kv 62
logotron_genesis.kv 63
logotron_genesis.kv 64
logotron_genesis.kv 65 Default_Chan = Channels[0]
logotron_genesis.kv 66 Min_Query_Length = 3
logotron_genesis.kv 67 Max_Search_Results = 1000
logotron_genesis.kv 68
logotron_genesis.kv 69
logotron_genesis.kv 70 Date_Short_Format = "%Y-%m-%d"
logotron_genesis.kv 71
logotron_genesis.kv 72
logotron_genesis.kv 73 app = Flask(__name__)
logotron_genesis.kv 74 cache = Cache(app,config={'CACHE_TYPE': 'simple'})
logotron_genesis.kv 75 app.config.from_object(__name__)
logotron_genesis.kv 76
logotron_genesis.kv 77 def get_db():
logotron_genesis.kv 78 db = getattr(g, 'db', None)
logotron_genesis.kv 79 if db is None:
logotron_genesis.kv 80 db = g.db = psycopg2.connect("dbname=%s user=%s" % (DB_Name, DB_User))
logotron_genesis.kv 81 return db
logotron_genesis.kv 82
logotron_genesis.kv 83 def close_db():
logotron_genesis.kv 84 if hasattr(g, 'db'):
logotron_genesis.kv 85 g.db.close()
logotron_genesis.kv 86
logotron_genesis.kv 87 @app.before_request
logotron_genesis.kv 88 def before_request():
logotron_genesis.kv 89 g.db = get_db()
logotron_genesis.kv 90
logotron_genesis.kv 91 @app.teardown_request
logotron_genesis.kv 92 def teardown_request(exception):
logotron_genesis.kv 93 close_db()
logotron_genesis.kv 94
logotron_genesis.kv 95 def query_db(query, args=(), one=False):
logotron_genesis.kv 96 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
logotron_genesis.kv 97 if (DB_DEBUG): print "query: '{0}'".format(query)
logotron_genesis.kv 98 cur.execute(query, args)
logotron_genesis.kv 99 rv = cur.fetchone() if one else cur.fetchall()
logotron_genesis.kv 100 if (DB_DEBUG): print "query res: '{0}'".format(rv)
logotron_genesis.kv 101 return rv
logotron_genesis.kv 102
logotron_genesis.kv 103 def exec_db(query, args=()):
logotron_genesis.kv 104 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
logotron_genesis.kv 105 if (DB_DEBUG): print "query: '{0}'".format(query)
logotron_genesis.kv 106 if (DB_DEBUG): print "args: '{0}'".format(args)
logotron_genesis.kv 107 if (DB_DEBUG): print "EXEC:"
logotron_genesis.kv 108 cur.execute(query, args)
logotron_genesis.kv 109
logotron_genesis.kv 110 def getlast_db():
logotron_genesis.kv 111 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
logotron_genesis.kv 112 cur.execute('select lastval()')
logotron_genesis.kv 113 return cur.fetchone()['lastval']
logotron_genesis.kv 114
logotron_genesis.kv 115 def commit_db():
logotron_genesis.kv 116 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
logotron_genesis.kv 117 g.db.commit()
logotron_genesis.kv 118
logotron_genesis.kv 119
logotron_genesis.kv 120
logotron_genesis.kv 121
logotron_genesis.kv 122 @app.errorhandler(404)
logotron_genesis.kv 123 def page_not_found(error):
logotron_genesis.kv 124 return redirect(url_for('log'))
logotron_genesis.kv 125
logotron_genesis.kv 126
logotron_genesis.kv 127
logotron_genesis.kv 128 html_escape_table = {
logotron_genesis.kv 129 "&": "&",
logotron_genesis.kv 130 '"': """,
logotron_genesis.kv 131 "'": "'",
logotron_genesis.kv 132 ">": ">",
logotron_genesis.kv 133 "<": "<",
logotron_genesis.kv 134 }
logotron_genesis.kv 135
logotron_genesis.kv 136 def html_escape(text):
logotron_genesis.kv 137 return "".join(html_escape_table.get(c,c) for c in text)
logotron_genesis.kv 138
logotron_genesis.kv 139
logotron_genesis.kv 140
logotron_genesis.kv 141
logotron_genesis.kv 142 def get_base():
logotron_genesis.kv 143 if DEBUG:
logotron_genesis.kv 144 return request.host_url
logotron_genesis.kv 145 return Base_URL
logotron_genesis.kv 146
logotron_genesis.kv 147
logotron_genesis.kv 148
logotron_genesis.kv 149 def line_url(l):
logotron_genesis.kv 150 return "{0}log/{1}/{2}#{3}".format(get_base(),
logotron_genesis.kv 151 l['chan'],
logotron_genesis.kv 152 l['t'].strftime(Date_Short_Format),
logotron_genesis.kv 153 l['idx'])
logotron_genesis.kv 154
logotron_genesis.kv 155 def gen_chanlist(selected_chan):
logotron_genesis.kv 156
logotron_genesis.kv 157 now = datetime.now()
logotron_genesis.kv 158
logotron_genesis.kv 159 s = """<table align="center" class="chantable"><tr>"""
logotron_genesis.kv 160 for chan in Channels:
logotron_genesis.kv 161 chan_formed = chan
logotron_genesis.kv 162 if chan == selected_chan:
logotron_genesis.kv 163 chan_formed = "<span class='highlight'>" + chan + "</span>"
logotron_genesis.kv 164 s += """<th><a href="{0}log/{1}">{2}</a></th>""".format(
logotron_genesis.kv 165 get_base(), chan, chan_formed)
logotron_genesis.kv 166 s += "</tr><tr>"
logotron_genesis.kv 167
logotron_genesis.kv 168 for chan in Channels:
logotron_genesis.kv 169
logotron_genesis.kv 170 last_time = query_db(
logotron_genesis.kv 171 '''select t, idx from loglines where chan=%s
logotron_genesis.kv 172 and idx = (select max(idx) from loglines where chan=%s) ;''',
logotron_genesis.kv 173 [chan, chan], one=True)
logotron_genesis.kv 174
logotron_genesis.kv 175 last_time_txt = ""
logotron_genesis.kv 176 if last_time != None:
logotron_genesis.kv 177 span = (now - last_time['t'])
logotron_genesis.kv 178 days = span.days
logotron_genesis.kv 179 hours = span.seconds/3600
logotron_genesis.kv 180 minutes = (span.seconds%3600)/60
logotron_genesis.kv 181
logotron_genesis.kv 182 if days != 0:
logotron_genesis.kv 183 last_time_txt += '%dd ' % days
logotron_genesis.kv 184 if hours != 0:
logotron_genesis.kv 185 last_time_txt += '%dh ' % hours
logotron_genesis.kv 186 if minutes != 0:
logotron_genesis.kv 187 last_time_txt += '%dm' % minutes
logotron_genesis.kv 188
logotron_genesis.kv 189 s += """<td><i><a href="{0}log/{1}/{2}
logotron_genesis.kv 190 get_base(),
logotron_genesis.kv 191 chan,
logotron_genesis.kv 192 last_time['t'].strftime(Date_Short_Format),
logotron_genesis.kv 193 last_time['idx'],
logotron_genesis.kv 194 last_time_txt)
logotron_genesis.kv 195
logotron_genesis.kv 196 else:
logotron_genesis.kv 197 last_time_txt = ""
logotron_genesis.kv 198 s += "<td></td>"
logotron_genesis.kv 199
logotron_genesis.kv 200 s += "</tr></table>"
logotron_genesis.kv 201 return s
logotron_genesis.kv 202
logotron_genesis.kv 203
logotron_genesis.kv 204
logotron_genesis.kv 205 app.jinja_env.globals.update(gen_chanlist=gen_chanlist)
logotron_genesis.kv 206
logotron_genesis.kv 207
logotron_genesis.kv 208
logotron_genesis.kv 209 tag_regex = re.compile("(<[^>]+>)")
logotron_genesis.kv 210
logotron_genesis.kv 211
logotron_genesis.kv 212
logotron_genesis.kv 213 def get_link_intervals(str):
logotron_genesis.kv 214 links = []
logotron_genesis.kv 215 span = []
logotron_genesis.kv 216 for match in tag_regex.finditer(str):
logotron_genesis.kv 217 span = match.span()
logotron_genesis.kv 218 links += [span]
logotron_genesis.kv 219 return links
logotron_genesis.kv 220
logotron_genesis.kv 221
logotron_genesis.kv 222
logotron_genesis.kv 223 def highlight_matches(strings, text):
logotron_genesis.kv 224 e = '(' + ('|'.join(strings)) + ')'
logotron_genesis.kv 225 return re.sub(e,
logotron_genesis.kv 226 r"""<span class='highlight'>\1</span>""",
logotron_genesis.kv 227 text,
logotron_genesis.kv 228 flags=re.I)
logotron_genesis.kv 229
logotron_genesis.kv 230
logotron_genesis.kv 231
logotron_genesis.kv 232
logotron_genesis.kv 233 def highlight_text(strings, text):
logotron_genesis.kv 234 result = ""
logotron_genesis.kv 235 last = 0
logotron_genesis.kv 236 for i in get_link_intervals(text):
logotron_genesis.kv 237 i_start, i_end = i
logotron_genesis.kv 238 result += highlight_matches(strings, text[last:i_start])
logotron_genesis.kv 239 result += text[i_start:i_end]
logotron_genesis.kv 240 last = i_end
logotron_genesis.kv 241 result += highlight_matches(strings, text[last:])
logotron_genesis.kv 242 return result
logotron_genesis.kv 243
logotron_genesis.kv 244
logotron_genesis.kv 245
uniturds_etc.kv 246 boxlinks_re = re.compile(
uniturds_etc.kv 247 '\[\s*<a href="(http[^ \[\]]+)"[^>]*>[^ <]+</a>\s*\]\[([^\[\]]+)\]')
uniturds_etc.kv 248
logotron_genesis.kv 249 stdlinks_re = re.compile('(http[^ \[\]]+)')
logotron_genesis.kv 250
logotron_genesis.kv 251
logotron_genesis.kv 252
multsel_and_datef... 253 def format_logline(l, highlights = [], select=[]):
logotron_genesis.kv 254 payload = html_escape(l['payload'])
logotron_genesis.kv 255
logotron_genesis.kv 256
uniturds_etc.kv 257 payload = re.sub(stdlinks_re,
uniturds_etc.kv 258 r'<a href="\1" target=\'_blank\'>\1</a>', payload)
logotron_genesis.kv 259
logotron_genesis.kv 260
uniturds_etc.kv 261 payload = re.sub(boxlinks_re,
uniturds_etc.kv 262 r'<a href="\1" target=\'_blank\'>\2</a>', payload)
logotron_genesis.kv 263
logotron_genesis.kv 264
logotron_genesis.kv 265 if highlights != []:
logotron_genesis.kv 266 payload = highlight_text(highlights, payload)
logotron_genesis.kv 267
logotron_genesis.kv 268 bot = ""
logotron_genesis.kv 269 if l['speaker'] in Bots:
logotron_genesis.kv 270 bot = " bot"
logotron_genesis.kv 271
multsel_and_datef... 272
multsel_and_datef... 273 dclass = l['speaker']
multsel_and_datef... 274
multsel_and_datef... 275
multsel_and_datef... 276 if select != []:
multsel_and_datef... 277 ss, se = select
multsel_and_datef... 278 if ss <= l['idx'] <= se:
multsel_and_datef... 279 dclass = "highlight"
multsel_and_datef... 280
logotron_genesis.kv 281
multsel_and_datef... 282 s = ("<div id='{0}' class='{6}{5}'>"
logotron_genesis.kv 283 "<a class='nick' title='{2}'"
logotron_genesis.kv 284 " href=\"{3}\">{1}</a>: {4}</div>").format(l['idx'],
logotron_genesis.kv 285 l['speaker'],
logotron_genesis.kv 286 l['t'],
logotron_genesis.kv 287 line_url(l),
logotron_genesis.kv 288 payload,
multsel_and_datef... 289 bot,
multsel_and_datef... 290 dclass)
logotron_genesis.kv 291 return s
logotron_genesis.kv 292
logotron_genesis.kv 293
logotron_genesis.kv 294 app.jinja_env.globals.update(format_logline=format_logline)
logotron_genesis.kv 295
logotron_genesis.kv 296
logotron_genesis.kv 297
logotron_genesis.kv 298 def generate_navbar(date, tail, chan):
logotron_genesis.kv 299 cur_day = datetime.strptime(date, Date_Short_Format)
logotron_genesis.kv 300 prev_day = cur_day - timedelta(days=1)
logotron_genesis.kv 301 prev_day_txt = prev_day.strftime(Date_Short_Format)
logotron_genesis.kv 302
logotron_genesis.kv 303 s = "<a href='{0}log/{1}/{2}'>← {2}</a>".format(
logotron_genesis.kv 304 get_base(),
logotron_genesis.kv 305 chan,
logotron_genesis.kv 306 prev_day_txt)
logotron_genesis.kv 307
logotron_genesis.kv 308 if not tail:
logotron_genesis.kv 309 next_day = cur_day + timedelta(days=1)
logotron_genesis.kv 310 next_day_txt = next_day.strftime(Date_Short_Format)
logotron_genesis.kv 311 s = s + " | <a href='{0}log/{1}/{2}'>{2} →</a>".format(
logotron_genesis.kv 312 get_base(),
logotron_genesis.kv 313 chan,
logotron_genesis.kv 314 next_day_txt)
logotron_genesis.kv 315
uniturds_etc.kv 316
uniturds_etc.kv 317
uniturds_etc.kv 318
logotron_genesis.kv 319 return s
logotron_genesis.kv 320
logotron_genesis.kv 321
logotron_genesis.kv 322 app.jinja_env.globals.update(generate_navbar=generate_navbar)
logotron_genesis.kv 323
logotron_genesis.kv 324
uniturds_etc.kv 325 @app.route('/rnd/<chan>')
uniturds_etc.kv 326 def rnd(chan):
uniturds_etc.kv 327
uniturds_etc.kv 328 if chan not in Channels:
uniturds_etc.kv 329 return redirect(url_for('log'))
uniturds_etc.kv 330
uniturds_etc.kv 331 rnd_line = query_db(
uniturds_etc.kv 332 '''select * from loglines where chan=%s
uniturds_etc.kv 333 order by random() limit 1 ;''',
uniturds_etc.kv 334 [chan], one=True)
uniturds_etc.kv 335
uniturds_etc.kv 336 return redirect(line_url(rnd_line))
uniturds_etc.kv 337
uniturds_etc.kv 338
logotron_genesis.kv 339 @app.route('/log/<chan>/<date>')
logotron_genesis.kv 340 @app.route('/log/<chan>', defaults={'date': None})
logotron_genesis.kv 341 @app.route('/log/', defaults={'chan': Default_Chan, 'date': None})
logotron_genesis.kv 342 @app.route('/log', defaults={'chan': Default_Chan, 'date': None})
logotron_genesis.kv 343 def log(chan, date):
logotron_genesis.kv 344
logotron_genesis.kv 345 if chan not in Channels:
logotron_genesis.kv 346 return redirect(url_for('log'))
logotron_genesis.kv 347
multsel_and_datef... 348
multsel_and_datef... 349 sel_start = request.args.get('ss', default = 0, type = int)
multsel_and_datef... 350 sel_end = request.args.get('se', default = 0, type = int)
uniturds_etc.kv 351
uniturds_etc.kv 352
uniturds_etc.kv 353 rev = request.args.get('rev', default = 0, type = int)
multsel_and_datef... 354
logotron_genesis.kv 355
logotron_genesis.kv 356 now = datetime.now()
logotron_genesis.kv 357
logotron_genesis.kv 358
logotron_genesis.kv 359 tail = False
logotron_genesis.kv 360
logotron_genesis.kv 361
logotron_genesis.kv 362 if date == None:
logotron_genesis.kv 363 date = now.strftime(Date_Short_Format)
logotron_genesis.kv 364 tail = True
logotron_genesis.kv 365
logotron_genesis.kv 366
logotron_genesis.kv 367 try:
logotron_genesis.kv 368 day_start = datetime.strptime(date, Date_Short_Format)
logotron_genesis.kv 369 except Exception, e:
logotron_genesis.kv 370 return redirect(url_for('log'))
logotron_genesis.kv 371
logotron_genesis.kv 372
logotron_genesis.kv 373 day_end = day_start + timedelta(days=1)
logotron_genesis.kv 374
multsel_and_datef... 375
rle_errata.kv 376 if day_end > now:
multsel_and_datef... 377 tail = True
multsel_and_datef... 378
logotron_genesis.kv 379
logotron_genesis.kv 380 lines = query_db(
logotron_genesis.kv 381 '''select * from loglines where chan=%s
logotron_genesis.kv 382 and t between %s and %s order by idx asc;''',
logotron_genesis.kv 383 [chan, day_start, day_end], one=False)
logotron_genesis.kv 384
uniturds_etc.kv 385
uniturds_etc.kv 386 if rev == 1:
uniturds_etc.kv 387 lines.reverse()
uniturds_etc.kv 388
logotron_genesis.kv 389
logotron_genesis.kv 390 return render_template('log.html',
logotron_genesis.kv 391 chan = chan,
logotron_genesis.kv 392 loglines = lines,
multsel_and_datef... 393 sel = (sel_start, sel_end),
logotron_genesis.kv 394 date = date,
uniturds_etc.kv 395 tail = tail,
uniturds_etc.kv 396 rev = not rev)
logotron_genesis.kv 397
logotron_genesis.kv 398
raw_line_export.kv 399 @app.route('/log-raw/<chan>')
raw_line_export.kv 400 def rawlog(chan):
raw_line_export.kv 401 res = ""
raw_line_export.kv 402
raw_line_export.kv 403
raw_line_export.kv 404 if chan not in Channels:
raw_line_export.kv 405 return Response("EGGOG: No such Channel!", mimetype='text/plain')
raw_line_export.kv 406
raw_line_export.kv 407
raw_line_export.kv 408 idx_start = request.args.get('istart', default = 0, type = int)
raw_line_export.kv 409 idx_end = request.args.get('iend', default = 0, type = int)
raw_line_export.kv 410
raw_line_export.kv 411
raw_line_export.kv 412 if idx_start > idx_end:
raw_line_export.kv 413 return Response("EGGOG: Start must precede End!",
raw_line_export.kv 414 mimetype='text/plain')
raw_line_export.kv 415
raw_line_export.kv 416
raw_line_export.kv 417 if (idx_end - idx_start) > Max_Raw_Ln :
raw_line_export.kv 418 return Response("EGGOG: May request Max. of %s Lines !" % Max_Raw_Ln,
raw_line_export.kv 419 mimetype='text/plain')
raw_line_export.kv 420
raw_line_export.kv 421
raw_line_export.kv 422 lines = query_db(
raw_line_export.kv 423 '''select * from loglines where chan=%s
raw_line_export.kv 424 and idx between %s and %s order by idx asc;''',
raw_line_export.kv 425 [chan, idx_start, idx_end], one=False)
raw_line_export.kv 426
raw_line_export.kv 427
raw_line_export.kv 428 for l in lines:
raw_line_export.kv 429 action = ""
raw_line_export.kv 430 if l['self']:
raw_line_export.kv 431 action = "*;"
raw_line_export.kv 432 res += "%s;%s;%s%s;%s\n" % (l['idx'],
raw_line_export.kv 433 l['t'].strftime('%s'),
raw_line_export.kv 434 action,
raw_line_export.kv 435 l['speaker'],
raw_line_export.kv 436 l['payload'])
raw_line_export.kv 437
raw_line_export.kv 438
raw_line_export.kv 439 return Response(res, mimetype='text/plain')
raw_line_export.kv 440
logotron_genesis.kv 441
logotron_genesis.kv 442 Name_Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"
logotron_genesis.kv 443
logotron_genesis.kv 444 def sanitize_speaker(s):
logotron_genesis.kv 445 return "".join([ch for ch in s if ch in Name_Chars])
logotron_genesis.kv 446
logotron_genesis.kv 447
logotron_genesis.kv 448 def re_escape(s):
logotron_genesis.kv 449 return re.sub(r"[(){}\[\].*?|^$\\+-]", r"\\\g<0>", s)
logotron_genesis.kv 450
logotron_genesis.kv 451
logotron_genesis.kv 452 @app.route('/log-search')
logotron_genesis.kv 453 def logsearch():
logotron_genesis.kv 454
logotron_genesis.kv 455 chan = request.args.get('chan', default = Default_Chan, type = str)
logotron_genesis.kv 456 query = request.args.get('q', default = '', type = str)
logotron_genesis.kv 457
logotron_genesis.kv 458
logotron_genesis.kv 459
logotron_genesis.kv 460 if chan not in Channels:
logotron_genesis.kv 461 return redirect(url_for('log'))
logotron_genesis.kv 462
logotron_genesis.kv 463 nres = 0
logotron_genesis.kv 464 searchres = []
logotron_genesis.kv 465 tokens_orig = []
logotron_genesis.kv 466 search_head = "Query is too short!"
logotron_genesis.kv 467
logotron_genesis.kv 468 if len(query) >= Min_Query_Length:
logotron_genesis.kv 469
logotron_genesis.kv 470 tokens = query.split()
logotron_genesis.kv 471 tokens_standard = []
logotron_genesis.kv 472 from_users = []
logotron_genesis.kv 473
logotron_genesis.kv 474
logotron_genesis.kv 475 for t in tokens:
logotron_genesis.kv 476 if t.startswith("from:") or t.startswith("f:"):
logotron_genesis.kv 477 from_users.append(t.split(':')[1])
logotron_genesis.kv 478 else:
logotron_genesis.kv 479 tokens_standard.append(t)
logotron_genesis.kv 480
logotron_genesis.kv 481 from_users = ['%' + sanitize_speaker(t) + '%' for t in from_users]
logotron_genesis.kv 482 tokens_orig = [re_escape(t) for t in tokens_standard]
logotron_genesis.kv 483 tokens_formed = ['%' + t + '%' for t in tokens_orig]
logotron_genesis.kv 484
logotron_genesis.kv 485
logotron_genesis.kv 486 if from_users == []:
logotron_genesis.kv 487 searchres = query_db(
logotron_genesis.kv 488 '''select * from loglines where chan=%s
logotron_genesis.kv 489 and payload ilike all(%s) order by idx desc limit %s;''',
logotron_genesis.kv 490 [chan,
logotron_genesis.kv 491 tokens_formed,
logotron_genesis.kv 492 Max_Search_Results], one=False)
logotron_genesis.kv 493 else:
logotron_genesis.kv 494 searchres = query_db(
logotron_genesis.kv 495 '''select * from loglines where chan=%s
logotron_genesis.kv 496 and speaker ilike any(%s)
logotron_genesis.kv 497 and payload ilike all(%s) order by idx desc limit %s;''',
logotron_genesis.kv 498 [chan,
logotron_genesis.kv 499 from_users,
logotron_genesis.kv 500 tokens_formed,
logotron_genesis.kv 501 Max_Search_Results], one=False)
logotron_genesis.kv 502
logotron_genesis.kv 503
logotron_genesis.kv 504
logotron_genesis.kv 505 nres = len(searchres)
logotron_genesis.kv 506 search_head = "<b>{0}</b> entries found in {1} for <b>'{2}'</b> :".format(
logotron_genesis.kv 507 nres, chan, html_escape(query))
logotron_genesis.kv 508
logotron_genesis.kv 509
logotron_genesis.kv 510 return render_template('searchres.html',
logotron_genesis.kv 511 query = query,
logotron_genesis.kv 512 nres = nres,
logotron_genesis.kv 513 chan = chan,
logotron_genesis.kv 514 search_head = search_head,
logotron_genesis.kv 515 tokens = tokens_orig,
logotron_genesis.kv 516 loglines = searchres)
logotron_genesis.kv 517
logotron_genesis.kv 518
logotron_genesis.kv 519
logotron_genesis.kv 520 @app.route('/favicon.ico')
logotron_genesis.kv 521 def favicon():
logotron_genesis.kv 522 return redirect(url_for('static', filename='favicon.ico'))
logotron_genesis.kv 523
logotron_genesis.kv 524
logotron_genesis.kv 525
logotron_genesis.kv 526 if __name__ == '__main__':
logotron_genesis.kv 527 app.run(threaded=True, port=WWW_Port)