Merge.

Thu, 11 Oct 2018 12:15:48 +0300

author
Iannis <i.binietoglou@impworks.gr>
date
Thu, 11 Oct 2018 12:15:48 +0300
changeset 19
2a6a9e95bd16
parent 17
9d25bd3e15c4 (diff)
parent 18
a952c1b250a8 (current diff)
child 27
8ebbba085eb0

Merge.

scc_access/scc_access.py file | annotate | diff | comparison | revisions
--- a/requirements.txt	Thu Oct 11 12:11:52 2018 +0300
+++ b/requirements.txt	Thu Oct 11 12:15:48 2018 +0300
@@ -1,1 +1,1 @@
-requests
+.
\ No newline at end of file
--- a/scc_access/scc_access.py	Thu Oct 11 12:11:52 2018 +0300
+++ b/scc_access/scc_access.py	Thu Oct 11 12:15:48 2018 +0300
@@ -2,12 +2,17 @@
 requests.packages.urllib3.disable_warnings()
 
 import sys
-import urlparse
+
+try:
+    import urllib.parse as urlparse  # Python 3
+except ImportError:
+    import urlparse  # Python 2
+
 import argparse
 import os
 import re
 import time
-import StringIO
+from io import StringIO
 from zipfile import ZipFile
 import datetime
 import logging
@@ -128,7 +133,7 @@
             os.makedirs(local_dir)
 
         # Save the file by chunk, needed if the file is big.
-        memory_file = StringIO.StringIO()
+        memory_file = StringIO()
 
         for chunk in request.iter_content(chunk_size=1024):
             if chunk:  # filter out keep-alive new chunks
@@ -366,7 +371,7 @@
         return measurement_id
 
 
-class ApiObject:
+class ApiObject(object):
     """ A generic class object. """
 
     def __init__(self, base_url, dict_response):
@@ -375,7 +380,11 @@
         if dict_response:
             # Add the dictionary key value pairs as object properties
             for key, value in dict_response.items():
-                setattr(self, key, value)
+                # logger.debug('Setting key {0} to value {1}'.format(key, value))
+                try:
+                    setattr(self, key, value)
+                except:
+                    logger.warning('Could not set attribute {0} to value {1}'.format(key, value))
             self.exists = True
         else:
             self.exists = False

mercurial