- 3B5645290A520A3F935B44372A1C98F60A0BC967EA3D6AD4160EF72E455C7C9636847847007334053703765FA80176A2509E3609005E4AB8D2518D27869F8002
+ A56AF711977A55E1332E0A42D8E2ACFDFB7C2D9DB72DC86C276949C337F0E66ACBE6455B19CB156FABB1B242BC7C7F8A69E48987F20D745BCBF44E60D52E9B46
logotron/reader.py
(306 . 31)(306 . 6)
28 app.jinja_env.globals.update(format_logline=format_logline)
29
30
31 # Generate navbar for the given date:
32 def generate_navbar(date, tail, chan):
33 cur_day = datetime.strptime(date, Date_Short_Format)
34 prev_day = cur_day - timedelta(days=1)
35 prev_day_txt = prev_day.strftime(Date_Short_Format)
36
37 s = "<a href='{0}log/{1}/{2}'>← {2}</a>".format(
38 get_base(),
39 chan,
40 prev_day_txt)
41
42 if not tail:
43 next_day = cur_day + timedelta(days=1)
44 next_day_txt = next_day.strftime(Date_Short_Format)
45 s = s + " | <a href='{0}log/{1}/{2}'>{2} →</a>".format(
46 get_base(),
47 chan,
48 next_day_txt)
49
50 return s
51
52 # Make above callable from inside htm templater:
53 app.jinja_env.globals.update(generate_navbar=generate_navbar)
54
55
56 @app.route('/rnd/<chan>')
57 def rnd(chan):
58 # Handle rubbish chan:
(387 . 7)(362 . 7)
60 # Enable 'tail' is day_end is after end of current day
61 if day_end > now:
62 tail = True
63
64
65 # Get the loglines from DB
66 lines = query_db(
67 '''select * from loglines where chan=%s
(397 . 14)(372 . 36)
69 # Optional 'reverse gear' knob:
70 if rev == 1:
71 lines.reverse()
72
73
74 # Generate navbar for the given date:
75 prev_day = ""
76 next_day = ""
77
78 prev_t = query_db(
79 '''select t from loglines where chan=%s
80 and t < %s order by idx desc limit 1;''',
81 [chan, day_start], one=True)
82
83 if prev_t != None:
84 prev_day = prev_t['t'].strftime(Date_Short_Format)
85
86 if not tail:
87 next_t = query_db(
88 '''select t from loglines where chan=%s
89 and t > %s order by idx asc limit 1;''',
90 [chan, day_end], one=True)
91
92 if next_t != None:
93 next_day = next_t['t'].strftime(Date_Short_Format)
94
95 # Return the HTMLized text
96 return render_template('log.html',
97 chan = chan,
98 loglines = lines,
99 sel = (sel_start, sel_end),
100 date = date,
101 tail = tail,
102 prev_day = prev_day,
103 next_day = next_day,
104 rev = not rev,
105 show_all = show_all,
106 idle_day = Days_Hide)