X-Git-Url: http://git.sourceforge.jp/view?p=fukui-no-namari%2Ffukui-no-namari.git;a=blobdiff_plain;f=src%2FHage1%2Fmisc.py;h=536f089506e559cc60e1edb78cda33231d25fe12;hp=9fc98bc3da03b3fc183cd778ed8c1483cfd48815;hb=8acb0434a170be0ffbd8ebd93538933c4006dfde;hpb=df8973c4acdd0d781a6690ebd8cf643e69bf4244 diff --git a/src/Hage1/misc.py b/src/Hage1/misc.py index 9fc98bc..536f089 100644 --- a/src/Hage1/misc.py +++ b/src/Hage1/misc.py @@ -16,10 +16,17 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os.path +import re +import time import config import brdlist +REG_EXPR_HTTPDATE = re.compile("((?:Mon)|(?:Tue)|(?:Wed)|(?:Thu)|(?:Fri)|(?:Sat)|(?:Sun)), (\d{2}) ((?:Jan)|(?:Feb)|(?:Mar)|(?:Apr)|(?:May)|(?:Jun)|(?:Jul)|(?:Aug)|(?:Sep)|(?:Oct)|(?:Nov)|(?:Dec)) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT") +WDAY_DICT = {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} +MON_DICT = {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7, + "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12} + def get_logs_dir_path(): return os.path.join(config.get_config_dir_path(), "logs") @@ -34,6 +41,31 @@ def get_board_base_url(bbs, board): return "http://" + brdlist.get(bbs, board, "host") + "/" + board + "/" +def get_thread_dat_url(bbs, board, thread): + """Returns thread dat url""" + + # if parameter is empty, raise ValueError + if not bbs or not board or not thread: + raise ValueError, "parameter must not be empty" + + return get_board_base_url(bbs, board) + "dat/" + thread + ".dat" + +def get_thread_dat_path(bbs, board, thread): + """Returns thread dat file path + + bbs: bbs id + + board: board id + + thread: thread id + """ + + # if parameter is empty, raise ValueError + if not bbs or not board or not thread: + raise ValueError, "parameter must not be empty" + + return os.path.join(get_board_dir_path(bbs, board), thread + ".dat") + def get_board_subjecttxt_url(bbs, board): """Returns subject.txt file url @@ -62,6 +94,20 @@ def get_board_subjecttxt_path(bbs, board): return os.path.join(get_logs_dir_path(), bbs, board, "subject.txt") +def get_board_idx_path(bbs, board): + """Returns board idx file path + + bbs: bbs id + + board: board id + """ + + # if parameter is empty, raise ValueError + if not bbs or not board: + raise ValueError, "parameter must not be empty" + + return os.path.join(get_logs_dir_path(), bbs, board, "subject.idx") + def get_board_dir_path(bbs, board): """Returns board dir path @@ -109,3 +155,22 @@ def get_board_cache_path(bbs, board): raise ValueError, "parameter must not be empty" return os.path.join(get_logs_dir_path(), bbs, board, ".cache") + +def httpdate_to_secs(httpdate): + """Returns the seconds since the epoch""" + + m = REG_EXPR_HTTPDATE.match(httpdate) + if m: + tm_wday = WDAY_DICT[m.group(1)] + tm_mday = int(m.group(2)) + tm_mon = MON_DICT[m.group(3)] + tm_year = int(m.group(4)) + tm_hour = int(m.group(5)) + tm_min = int(m.group(6)) + tm_sec = int(m.group(7)) + + return int(time.mktime( + (tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,0,-1)) \ + - time.timezone) + else: + raise ValueError