summaryrefslogtreecommitdiff
path: root/Param/Img_url/__init__.py
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-09-19 16:13:31 -0700
committeryo mama <pepper@scannerjammer.com>2015-09-19 16:13:31 -0700
commit8f2230b7c866320e3839d6812b98b8370a7ec5d9 (patch)
treed3a9b450c42c39b20a1f13dcdf826c64b140b42e /Param/Img_url/__init__.py
parent1d1889c9d909313499948d329f1b7826a51ed83c (diff)
ok all modules working
Diffstat (limited to 'Param/Img_url/__init__.py')
-rw-r--r--Param/Img_url/__init__.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/Param/Img_url/__init__.py b/Param/Img_url/__init__.py
index 176888b..58ed2e0 100644
--- a/Param/Img_url/__init__.py
+++ b/Param/Img_url/__init__.py
@@ -1,7 +1,9 @@
+import os
from Param import Param
from Config import *
import urllib, urllib2
from subprocess import Popen, PIPE
+import sys
Request = urllib2.Request
urlencode = urllib.urlencode
urlopen = urllib2.urlopen
@@ -9,26 +11,41 @@ Request = urllib2.Request
urlencode = urllib.urlencode
urlopen = urllib2.urlopen
-
-def ParamImg_url(Param):
+import sys;
+class ParamImg_url(Param):
def __init__(self, value, key="", classname=""):
- self._classname = classname
- super(ParamImg_url).__init__()
-
+ super(ParamImg_url, self).__init__(classname=classname)
if value:
try:
self.filename = self._filename_temporary(key)
- self.path = os.path.join(self._working_dir, _filename)
- self._image_download(value, self._path)
- self.mimetype = self._image_mimetype(_path)
- self.value = self.path
+
+ self.path = os.path.join(self._working_dir, self.filename)
+ self._image_download(value, self.path)
+ self.mimetype = self._image_mimetype(self.path)
+ self.url = value
except Exception as e:
self.err_warn("Unable to download image: %s" % str(value))
self.err_warn(str(e))
-
def _filename_temporary(self, s):
return "_tmp-{}-{}_{}".format(self._classname, self._now, s)
+
+ def __dict__(self):
+ return {
+ 'filename' : self.filename,
+ 'path': self.path,
+ 'url': self.url,
+ 'mimetype': self.mimetype
+ }
+
+ def __getitem__(self, item):
+ return self.__dict__().__getitem__(item)
+
+ def __str__(self):
+ return str(self.__dict__())
+
+ def __nonzero__(self):
+ return True if self.path and self.mimetype else False
def _image_download(self, url, path):
max_size = MAX_SIZE