equal
deleted
inserted
replaced
1 """ |
1 """ |
2 A source of IRC log files |
2 A source of IRC log files |
3 """ |
3 """ |
4 |
4 |
5 import datetime, calendar, itertools, functools |
5 import datetime, calendar, itertools, functools, math |
6 import os, errno |
6 import os, errno |
7 import pytz |
7 import pytz |
8 |
8 |
9 class LogSource (object) : |
9 class LogSource (object) : |
10 """ |
10 """ |
40 skip = (page - 1) * count |
40 skip = (page - 1) * count |
41 |
41 |
42 else : |
42 else : |
43 skip = None |
43 skip = None |
44 |
44 |
|
45 # count the full number of lines |
|
46 line_count = 0 |
|
47 |
45 # collect lines |
48 # collect lines |
46 lines = [] |
49 lines = [] |
47 |
50 |
48 # iterate using get_date |
51 # iterate using get_date |
49 for line in self.get_date(dt) : |
52 for line in self.get_date(dt) : |
|
53 # count them |
|
54 line_count += 1 |
|
55 |
50 # skip? |
56 # skip? |
51 if skip : |
57 if skip : |
52 skip -= 1 |
58 skip -= 1 |
53 continue |
59 continue |
54 |
60 |
|
61 # already full? |
|
62 if len(lines) > count : |
|
63 continue |
|
64 |
55 # store line |
65 # store line |
56 lines.append(line) |
66 lines.append(line) |
57 |
67 |
58 # count? |
68 # calculate max_pages |
59 if len(lines) >= count : |
69 max_pages = math.ceil(float(line_count) / count) |
60 break |
70 |
61 |
71 # return |
62 return (page, 0, lines) |
72 return (page, max_pages, lines) |
63 |
73 |
64 def get_month_days (self, dt) : |
74 def get_month_days (self, dt) : |
65 """ |
75 """ |
66 Get a set of dates, telling which days in the given month (as a datetime) have logs available |
76 Get a set of dates, telling which days in the given month (as a datetime) have logs available |
67 """ |
77 """ |