def ParseDateTimeGMT(arpastring, parse_arpadatetime=arpadatetimeRE.match): """ ParseDateTimeGMT(arpastring) Returns a DateTime instance reflecting the given ARPA date converting it to UTC (timezones are honored). """ s = arpastring.strip() date = parse_arpadatetime(s) if not date: raise ValueError, 'wrong format or unknown time zone' litday, day, litmonth, month, year, hour, minute, second, zone = date.groups( ) if len(year) == 2: year = DateTime.add_century(int(year)) else: year = int(year) if litmonth: litmonth = litmonth.lower() try: month = litmonthtable[litmonth] except KeyError: raise ValueError, 'wrong month format' else: month = int(month) day = int(day) hour = int(hour) minute = int(minute) if second is None: second = 0.0 else: second = float(second) offset = Timezone.utc_offset(zone) # litday is ignored return DateTime.DateTime(year, month, day, hour, minute, second) - offset
def ParseDateTimeGMT(arpastring,parse_arpadatetime=arpadatetimeRE.match): """ ParseDateTimeGMT(arpastring) Returns a DateTime instance reflecting the given ARPA date converting it to UTC (timezones are honored). """ s = arpastring.strip() date = parse_arpadatetime(s) if not date: raise ValueError,'wrong format or unknown time zone' litday,day,litmonth,month,year,hour,minute,second,zone = date.groups() if len(year) == 2: year = DateTime.add_century(int(year)) else: year = int(year) if litmonth: litmonth = litmonth.lower() try: month = litmonthtable[litmonth] except KeyError: raise ValueError,'wrong month format' else: month = int(month) day = int(day) hour = int(hour) minute = int(minute) if second is None: second = 0.0 else: second = float(second) offset = Timezone.utc_offset(zone) # litday is ignored return DateTime.DateTime(year,month,day,hour,minute,second) - offset
def ParseDateTimeGMT(isostring, parse_isodatetime=isodatetimeRE.match, strip=string.strip, atoi=string.atoi, atof=string.atof): """ParseDateTimeGMT(isostring) Returns a DateTime instance in UTC reflecting the given ISO date. A time part is optional and must be delimited from the date by a space or 'T'. Timezones are honored. """ s = strip(isostring) date = parse_isodatetime(s) if not date: raise ValueError, 'wrong format, use YYYY-MM-DD HH:MM:SS' year, month, day, hour, minute, second, zone = date.groups() year = atoi(year) if month is None: month = 1 else: month = atoi(month) if day is None: day = 1 else: day = atoi(day) if hour is None: hour = 0 else: hour = atoi(hour) if minute is None: minute = 0 else: minute = atoi(minute) if second is None: second = 0.0 else: second = atof(second) offset = Timezone.utc_offset(zone) return DateTime.DateTime(year, month, day, hour, minute, second) - offset
def ParseDateTimeGMT(isostring,parse_isodatetime=isodatetimeRE.match, strip=string.strip,atoi=string.atoi,atof=string.atof): """ParseDateTimeGMT(isostring) Returns a DateTime instance in UTC reflecting the given ISO date. A time part is optional and must be delimited from the date by a space or 'T'. Timezones are honored. """ s = strip(isostring) date = parse_isodatetime(s) if not date: raise ValueError,'wrong format, use YYYY-MM-DD HH:MM:SS' year,month,day,hour,minute,second,zone = date.groups() year = atoi(year) if month is None: month = 1 else: month = atoi(month) if day is None: day = 1 else: day = atoi(day) if hour is None: hour = 0 else: hour = atoi(hour) if minute is None: minute = 0 else: minute = atoi(minute) if second is None: second = 0.0 else: second = atof(second) offset = Timezone.utc_offset(zone) return DateTime.DateTime(year,month,day,hour,minute,second) - offset
def _parse_time(text, formats=_time_formats, int=int,float=float,replace=string.replace): """ Parses a time part given in text and returns a tuple (text,hour,minute,second,offset,style) with the following meanings: * text gives the original text without the time part * hour,minute,second give the parsed time * offset gives the time zone UTC offset * style gives information about which parser was successful: 'standard' - the standard parser 'iso' - the ISO time format parser 'unknown' - no time part was found formats may be set to a tuple specifying the parsers to use: 'standard' - standard time format with ':' delimiter 'iso' - ISO time format (superset of 'standard') 'unknown' - default to 0:00:00, 0 zone offset If 'unknown' is not given in formats and the time cannot be parsed, a ValueError is raised. """ match = None style = '' # Apply parsers in the order given in formats for format in formats: # Standard format if format == 'standard': match = _timeRE.search(text) if match is not None: hour,minute,second,ampm,zone = match.groups() style = 'standard' break # ISO format if format == 'iso': match = _isotimeRE.search(text) if match is not None: hour,minute,second,zone = match.groups() ampm = None style = 'iso' break # Default handling elif format == 'unknown': hour,minute,second,offset = 0,0,0.0,0 style = 'unknown' break if not style: # If no default handling should be applied, raise an error raise ValueError, 'unknown time format: "%s"' % text # Post-processing if match is not None: if zone: # Convert to UTC offset offset = Timezone.utc_offset(zone) else: offset = 0 hour = int(hour) if ampm: if ampm[0] in ('p', 'P'): # 12pm = midday if hour < 12: hour = hour + 12 else: # 12am = midnight if hour >= 12: hour = hour - 12 if minute: minute = int(minute) else: minute = 0 if not second: second = 0.0 else: if ',' in second: second = replace(second, ',', '.') second = float(second) # Remove time from text left,right = match.span() if 0 and _debug: print 'parsed time:',repr(text[left:right]),\ 'giving:',hour,minute,second,offset text = text[:left] + text[right:] #print '_parse_time:',text,hour,minute,second,offset,style return text,hour,minute,second,offset,style
'info': ['ai03', 'goat', 'kalendar'], 'films': ['apex', 'ash', 'kebo', 'tx'], 'firmware': ['qmkgui', 'via'], 'services': ['ash'], 'artisans': ['alpha', 'jelly', 'kpr', 'kyle', 'mk', 'scraft', 'space', 'summit'], 'ergo': ['aura', 'mkultra', 'wooting'], 'springs': ['prime', 'tx'], 'deskmats': ['aura', 'cannon', 'deskhero', 'kono', 'kpr', 'nk', 'prime', 'tkc', 'tx'], 'groupbuy': [ 'candy', 'cannon', 'dclack', 'deskhero', 'dixie', 'kono', 'krelbit', 'nk', 'origin', 'tkc', 'tx', 'wei' ], 'cad': ['apex', 'ash', 'aura', 'deskhero', 'kofi', 'zeal'] } # load pickles tagDict = load_dict(Constants.TAG_DICT_PATH) siteDict = load_dict(Constants.SITE_DICT_PATH) typeDict = load_dict(Constants.TYPE_DICT_PATH) bDict = load_dict(Constants.B_DICT_PATH) aDict = load_dict(Constants.A_DICT_PATH) shareDict = load_dict(Constants.SHARE_DICT_PATH) # startup bot.add_cog(Timezone(bot)) bot.add_cog(Music(bot)) bot.add_cog(Currency(bot)) bot.run(Constants.DISCORD_SECRET)
def _parse_time(text, formats=_time_formats, int=int, float=float, replace=string.replace): """ Parses a time part given in text and returns a tuple (text,hour,minute,second,offset,style) with the following meanings: * text gives the original text without the time part * hour,minute,second give the parsed time * offset gives the time zone UTC offset * style gives information about which parser was successful: 'standard' - the standard parser 'iso' - the ISO time format parser 'unknown' - no time part was found formats may be set to a tuple specifying the parsers to use: 'standard' - standard time format with ':' delimiter 'iso' - ISO time format (superset of 'standard') 'unknown' - default to 0:00:00, 0 zone offset If 'unknown' is not given in formats and the time cannot be parsed, a ValueError is raised. """ match = None style = '' # Apply parsers in the order given in formats for format in formats: # Standard format if format == 'standard': match = _timeRE.search(text) if match is not None: hour, minute, second, ampm, zone = match.groups() style = 'standard' break # ISO format if format == 'iso': match = _isotimeRE.search(text) if match is not None: hour, minute, second, zone = match.groups() ampm = None style = 'iso' break # Default handling elif format == 'unknown': hour, minute, second, offset = 0, 0, 0.0, 0 style = 'unknown' break if not style: # If no default handling should be applied, raise an error raise ValueError, 'unknown time format: "%s"' % text # Post-processing if match is not None: if zone: # Convert to UTC offset offset = Timezone.utc_offset(zone) else: offset = 0 hour = int(hour) if ampm: if ampm[0] in ('p', 'P'): # 12pm = midday if hour < 12: hour = hour + 12 else: # 12am = midnight if hour >= 12: hour = hour - 12 if minute: minute = int(minute) else: minute = 0 if not second: second = 0.0 else: if ',' in second: second = replace(second, ',', '.') second = float(second) # Remove time from text left, right = match.span() if 0 and _debug: print 'parsed time:',repr(text[left:right]),\ 'giving:',hour,minute,second,offset text = text[:left] + text[right:] #print '_parse_time:',text,hour,minute,second,offset,style return text, hour, minute, second, offset, style