From ac728fffb21c3425e80d8618477db7c3ae676ece Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 29 Jul 2010 19:59:45 +0800 Subject: [PATCH] FTP and Timezone fix. Error reported with the following hand hostory from FTP France: Full Tilt Poker.fr Game #22632637058: Daily Euro (174599326), Table 3 - 10/20 - No Limit Hold'em - 20:15:39 CET - 2010/07/27 The existing FTP parser crashed on CET times. 1) Fixed parser to accept CET 2) Added timezone offset into HHC Not happy with TZ1/TZ2 solution. --- pyfpdb/FulltiltToFpdb.py | 19 ++++++++++++------- pyfpdb/HandHistoryConverter.py | 14 +++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index be566ef7..cfeb7de1 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -54,7 +54,7 @@ class Fulltilt(HandHistoryConverter): \$?(?P[.0-9]+)/\$?(?P[.0-9]+)\s(Ante\s\$?(?P[.0-9]+)\s)?-\s \$?(?P[.0-9]+\sCap\s)? (?P[a-zA-Z\/\'\s]+)\s-\s - (?P\d+:\d+:\d+\s\w+\s-\s\d+/\d+/\d+|\d+:\d+\s\w+\s-\s\w+\,\s\w+\s\d+\,\s\d+) + (?P\d+:\d+:\d+\s(?P\w+)\s-\s\d+/\d+/\d+|\d+:\d+\s(?P\w+)\s-\s\w+\,\s\w+\s\d+\,\s\d+) (?P\(partial\))?\n (?:.*?\n(?PHand\s\#(?P=HID)\shas\sbeen\scanceled))? ''', re.VERBOSE|re.DOTALL) @@ -201,13 +201,18 @@ class Fulltilt(HandHistoryConverter): return None hand.handid = m.group('HID') hand.tablename = m.group('TABLE') - - try: - hand.startTime = datetime.datetime.strptime(m.group('DATETIME'), "%H:%M:%S ET - %Y/%m/%d") - except: - hand.startTime = datetime.datetime.strptime(m.group('DATETIME'), "%H:%M ET - %a, %B %d, %Y") - hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "ET", "UTC") + timezone = "ET" + if m.group('TZ1') == "CET" or m.group('TZ2') == "CET": + timezone = "CET" + try: + stringformat = "%H:%M:%S " + m.group('TZ1') + " - %Y/%m/%d" + hand.startTime = datetime.datetime.strptime(m.group('DATETIME'), stringformat) + except: + stringformat = "%H:%M " + m.group('TZ2') + " - %a, %B %d, %Y" + hand.startTime = datetime.datetime.strptime(m.group('DATETIME'), stringformat) + + hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, timezone, "UTC") if m.group("CANCELLED") or m.group("PARTIAL"): raise FpdbParseError(hid=m.group('HID')) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 4554c2e8..bfd71640 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -497,19 +497,23 @@ or None if we fail to get the info """ @staticmethod def changeTimezone(time, givenTimezone, wantedTimezone): + offest = datetime.timedelta(hours=0) if givenTimezone=="ET" and wantedTimezone=="UTC": # approximate rules for ET daylight savings time: if ( time.month == 12 # all of Dec or (time.month == 11 and time.day > 4) # and most of November or time.month < 3 # and all of Jan/Feb or (time.month == 3 and time.day < 11) ): # and 1st 10 days of March - offset = datetime.timedelta(hours=5) # are EST: assume 5 hour offset (ET without daylight saving) + offset = datetime.timedelta(hours=5) # are EST: assume 5 hour offset (ET without daylight saving) else: - offset = datetime.timedelta(hours=4) # rest is EDT: assume 4 hour offset (ET with daylight saving) - # adjust time into UTC: - time = time + offset + offset = datetime.timedelta(hours=4) # rest is EDT: assume 4 hour offset (ET with daylight saving) #print " tz = %s start = %s" % (tz, str(hand.starttime)) - return time + elif givenTimezone=="CET" and wantedTimezone=="UTC": + offset = datetime.timedelta(hours=1) + + # adjust time into UTC: + time = time + offset + return time #end @staticmethod def changeTimezone @staticmethod