~numerigraphe-team/report-print-send/7.0-report_webkit_custom_paper_size

« back to all changes in this revision

Viewing changes to pingen/pingen.py

  • Committer: nicolas.bessi at camptocamp
  • Author(s): gbaconnier-c2c
  • Date: 2012-12-28 14:06:44 UTC
  • mfrom: (4.2.1 lp6.1-pingen-1086393)
  • Revision ID: nicolas.bessi@camptocamp.com-20121228140644-2vx8adotp1er3gbx
[FIX] pingen bug lp:1086393

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import logging
24
24
import urlparse
25
25
import json
 
26
import pytz
26
27
 
 
28
from datetime import datetime
27
29
from requests.packages.urllib3.filepost import encode_multipart_formdata
28
30
 
29
31
_logger = logging.getLogger(__name__)
37
39
    400: 'Sending cancelled',
38
40
}
39
41
 
 
42
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'  # this is the format used by pingen API
 
43
 
 
44
TZ = pytz.timezone('Europe/Zurich')  # this is the timezone of the pingen API
 
45
 
 
46
 
 
47
def pingen_datetime_to_utc(dt):
 
48
    """ Convert a date/time used by pingen.com to UTC timezone
 
49
 
 
50
    :param dt: pingen date/time as string (as received from the API)
 
51
               to convert to UTC
 
52
    :return: datetime in the UTC timezone
 
53
    """
 
54
    utc = pytz.utc
 
55
    dt = datetime.strptime(dt, DATETIME_FORMAT)
 
56
    localized_dt = TZ.localize(dt, is_dst=True)
 
57
    return localized_dt.astimezone(utc)
 
58
 
40
59
 
41
60
class PingenException(RuntimeError):
42
61
    """There was an ambiguous exception that occurred while handling your