From f1f5728949f9eabbb77e487d60f41d77d59285c6 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 10 Jan 2013 10:58:10 +0200 Subject: Added _process(), langs.json --- gsx.py | 28 ++++++++++++++++++++++++++-- langs.json | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 langs.json diff --git a/gsx.py b/gsx.py index 2f42fcc..5adc33c 100755 --- a/gsx.py +++ b/gsx.py @@ -1,8 +1,9 @@ -#!/usr/bin/env python #coding=utf-8 import re +import base64 from suds.client import Client +from datetime import date, time import logging logging.basicConfig(level=logging.INFO) @@ -87,6 +88,29 @@ class GsxObject(object): def __make_type(self, new_dt): return CLIENT.factory.create(new_dt) + def _process(self, data): + """ + Tries to coerce some types to their Python counterparts + """ + for k, v in data: + # decode binary data + if k in ['packingList', 'proformaFileData', 'returnLabelFileData']: + v = base64.b64decode(v) + + if isinstance(v, basestring): + # convert dates to native Python + if re.search('^\d{2}/\d{2}/\d{2}$', v): + m, d, y = v.split('/') + v = date(2000+int(y), int(m), int(d)).isoformat() + + # strip currency prefix and munge into float + if re.search('Price$', k): + v = float(re.sub('[A-Z ,]', '', v)) + + setattr(data, k, v) + + return data + class Lookup(GsxObject): def parts(self): """ @@ -320,7 +344,7 @@ class Product(GsxObject): """ self.set_request('ns3:warrantyStatusRequestType', 'unitDetail') result = self.submit('WarrantyStatus') - return result.warrantyDetailInfo + return self._process(result.warrantyDetailInfo) def get_activation(self): """ diff --git a/langs.json b/langs.json new file mode 100644 index 0000000..560a595 --- /dev/null +++ b/langs.json @@ -0,0 +1,41 @@ +{ + "en_CA": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "en_GB": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "en_US": {"df": "MM/DD/YY", "tf": "HH:MM A"}, + "en_IN": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "en_IE": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "en_AU": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "en_NZ": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "en_ZA": {"df": "YY/MM/DD", "tf": "HH:MM A"}, + "en_HK": {"df": "MM/DD/YY", "tf": "HH:MM A"}, + "en_SG": {"df": "DD-MM-YY", "tf": "HH:MM A"}, + "en_TH": {"df": "DD-MM-YY", "tf": "HH:MM A"}, + "en_XXX": {"df": "%m/%d/%y", "tf": "%I:%M %p"}, + "fr_FR": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "fr_LU": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "fr_CH": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "fr_BE": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "fr_CA": {"df": "YY-MM-DD", "tf": "HH:MM"}, + "fr_XXX": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "it_IT": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "it_CH": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "it_XXX": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "de_CH": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "de_AT": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "de_DE": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "de_DK": {"df": "DD-MM-YY", "tf": "HH:MM"}, + "de_LU": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "de_XXX": {"df": "DD.MM.YY", "tf": "HH:MM"}, + "es_MX": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "es_ES": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "es_CR": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "es_AR": {"df": "DD/MM/YY", "tf": "HH:MM"}, + "es_CL": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "es_EC": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "es_XXX": {"df": "DD/MM/YY", "tf": "HH:MM A"}, + "ja_JP": {"df": "YYYY/MM/DD", "tf": "HH:MM"}, + "ja_XXX": {"df": "YYYY/MM/DD", "tf": "HH:MM"}, + "ko_XXX": {"df": "MM/DD/YY", "tf": "HH:MM A"}, + "zf_XXX": {"df": "MM/DD/YY", "tf": "HH:MM A"}, + "zh_XXX": {"df": "DD-MM-YY", "tf": "HH:MM A"} +} -- cgit v1.2.3