From 048548b0a7564c7333aff3469fbba8c507f7c77e Mon Sep 17 00:00:00 2001 From: Mat Kelly Date: Thu, 14 Dec 2017 17:21:45 -0500 Subject: [PATCH] Windows locale detection for win32 --- ipwb/util.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ipwb/util.py b/ipwb/util.py index 225faadb..f2fed591 100644 --- a/ipwb/util.py +++ b/ipwb/util.py @@ -17,6 +17,7 @@ import locale import datetime import logging +import platform import urllib2 import json @@ -136,10 +137,15 @@ def retrieveMemCount(): def datetimeToRFC1123(digits14): - try: - locale.setlocale(locale.LC_TIME, 'en_US') - except locale.Error as e: - locale.setlocale(locale.LC_TIME, 'en_US.utf8') + currentOS = platform.system() + if currentOS == 'Darwin': + newLocale = 'en_US' + elif currentOS == 'Windows': + newLocale = 'english' + else: # Assume Linux + newLocale = 'en_US.utf8' + + locale.setlocale(locale.LC_TIME, newLocale) d = datetime.datetime.strptime(digits14, '%Y%m%d%H%M%S') return d.strftime('%a, %d %b %Y %H:%M:%S GMT')