summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IMAGES_I_LIKE30
-rwxr-xr-xexample.py24
-rw-r--r--ricky/config.py6
-rw-r--r--ricky/im.py13
-rw-r--r--ricky/imgradient/options.py49
-rw-r--r--ricky/imgrid/params.py2
-rw-r--r--ricky/param/color.py2
-rw-r--r--ricky/param/multiselect.py86
-rw-r--r--ricky/param/numberrange.py2
-rw-r--r--ricky/param/param.py58
-rw-r--r--ricky/params.py89
11 files changed, 221 insertions, 140 deletions
diff --git a/IMAGES_I_LIKE b/IMAGES_I_LIKE
new file mode 100644
index 0000000..b6015c1
--- /dev/null
+++ b/IMAGES_I_LIKE
@@ -0,0 +1,30 @@
+http://i.asdf.us/im/17/PbGradientrgb-170,85,191--rgb-82,218,137-_1444004673_RICHARD_GIOVANNI.gif
+http://i.asdf.us/im/f8/PbGradientrgb-132,244,247--rgb-224,81,193-_1444004381_RICHARD_GIOVANNI.gif
+http://i.asdf.us/im/2e/PbGradientrgb-234,111,243--rgb-148,81,42-_1443599254_RICHARD_GIOVANNI.png
+http://i.asdf.us/im/fe/PbGradientrgb-161,192,227--rgb-0,122,157-_1443599454_RICHARD_GIOVANNI.png
+http://i.asdf.us/im/e5/gradient_EE7600-DAA520_1333686676_richard_giovanni.gif
+http://i.asdf.us/im/1f/imGradientrgb-151,177,5--rgb-199,170,60-_1426369687_RICHARD_GIOVANNI.gif
+http://i.asdf.us/im/a8/gradient_B23AEE-DBDBDB_1333686618_richard_giovanni.gif
+http://i.asdf.us/im/3f/gradient_1C1C1C-CD950C_1330752187_richard_giovanni.gif
+http://i.asdf.us/im/81/gradient_9ACD32-D1D1D1_1330751036_richard_giovanni.gif
+http://i.asdf.us/im/8f/gradient_8B7E66-FFE7BA_1342331099_richard_giovanni.gif
+http://i.asdf.us/im/35/gradient_8B6914-5CACEE_1332473103_richard_giovanni.gif
+http://i.asdf.us/im/d5/gradient_9FB6CD-FFA54F_1332473270_richard_giovanni.gif
+http://i.asdf.us/im/7e/gradient_698B22-CD6839_1337832614_richard_giovanni.gif
+http://i.asdf.us/im/8a/gradient_A4D3EE-EDEDED_1359970821_richard_giovanni.jpg
+http://i.asdf.us/im/86/gradient_FFFF00-7A67EE_1337832461_richard_giovanni.jpg
+http://i.asdf.us/im/7e/gradient_698B22-CD6839_1337832614_richard_giovanni.gif
+http://i.asdf.us/im/ec/gradient_8B7B8B-EE7621_1342330941_richard_giovanni.gif
+http://i.asdf.us/im/5c/gradient_FFF68F-CD919E_1337841392_richard_giovanni.gif
+http://i.asdf.us/im/e0/gradient_473C8B-4D4D4D_1337840985_richard_giovanni.jpg
+http://i.asdf.us/im/b1/gradient_EE7600-EE3A8C_1337841661_richard_giovanni.jpg
+http://i.asdf.us/im/70/gradient_00C5CD-C6E2FF_1337832592_richard_giovanni.png
+http://i.asdf.us/im/de/gradient_FFB6C1-6959CD_1330753369_richard_giovanni.gif
+http://i.asdf.us/im/e4/gradient_66CDAA-FFF68F_1337832286_richard_giovanni.png
+http://i.asdf.us/im/e5/gradient_EE7600-DAA520_1333686676_richard_giovanni.gif
+http://i.asdf.us/im/d0/gradient_00FFFF-2F4F4F_1332472862_richard_giovanni.png
+http://i.asdf.us/im/74/gradient_8B8386-63B8FF_1372295330_richard_giovanni.png
+http://i.asdf.us/im/2a/imGradientwhite-rgb(214,66,169)_1425441566_RICHARD_GIOVANNI.png
+http://i.asdf.us/im/6f/gradient_B3B3B3-2E8B57_1330812175_richard_giovanni.gif
+http://i.asdf.us/im/f3/gradient_8B8970-474747_1330753647_richard_giovanni.jpg
+http://i.asdf.us/im/e5/gradient_FF7F00-E3E3E3_1359970890_richard_giovanni.jpg
diff --git a/example.py b/example.py
index 58e4d9f..600181e 100755
--- a/example.py
+++ b/example.py
@@ -5,33 +5,43 @@ from ricky.imgrid import ImGrid
from ricky.imbreak import ImBreak
from ricky.imgradient import ImGradient
import pprint
+import time
-api = ImPattern()
+#ok we are 32 and we need a from_dict method
+#ok we are 32 and we need a from_dict method
+test_d = {'username': 'RICHARD_GIOVANNI', 'bevel': 'flatinner', 'saturation': '', 'rotate': 34, 'percentbeveled': 96, 'brightness': 79, 'stripenumber': 2, 'filetype': 'png', 'blurriness': 180, 'flip': '', 'height': 594, 'color1': 'rgb(191,125,24)', 'width': 536, 'color2': 'rgb(186,78,94)', 'gradienttype': 'mirrored', 'stripeintensity': 2515, 'tilt': 58, 'flop': '', 'halftone': 'etchedtransition', 'hue': 146}
+#for i in xrange(0,100):
+api = ImGradient()
params = api.params_init()
-params.randomize()
+params.from_dict(test_d)
+#params.randomize()
print params.as_dict()
req = params.execute()
print req
+#if not (i % 5):
+# time.sleep(2)
-#api = ImGrid()
+
+#api = ImPattern()
#params = api.params_init()
#params.randomize()
#print params.as_dict()
#req = params.execute()
#print req
-
-
-#api = ImBreak()
+#api = ImGrid()
#params = api.params_init()
#params.randomize()
#print params.as_dict()
#req = params.execute()
#print req
-#api = ImGradient()
+
+
+#api = ImBreak()
#params = api.params_init()
#params.randomize()
#print params.as_dict()
#req = params.execute()
#print req
+
diff --git a/ricky/config.py b/ricky/config.py
index 3aeba81..d68543c 100644
--- a/ricky/config.py
+++ b/ricky/config.py
@@ -1,5 +1,9 @@
+"""ALL GLOBAL CONSTANTS GO HERE"""
USERNAME = "RICHARD_GIOVANNI"
-TEST_URL = "http://i.asdf.us/im/65/imBreak5qI6DN2_14254-PbPattern_1444004782_pepper.png"
+TEST_URL = (
+ "http://i.asdf.us/im/"
+ "65/imBreak5qI6DN2_14254-PbPattern_1444004782_pepper.png"
+)
PATTERN_BASE_URL = "http://asdf.us/impattern/patterns"
IMPATTERN_URL = "http://asdf.us/im/api/impattern"
IMGRID_URL = "http://asdf.us/im/api/imgrid"
diff --git a/ricky/im.py b/ricky/im.py
index 715d825..159aa89 100644
--- a/ricky/im.py
+++ b/ricky/im.py
@@ -1,19 +1,23 @@
import urllib
import urllib2
import sys
-import random
import simplejson as json
-import urllib2
+
class Im:
def __init__(self):
self._required_keys = []
self.url = ""
+
def post_request(self, url, params):
params = urllib.urlencode(params)
headers = {
"Content-type": "application/x-www-form-urlencoded",
- "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36",
+ "User-Agent":(
+ "Mozilla/5.0 (X11; Linux x86_64) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
+ "Chrome/40.0.2214.94 Safari/537.36"
+ ),
"Accept": "text/plain"
}
try:
@@ -23,7 +27,8 @@ class Im:
except Exception as e:
sys.stderr.write(str(e))
raise
+
def call(self, params):
if not(params.is_ready()):
- raise Exception("Im Params Not Ready")
+ raise Exception("Im Params Not Ready")
return json.loads(self.post_request(self.url, params.as_dict()))
diff --git a/ricky/imgradient/options.py b/ricky/imgradient/options.py
index 29091ce..0873c2c 100644
--- a/ricky/imgradient/options.py
+++ b/ricky/imgradient/options.py
@@ -1,19 +1,20 @@
from ricky.param.options import Options
+
width_options = Options.from_dict(
- { "value" : 400, "weight" : 1 },
- { "value" : 600, "weight" : 1 },
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
)
height_options = Options.from_dict(
- { "value" : 400, "weight" : 1 },
- { "value" : 600, "weight" : 1 },
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
)
color1_options = Options.from_dict(
- { "value" : "black", "weight" : 1 },
- { "value" : "white", "weight" : 2 },
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 2 },
)
color2_options = Options.from_dict(
- { "value" : "black", "weight" : 2 },
- { "value" : "white", "weight" : 1 },
+ { "value" : "black", "weight" : 2 },
+ { "value" : "white", "weight" : 1 },
)
stripes_options = Options.from_dict(
{"value":"true", "weight": 1},
@@ -40,14 +41,14 @@ halftone_options = Options.from_dict(
{ "value" : "flatstripes", "weight": 1 },
)
bevel_options = Options.from_dict(
- { "value" : "", "weight" : 4 },
- { "value" : "flatout", "weight" : 1 },
- { "value" : "flatinner", "weight" : 1 },
- { "value" : "evenlyframed", "weight" : 1 },
- { "value" : "biginner", "weight" : 1 },
- { "value" : "bigouter", "weight" : 1 },
- { "value" : "dramaticflatout", "weight" : 1 },
- { "value" : "dramaticflatinner", "weight" : 1 },
+ { "value" : "", "weight" : 4 },
+ { "value" : "flatout", "weight" : 1 },
+ { "value" : "flatinner", "weight" : 1 },
+ { "value" : "evenlyframed", "weight" : 1 },
+ { "value" : "biginner", "weight" : 1 },
+ { "value" : "bigouter", "weight" : 1 },
+ { "value" : "dramaticflatout", "weight" : 1 },
+ { "value" : "dramaticflatinner", "weight" : 1 },
)
blurriness_options = \
@@ -72,12 +73,12 @@ filetype_options = Options.from_dict(
{"value":"gif", "weight": 2},
)
gradienttype_options = Options.from_dict(
- { "value" : "canvas", "weight" : 1 },
- { "value" : "gradient", "weight" : 3 },
- { "value" : "radial", "weight" : 1 },
- { "value" : "colorspace", "weight" : 1 },
- { "value" : "plasmawash", "weight" : 1 },
- { "value" : "gradientwash", "weight" : 1 },
- { "value" : "mirrored", "weight" : 1 },
- { "value" : "noise", "weight" : 1 },
+ { "value" : "canvas", "weight" : 1 },
+ { "value" : "gradient", "weight" : 3 },
+ { "value" : "radial", "weight" : 1 },
+ { "value" : "colorspace", "weight" : 1 },
+ { "value" : "plasmawash", "weight" : 1 },
+ { "value" : "gradientwash", "weight" : 1 },
+ { "value" : "mirrored", "weight" : 1 },
+ { "value" : "noise", "weight" : 1 },
)
diff --git a/ricky/imgrid/params.py b/ricky/imgrid/params.py
index 0d78c08..2bcb367 100644
--- a/ricky/imgrid/params.py
+++ b/ricky/imgrid/params.py
@@ -35,7 +35,7 @@ class Param_Zoom(NumberRange):
@property
def value(self):
- return super(MultiSelect, self).get_value()
+ return super(MultiSelect, self).value_get()
@value.setter
def value(self, value):
self._value = value
diff --git a/ricky/param/color.py b/ricky/param/color.py
index 8980236..b331fb9 100644
--- a/ricky/param/color.py
+++ b/ricky/param/color.py
@@ -10,7 +10,7 @@ class Color(MultiSelect):
@property
def value(self):
- return super(MultiSelect, self).get_value()
+ return super(MultiSelect, self).value_get()
@value.setter
def value(self, value):
self._value = value
diff --git a/ricky/param/multiselect.py b/ricky/param/multiselect.py
index d7db80f..1db22f3 100644
--- a/ricky/param/multiselect.py
+++ b/ricky/param/multiselect.py
@@ -1,56 +1,60 @@
import random
from ricky.param import Param
+
class MultiSelect(Param):
def __init__(self, **kwargs):
- self._options = []
- if 'options' in kwargs: self._options = kwargs['options'] or []
- super(MultiSelect, self).__init__(**kwargs)
- if len(self._options):
- self._validate_options()
- self.default(self._choose_heaviest())
-
+ self._options = kwargs.get('options') or []
+ super(MultiSelect, self).__init__(**kwargs)
+ if len(self._options):
+ self._validate_options()
+ """default value is the option with the heaviest weight"""
+ self.default(self._choose_heaviest())
def options(self):
- return self._options
+ return self._options
+
def _validate_options(self):
- try:
- int(self._options[0]['weight'])
- self._options[0]['value']
- except Exception as e:
- raise ValueError
+ try:
+ int(self._options[0]['weight'])
+ self._options[0]['value']
+ except Exception:
+ raise ValueError('Unable to validate %s\n:' % self.name)
- def get_value(self):
- return super(MultiSelect, self).get_value()
- def set_value(self, value):
- if not any([ value == i['value'] for i in self._options ]) and value != None:
- raise ValueError
- super(MultiSelect, self).set_value(value)
- value = property(get_value, set_value)
+ def value_get(self):
+ return super(MultiSelect, self).value_get()
+ def value_set(self, value):
+ if not any([value == i['value'] for i in self._options]) and \
+ value is not None:
+ raise ValueError
+ super(MultiSelect, self).value_set(value)
+
+ value = property(value_get, value_set)
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.options()))
- choice = random.randint(0, weights_total)
- position = 0
- for elem in self.options():
- position += elem["weight"]
- if position >= choice:
- self.value = elem["value"]
- break
+ weights_total = sum(map(lambda x: x["weight"], self.options()))
+ choice = random.randint(0, weights_total)
+ position = 0
+ for elem in self.options():
+ position += elem["weight"]
+ if position >= choice:
+ self.value = elem["value"]
+ break
def _choose_heaviest(self):
- heaviest_idx = 0
- heaviest_weight = 0
- idx = 0
- if (len(self.options())):
- for elem in self.options():
- if elem["weight"] > heaviest_weight:
- heaviest_weight = elem["weight"]
- heaviest_idx = idx;
- idx += 1
- return self.options()[heaviest_idx]["value"]
- else:
- self.randomize()
+ heaviest_idx = 0
+ heaviest_weight = 0
+ idx = 0
+ if (len(self.options())):
+ for elem in self.options():
+ if elem["weight"] > heaviest_weight:
+ heaviest_weight = elem["weight"]
+ heaviest_idx = idx
+ idx += 1
+ return self.options()[heaviest_idx]["value"]
+ else:
+ self.randomize()
+
def heaviest(self):
- self.value = self._choose_heaviest()
+ self.value = self._choose_heaviest()
diff --git a/ricky/param/numberrange.py b/ricky/param/numberrange.py
index 7e01a81..37b85e3 100644
--- a/ricky/param/numberrange.py
+++ b/ricky/param/numberrange.py
@@ -18,7 +18,7 @@ class NumberRange(MultiSelect):
self.value = random.randint(self.range_min,self.range_max)
@property
def value(self):
- return super(MultiSelect, self).get_value()
+ return super(MultiSelect, self).value_get()
@value.setter
def value(self, value):
self._value = value
diff --git a/ricky/param/param.py b/ricky/param/param.py
index 05388f8..838da6b 100644
--- a/ricky/param/param.py
+++ b/ricky/param/param.py
@@ -1,38 +1,48 @@
import pprint
+import sys
class Param(object):
-# def __init__(self, **kwargs):
- def __init__(self, required=0, set_by_user=0, value=None, name=None, **kwargs):
- self._value_default = None
- self.name = name
- self.required = required
- self.is_ready = 0
- self.value = value
- self.set_by_user = set_by_user
+ def __init__(
+ self,
+ required=0,
+ set_by_user=0,
+ value=None,
+ name=None,
+ **kwargs):
+ self._value_default = None
+ self.name = name
+ self.required = required
+ self.is_ready = 0
+ self._value = value
+ self.set_by_user = set_by_user
+
def __str__(self):
- return pprint.pformat(vars(self))
+ return pprint.pformat(vars(self))
+
+ def value_get(self):
+ if self.set_by_user == 1:
+ return self._value
+ return self._value_default
+
+ def value_set(self, value):
+ self._value = value
+ sys.stderr.write("trying to set %s: %s \n" % (self.name, value))
+ if self._value:
+ self.is_ready = 1
+ self.set_by_user = 1
- def get_value(self):
- if self.set_by_user == 1:
- return self._value
- return self._value_default
- def set_value(self, value):
- self._value = value
- if not self._value is None:
- self.is_ready = 1
- self.set_by_user = 1
- value = property(get_value, set_value)
+ value = property(value_get, value_set)
def default(self, value):
- self._value_default = value
+ self._value_default = value
@property
def is_ready(self):
- return self._is_ready or not self.required
+ return self._is_ready or not self.required
+
@is_ready.setter
def is_ready(self, n):
- self._is_ready = n
-
+ self._is_ready = n
def randomize(self):
- pass
+ pass
diff --git a/ricky/params.py b/ricky/params.py
index 304ad2d..2b5e6ee 100644
--- a/ricky/params.py
+++ b/ricky/params.py
@@ -1,49 +1,66 @@
+"""base class for all params"""
import sys
import pprint
+
+
class Params(object):
- def __init__(self):
- self._api = None
- self._params = []
+ def __init__(self):
+ self._api = None
+ self._params = []
+
+ def param(self, name):
+ """getter for the param by name"""
+ for param in self._params:
+ if param.name == name:
+ return param
+ return None
- def param(self, name):
- for p in self._params:
- if p.name == name:
- return p
- return None
+ def __str__(self):
+ """string representation"""
+ return pprint.pformat({"params": map(lambda x: vars(x), self._params)})
- def __str__(self):
- return pprint.pformat({ "params": map(lambda x: vars(x), self._params) })
+ def randomize(self):
+ """assign random values to all params, taking into account weight"""
+ for param in self._params:
+ if param.set_by_user:
+ continue
+ param.randomize()
- def randomize(self):
- for el in self._params:
- if el.set_by_user:
- continue
- el.randomize()
- @property
- def api(self):
- return self._api
+ @property
+ def api(self):
+ """property setter for im api"""
+ return self._api
- @api.setter
- def api(self, cls):
- self._api = cls
+ @api.setter
+ def api(self, cls):
+ """property getter for im api"""
+ self._api = cls
+ def execute(self):
+ """calls the associated api"""
+ return self.api.call(self)
- def execute(self):
- return self.api.call(self)
+ def is_ready(self):
+ """test to see if any params with required values are missing"""
+ for param in self._params:
+ if not param.is_ready and not param.default:
+ sys.stderr.write("param not ready: %s\n" % param)
+ return 0
+ return 1
- def is_ready(self):
- for p in self._params:
- if not p.is_ready and not p.default:
- sys.stderr.write("param not ready: {}".format(p))
- return 0
- return 1
+ def __dict__(self):
+ result = {}
+ for param in self._params:
+ result[param.name] = param.value
+ return result
- def __dict__(self):
- result = {}
- for p in self._params:
- result[p.name] = p.value
- return result
+ def as_dict(self):
+ """alias for __dict__"""
+ return self.__dict__()
- def as_dict(self):
- return self.__dict__()
+ def from_dict(self, params_dict):
+ """set param values manually from a dictionary"""
+ for param in self._params:
+ if param.name in params_dict.keys():
+ param.value_set(params_dict[param.name])