From 53b15898ce61b4033bf2af38c8e18536bd09f30b Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 21 Aug 2010 21:10:21 +0100 Subject: [PATCH] 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