- 8AC522F24E0ADD9BA37C81161EDBB0BA5FE70DF54C03E73FC8A6A60BAC3BF993D1530088C5A3A8A7CAA90DB67EE6B3CDAE75A15B4C6D698ED3D95AFF12E54626
+ 3B5645290A520A3F935B44372A1C98F60A0BC967EA3D6AD4160EF72E455C7C9636847847007334053703765FA80176A2509E3609005E4AB8D2518D27869F8002
logotron/reader.py
(101 . 22)(101 . 6)
47 if (DB_DEBUG): print "query res: '{0}'".format(rv)
48 return rv
49
50 def exec_db(query, args=()):
51 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
52 if (DB_DEBUG): print "query: '{0}'".format(query)
53 if (DB_DEBUG): print "args: '{0}'".format(args)
54 if (DB_DEBUG): print "EXEC:"
55 cur.execute(query, args)
56
57 def getlast_db():
58 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
59 cur.execute('select lastval()')
60 return cur.fetchone()['lastval']
61
62 def commit_db():
63 cur = get_db().cursor(cursor_factory=psycopg2.extras.RealDictCursor)
64 g.db.commit()
65
66 ##############################################################################
67
68 ## All eggogs redirect to main page
(212 . 7)(196 . 7)
70 if chan_tbl[chan]['show']:
71 s += """<td>{0}</td>""".format(chan_tbl[chan]['time'])
72 # wrap up:
73 s += "</tr>"
74 s += "</tr></table>"
75 return s
76
77
(265 . 7)(249 . 7)
79
80
81 ## Format given log line for display
82 def format_logline(l, highlights = [], select=[]):
83 def format_logline(l, highlights = [], select=[], showchan=False):
84 payload = html_escape(l['payload'])
85
86 # Format ordinary links:
(296 . 6)(280 . 9)
88 speaker = l['speaker']
89 separator = ":"
90
91 if showchan:
92 speaker = '<small>(' + l['chan'] + ')</small> ' + speaker
93
94 # If 'action', annotate:
95 if l['self']:
96 separator = ""
(485 . 10)(472 . 26)
98 query = request.args.get('q', default = '', type = str)
99 # page_num = request.args.get('page', default = 0, type = int)
100
101 # Handle rubbish chan:
102 if chan not in Channels:
103 return redirect(url_for('log'))
104 # channels to search in
105 chans = []
106
107 # whether to indicate chan per log line
108 showchan = False
109
110 if chan == 'all':
111 # search in all logged channels
112 chans = Channels
113 legend = "<i>all logged channels</i>"
114 showchan = True
115 else:
116 # Handle possible rubbish chan:
117 if chan not in Channels:
118 return redirect(url_for('log'))
119 else:
120 # search in selected channel only
121 chans = [chan]
122 legend = chan
123
124 nres = 0
125 searchres = []
126 tokens_orig = []
(514 . 17)(517 . 17)
128 # Query is usable; perform the search on DB and get the finds
129 if from_users == []:
130 searchres = query_db(
131 '''select * from loglines where chan=%s
132 and payload ilike all(%s) order by idx desc limit %s;''',
133 [chan,
134 '''select * from loglines where chan = any(%s)
135 and payload ilike all(%s) order by t desc limit %s;''',
136 [(chans,),
137 tokens_formed,
138 Max_Search_Results], one=False)
139 else:
140 searchres = query_db(
141 '''select * from loglines where chan=%s
142 '''select * from loglines where chan = any(%s)
143 and speaker ilike any(%s)
144 and payload ilike all(%s) order by idx desc limit %s;''',
145 [chan,
146 and payload ilike all(%s) order by t desc limit %s;''',
147 [(chans,),
148 from_users,
149 tokens_formed,
150 Max_Search_Results], one=False)
(533 . 7)(536 . 7)
152 # Number of entries found
153 nres = len(searchres)
154 search_head = "<b>{0}</b> entries found in {1} for <b>'{2}'</b> :".format(
155 nres, chan, html_escape(query))
156 nres, legend, html_escape(query))
157
158 # No paging support just yet:
159 return render_template('searchres.html',
(542 . 8)(545 . 8)
161 chan = chan,
162 search_head = search_head,
163 tokens = tokens_orig,
164 loglines = searchres)
165
166 loglines = searchres,
167 showchan = showchan)
168
169 # Comment this out if you don't have one
170 @app.route('/favicon.ico')