From 683f6cee2028ee953650cfd1618a399ffa706273 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 21 Aug 2010 13:44:01 +0100 Subject: [PATCH 1/6] 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': From 53b15898ce61b4033bf2af38c8e18536bd09f30b Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 21 Aug 2010 21:10:21 +0100 Subject: [PATCH 2/6] more fixes to OnGame import --- pyfpdb/HandHistoryConverter.py | 17 ++++++- pyfpdb/OnGameToFpdb.py | 88 ++++++++++++++++++++++++---------- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 7ec5327c..f7333dfa 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -70,6 +70,7 @@ class HandHistoryConverter(): # "utf_8" is more likely if there are funny characters codepage = "cp1252" + re_tzOffset = re.compile('^\w+[+-]\d{4}$') def __init__(self, config, in_path = '-', out_path = '-', follow=False, index=0, autostart=True, starsArchive=False, ftpArchive=False): """\ @@ -572,6 +573,12 @@ or None if we fail to get the info """ @staticmethod def changeTimezone(time, givenTimezone, wantedTimezone): + """Takes a givenTimezone in format AAA or AAA+HHMM where AAA is a standard timezone + and +HHMM is an optional offset (+/-) in hours (HH) and minutes (MM) + (See OnGameToFpdb.py for example use of the +HHMM part) + Tries to convert the time parameter (with no timezone) from the givenTimezone to + the wantedTimeZone (currently only allows "UTC") + """ log.debug( _("raw time:")+str(time) + _(" given TZ:")+str(givenTimezone) ) if wantedTimezone=="UTC": wantedTimezone = pytz.utc @@ -579,6 +586,10 @@ or None if we fail to get the info """ raise Error #TODO raise appropriate error givenTZ = None + if HandHistoryConverter.re_tzOffset.match(givenTimezone): + offset = int(givenTimezone[-5:]) + givenTimezone = givenTimezone[0:-5] + log.debug( _("changeTimeZone: offset=") + str(offset) ) if givenTimezone=="ET": givenTZ = timezone('US/Eastern') @@ -634,8 +645,12 @@ or None if we fail to get the info """ else: raise Error #TODO raise appropriate error + if givenTZ is None: + raise Error #TODO raise appropriate error + # (or just return time unchanged?) + localisedTime = givenTZ.localize(time) - utcTime = localisedTime.astimezone(wantedTimezone) + utcTime = localisedTime.astimezone(wantedTimezone) + datetime.timedelta(seconds=-3600*(offset/100)-60*(offset%100)) log.debug( _("utcTime:")+str(utcTime) ) return utcTime #end @staticmethod def changeTimezone diff --git a/pyfpdb/OnGameToFpdb.py b/pyfpdb/OnGameToFpdb.py index 0651d0ed..6e3c51f1 100755 --- a/pyfpdb/OnGameToFpdb.py +++ b/pyfpdb/OnGameToFpdb.py @@ -43,6 +43,8 @@ class OnGame(HandHistoryConverter): codepage = ("utf8", "cp1252") siteId = 5 # Needs to match id entry in Sites database + mixes = { } # Legal mixed games + sym = {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": "\xe2\x82\xac", "GBP": "\xa3"} # ADD Euro, Sterling, etc HERE substitutions = { 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes 'LS' : "\$|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8) @@ -83,20 +85,24 @@ class OnGame(HandHistoryConverter): )? """ % substitutions, re.MULTILINE|re.DOTALL|re.VERBOSE) + re_TailSplitHands = re.compile(u'(\*\*\*\*\*\sEnd\sof\shand\s[-A-Z\d]+.*\n)(?=\*)') + re_Button = re.compile('Button: seat (?P