- A56AF711977A55E1332E0A42D8E2ACFDFB7C2D9DB72DC86C276949C337F0E66ACBE6455B19CB156FABB1B242BC7C7F8A69E48987F20D745BCBF44E60D52E9B46
+ C9984744C90B16EDBB46D64DE35F29247076166350A48239295A72270097CB3FD557B38D252B458174361022324D7A0C0714AABC70E68AA375924F62F19497EC
logotron/reader.py
(55 . 6)(55 . 7)
65 Days_Hide = int(cfg.get("logotron", "days_hide"))
66 # WWW:
67 WWW_Port = int(cfg.get("logotron", "www_port"))
68 Max_Search_Results = int(cfg.get("logotron", "max_search"))
69
70 except Exception as e:
71 print "Invalid config: ", e
(66 . 7)(67 . 6)
73 ### Knobs not made into config yet ###
74 Default_Chan = Channels[0]
75 Min_Query_Length = 3
76 Max_Search_Results = 1000
77
78 ## Format for Date in Log Lines
79 Date_Short_Format = "%Y-%m-%d"
(247 . 6)(247 . 12)
81
82 stdlinks_re = re.compile('(http[^ \[\]]+)')
83
84 # For era 1 ('bitcoin-assets') links :
85 era1_re = re.compile('(<a href="http[^ \[\]]\/\/log\d*\.bitcoin-assets\.com\/\?date=\d+-\d+-\d+#)(\d+)')
86
87 # For era 2 ('btcbase') links :
88 era2_re = re.compile('(<a href="http[^ \[\]]\/\/btcbase\.org\/log\/\d+-\d+-\d+#)(\d+)')
89
90
91 ## Format given log line for display
92 def format_logline(l, highlights = [], select=[], showchan=False):
(259 . 7)(265 . 18)
94 # Now also format [link][text] links :
95 payload = re.sub(boxlinks_re,
96 r'<a href="\1" target=\'_blank\'>\2</a>', payload)
97
98
99 # For ancient logs strictly: substitute orig. link with our logger :
100 if l['era'] < 3:
101 payload = re.sub(era1_re,
102 r'<a href="/ilog/{0}/\2'.format(l['chan']),
103 payload)
104
105 # Adjust era 2 links in all cases:
106 payload = re.sub(era2_re,
107 r'<a href="/ilog/{0}/\2'.format(l['chan']),
108 payload)
109
110 # If this is a search result, illuminate the matched strings:
111 if highlights != []:
112 payload = highlight_text(highlights, payload)
(407 . 6)(424 . 30)
114 idle_day = Days_Hide)
115
116
117 # Primarily for use with 'era 1' and 'era 2' :
118 # Get arbitrary log item by chan and raw line index
119 @app.route('/ilog/<chan>/<idx>')
120 def ilog(chan, idx):
121 # Handle rubbish chan:
122 if chan not in Channels:
123 return redirect(url_for('log'))
124
125 # Attempt to locate given chan/idx:
126 item = query_db(
127 '''select * from loglines where chan=%s and idx = %s ;''',
128 [chan, idx], one=True)
129
130 # If given chan/idx not found:
131 if item == None:
132 return redirect(url_for('log'))
133
134 # Determine date where item appears in log :
135 item_date = item['t'].strftime(Date_Short_Format)
136
137 # Go there:
138 return redirect("/log/" + chan + "/" + item_date + "#" + idx)
139
140
141 @app.route('/log-raw/<chan>')
142 def rawlog(chan):
143 res = ""
(467 . 8)(508 . 8)
145 # The query params:
146 chan = request.args.get('chan', default = Default_Chan, type = str)
147 query = request.args.get('q', default = '', type = str)
148 # page_num = request.args.get('page', default = 0, type = int)
149
150 offset = request.args.get('after', default = 0, type = int)
151
152 # channels to search in
153 chans = []
154
(515 . 32)(556 . 50)
156 if from_users == []:
157 searchres = query_db(
158 '''select * from loglines where chan = any(%s)
159 and payload ilike all(%s) order by t desc limit %s;''',
160 and payload ilike all(%s) order by t desc
161 limit %s offset %s;''',
162 [(chans,),
163 tokens_formed,
164 Max_Search_Results], one=False)
165 Max_Search_Results,
166 offset], one=False)
167 else:
168 searchres = query_db(
169 '''select * from loglines where chan = any(%s)
170 and speaker ilike any(%s)
171 and payload ilike all(%s) order by t desc limit %s;''',
172 and payload ilike all(%s) order by t desc
173 limit %s offset %s;''',
174 [(chans,),
175 from_users,
176 tokens_formed,
177 Max_Search_Results], one=False)
178
179
180 # Number of entries found
181 Max_Search_Results,
182 offset], one=False)
183
184 # Number of search results returned in this query
185 nres = len(searchres)
186 search_head = "<b>{0}</b> entries found in {1} for <b>'{2}'</b> :".format(
187 nres, legend, html_escape(query))
188
189
190 # Whether to display 'back' button :
191 back = (offset != 0)
192
193 # Whether to display 'forward' button :
194 forw = (nres == Max_Search_Results)
195
196 # Starting index of search results
197 sres = offset
198
199 # Ending index of search results
200 eres = offset + min(nres, Max_Search_Results)
201
202 # No paging support just yet:
203 return render_template('searchres.html',
204 query = query,
205 nres = nres,
206 hquery = html_escape(query),
207 legend = legend,
208 sres = sres,
209 eres = eres,
210 back = back,
211 forw = forw,
212 psize = Max_Search_Results,
213 chan = chan,
214 search_head = search_head,
215 tokens = tokens_orig,
216 loglines = searchres,
217 showchan = showchan)