From 683f6cee2028ee953650cfd1618a399ffa706273 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 21 Aug 2010 13:44:01 +0100 Subject: [PATCH] get OnGame parser working --- pyfpdb/HandHistoryConverter.py | 23 ++++++++++++++--------- pyfpdb/OnGameToFpdb.py | 8 +++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 7169b668..7ec5327c 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -150,6 +150,7 @@ Otherwise, finish at EOF. log.debug(handText) else: handsList = self.allHandsAsList() + log.debug( _("handsList is ") + str(handsList) ) log.info("Parsing %d hands" % len(handsList)) # Determine if we're dealing with a HH file or a Summary file # quick fix : empty files make the handsList[0] fail ==> If empty file, go on with HH parsing @@ -571,17 +572,21 @@ or None if we fail to get the info """ @staticmethod def changeTimezone(time, givenTimezone, wantedTimezone): - #print "raw time:",time, "given TZ:", givenTimezone + log.debug( _("raw time:")+str(time) + _(" given TZ:")+str(givenTimezone) ) if wantedTimezone=="UTC": wantedTimezone = pytz.utc else: raise Error #TODO raise appropriate error - + + givenTZ = None + if givenTimezone=="ET": - givenTimezone = timezone('US/Eastern') + givenTZ = timezone('US/Eastern') elif givenTimezone=="CET": - givenTimezone = timezone('Europe/Berlin') + givenTZ = timezone('Europe/Berlin') #Note: Daylight Saving Time is standardised across the EU so this should be fine + elif givenTimezone == 'GMT': # Greenwich Mean Time (same as UTC - no change to time) + givenTZ = timezone('GMT') elif givenTimezone == 'HST': # Hawaiian Standard Time pass elif givenTimezone == 'AKT': # Alaska Time @@ -615,23 +620,23 @@ or None if we fail to get the info """ elif givenTimezone == 'JST': # Japan Standard Time pass elif givenTimezone == 'AWST': # Australian Western Standard Time - givenTimezone = timezone('Australia/West') + givenTZ = timezone('Australia/West') elif givenTimezone == 'ACST': # Australian Central Standard Time - givenTimezone = timezone('Australia/Darwin') + givenTZ = timezone('Australia/Darwin') elif givenTimezone == 'AEST': # Australian Eastern Standard Time # Each State on the East Coast has different DSTs. # Melbournce is out because I don't like AFL, Queensland doesn't have DST # ACT is full of politicians and Tasmania will never notice. # Using Sydney. - givenTimezone = timezone('Australia/Sydney') + givenTZ = timezone('Australia/Sydney') elif givenTimezone == 'NZT': # New Zealand Time pass else: raise Error #TODO raise appropriate error - localisedTime = givenTimezone.localize(time) + localisedTime = givenTZ.localize(time) utcTime = localisedTime.astimezone(wantedTimezone) - #print "utcTime:",utcTime + log.debug( _("utcTime:")+str(utcTime) ) return utcTime #end @staticmethod def changeTimezone diff --git a/pyfpdb/OnGameToFpdb.py b/pyfpdb/OnGameToFpdb.py index d7117e9c..0651d0ed 100755 --- a/pyfpdb/OnGameToFpdb.py +++ b/pyfpdb/OnGameToFpdb.py @@ -65,7 +65,8 @@ class OnGame(HandHistoryConverter): #self.rexx.setGameInfoRegex('.*Blinds \$?(?P[.0-9]+)/\$?(?P[.0-9]+)') # Static regexes - re_SplitHands = re.compile('\n\n\n+') + # ***** End of hand R5-75443872-57 ***** + re_SplitHands = re.compile(u'\*\*\*\*\*\sEnd\sof\shand\s[-A-Z\d]+.*\n(?=\*)') # ***** History for hand R5-75443872-57 ***** # Start hand: Wed Aug 18 19:29:10 GMT+0100 2010 @@ -179,9 +180,10 @@ class OnGame(HandHistoryConverter): # So we need to re-interpret te string to be useful m1 = self.re_DateTime.finditer(info[key]) for a in m1: - datetimestr = "%s %s %s %s:%s:%s" % (a.group('M'),a.group('D'), a.group('Y'), a.group('H'),a.group('MIN'),a.group('S')) - hand.startTime = time.strptime(datetimestr, "%b %d %Y %H:%M:%S") + datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'),a.group('M'), a.group('D'), a.group('H'),a.group('MIN'),a.group('S')) # TODO: Manually adjust time against OFFSET + hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%b/%d %H:%M:%S") # also timezone at end, e.g. " ET" + hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "GMT", "UTC") if key == 'HID': hand.handid = info[key] if key == 'TABLE':