diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:44:05 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-29 17:44:05 -0800 |
| commit | f3cfd54c876ba3e7540443c2f442d2baa22acef8 (patch) | |
| tree | 583c088e6f183232ddb21bd86f68c9e7b53ccccf | |
| parent | 9a7bf3bffb2a8459e66b988aaff53611723b5ab4 (diff) | |
switched to json probabilities
| -rw-r--r-- | ricky/im.py | 13 | ||||
| -rw-r--r-- | ricky/imgradient/__init__.py | 17 | ||||
| -rw-r--r-- | ricky/imgradient/imgradient.py | 16 | ||||
| -rw-r--r-- | ricky/imgradient/params.py | 116 | ||||
| -rw-r--r-- | ricky/imgradient/selections.py | 105 | ||||
| -rwxr-xr-x | ricky/impattern/__init__.py | 13 | ||||
| -rwxr-xr-x | ricky/impattern/impattern.py | 12 | ||||
| -rw-r--r-- | ricky/impattern/params.py | 18 | ||||
| -rw-r--r-- | ricky/params.py | 5 |
9 files changed, 121 insertions, 194 deletions
diff --git a/ricky/im.py b/ricky/im.py index 3bbcf43..3f94e94 100644 --- a/ricky/im.py +++ b/ricky/im.py @@ -13,7 +13,7 @@ class Im(object): params = urllib.urlencode(params) headers = { "Content-type": "application/x-www-form-urlencoded", - "User-Agent":( + "User-Agent": ( "Mozilla/5.0 (X11; Linux x86_64) " "AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/40.0.2214.94 Safari/537.36" @@ -24,11 +24,10 @@ class Im(object): req = urllib2.Request(url, params, headers) response = urllib2.urlopen(req) return response.read() - except Exception as e: - sys.stderr.write(str(e)) - raise + except urllib.error.HTTPError: + sys.stderr.write("Post Request failed!") def call(self, params): - if not(params.is_ready()): - raise Exception("Im Params Not Ready") - return json.loads(self.post_request(self.url, params.as_dict())) + return json.loads( + self.post_request(self.url, params.as_dict()) + ) diff --git a/ricky/imgradient/__init__.py b/ricky/imgradient/__init__.py index 72efca1..1d8da3d 100644 --- a/ricky/imgradient/__init__.py +++ b/ricky/imgradient/__init__.py @@ -1 +1,16 @@ -from ricky.imgradient.imgradient import ImGradient +"""class for the imgradient api handler""" +from ricky.im import Im +from ricky.imgradient.params import Params +from ricky.config import IMGRADIENT_URL + + +class ImGradient(Im): + def __init__(self): + super(ImGradient, self).__init__() + self.url = IMGRADIENT_URL + + def params_init(self): + new_params = Params() + #new_params = self.get_from_server() + new_params.api = self + return new_params diff --git a/ricky/imgradient/imgradient.py b/ricky/imgradient/imgradient.py deleted file mode 100644 index 1d8da3d..0000000 --- a/ricky/imgradient/imgradient.py +++ /dev/null @@ -1,16 +0,0 @@ -"""class for the imgradient api handler""" -from ricky.im import Im -from ricky.imgradient.params import Params -from ricky.config import IMGRADIENT_URL - - -class ImGradient(Im): - def __init__(self): - super(ImGradient, self).__init__() - self.url = IMGRADIENT_URL - - def params_init(self): - new_params = Params() - #new_params = self.get_from_server() - new_params.api = self - return new_params diff --git a/ricky/imgradient/params.py b/ricky/imgradient/params.py index 373a9a1..8786ae6 100644 --- a/ricky/imgradient/params.py +++ b/ricky/imgradient/params.py @@ -1,120 +1,154 @@ -import re from ricky.params import Params as _Params from ricky.param.username import Username from ricky.param.multiselect import MultiSelect -from ricky.param.numberrange import NumberRange +from ricky.param.constrainednumber import ConstrainedNumber +from ricky.param.bool import Bool from ricky.param.color import Color -from ricky.imgradient.selections import * + + +_HALFTONE_OPTIONS = [ + "", + "checkeredfade", + "etchedtransition", + "bendaydots", + "smallerdots1", + "smallerdots2", + "flatstripes", +] + +_BEVEL_OPTIONS = [ + "", + "flatout", + "flatinner", + "evenlyframed", + "biginner", + "bigouter", + "dramaticflatout", + "dramaticflatinner", +] + +_FILETYPE_OPTIONS = [ + "png", + "jpg", + "gif", +] + +_GRADIENTTYPE_OPTIONS = [ + "canvas", + "gradient", + "radial", + "colorspace", + "plasmawash", + "gradientwash", + "mirrored", + "noise", +] class Params(_Params): def __init__(self): super(Params, self).__init__( Username(name="username", required=0), - NumberRange( + ConstrainedNumber( name="width", required=1, - selections=width_selections, min=10, max=800 ), - NumberRange( + ConstrainedNumber( name="height", required=1, - selections=height_selections, min=10, max=800 ), - Color(name="color1", required=1, selections=color1_selections), - Color(name="color2", required=1, selections=color2_selections), + Color(name="color1", required=1), + Color(name="color2", required=1), MultiSelect( name="filetype", required=0, - selections=filetype_selections ), MultiSelect( name="gradienttype", required=1, - selections=gradienttype_selections + options=_GRADIENTTYPE_OPTIONS ), MultiSelect( name="halftone", required=0, - selections=halftone_selections + options=_HALFTONE_OPTIONS ), - MultiSelect(name="bevel", required=0, selections=bevel_selections), - - NumberRange( + MultiSelect( + name="bevel", + required=0, + options=_BEVEL_OPTIONS + ), + ConstrainedNumber( name="stripenumber", required=0, - selections=stripenumber_selections, min=0, max=400 ), - NumberRange( + ConstrainedNumber( name="stripeintensity", required=0, - selections=stripeintensity_selections, min=0, max=5000 ), - NumberRange( + ConstrainedNumber( name="blurriness", required=0, - selections=blurriness_selections, min=0, max=200 ), - # NumberRange( - # name="contrast", - # required=0, - # selections=contrast_selections, - # min=0, - # max=200 - # ), - NumberRange( + ConstrainedNumber( + name="contrast", + required=0, + min=0, + max=200 + ), + ConstrainedNumber( name="brightness", required=0, - selections=brightness_selections, min=0, max=200 ), - NumberRange( + ConstrainedNumber( name="saturation", required=0, - selections=saturation_selections, min=0, max=200 ), - NumberRange( + ConstrainedNumber( name="hue", required=0, - selections=hue_selections, min=0, max=200 ), - NumberRange( + ConstrainedNumber( name="percentbeveled", required=0, - selections=percentbeveled_selections, min=0, max=100 ), - NumberRange( + ConstrainedNumber( name="rotate", required=0, - selections=rotate_selections, min=0, max=360 ), - NumberRange( + ConstrainedNumber( name="tilt", required=0, - selections=tilt_selections, min=0, max=360 ), - MultiSelect(name="flop", required=0, selections=flop_selections), - MultiSelect(name="flip", required=0, selections=flip_selections), + Bool( + name="flop", + required=0, + ), + Bool( + name="flip", + required=0 + ), ) diff --git a/ricky/imgradient/selections.py b/ricky/imgradient/selections.py deleted file mode 100644 index 5d0d345..0000000 --- a/ricky/imgradient/selections.py +++ /dev/null @@ -1,105 +0,0 @@ -from ricky.param.selections import Selections - -width_selections = Selections.from_dict( - {"value": 40, "weight": 60}, - {"value": 20, "weight": 60}, - {"value": 60, "weight": 60}, - {"value": 80, "weight": 60}, -) -height_selections = Selections.from_dict( - {"value": 400, "weight": 900}, -) -color1_selections = Selections.from_dict( - {"value": "", "weight": 0}, -# {"value": "black", "weight": 1}, -# {"value": "white", "weight": 2}, -) -color2_selections = Selections.from_dict( - {"value": "", "weight": 0}, -# {"value": "black", "weight": 2}, -# {"value": "white", "weight": 1}, -) -stripes_selections = Selections.from_dict( - {"value": "true", "weight": 3}, - {"value": "false", "weight": 1}, -) -stripenumber_selections = Selections.from_dict( - {"value": 3, "weight": 10}, - {"value": 10, "weight": 10}, - {"value": 20, "weight": 10}, - {"value": 100, "weight": 10}, - {"value": 40, "weight": 10}, -# {"value": 1, "weight": 50}, -# {"value": 2, "weight": 50}, -# {"value": 2, "weight": 50}, - -) -stripeintensity_selections = Selections.from_dict( - {"value": 1000, "weight": 10}, - {"value": 4, "weight": 10}, -) -# contrast_selections = \ -brightness_selections = \ - saturation_selections = \ - hue_selections = \ - Selections.from_dict( - {"value": "", "weight": 0}, -# {"value": "", "weight": 300}, -) -halftone_selections = Selections.from_dict( - {"value": "", "weight": 60}, - {"value": "checkeredfade", "weight": 10}, - {"value": "etchedtransition", "weight": 10}, - {"value": "bendaydots", "weight": 10}, - {"value": "smallerdots1", "weight": 10}, - {"value": "smallerdots2", "weight": 10}, - {"value": "flatstripes", "weight": 10}, -) -bevel_selections = Selections.from_dict( - {"value": "", "weight": 4}, - {"value": "flatout", "weight": 1}, - {"value": "flatinner", "weight": 0}, - {"value": "evenlyframed", "weight": 1}, -# {"value": "biginner", "weight": 1}, - {"value": "bigouter", "weight": 1}, - {"value": "dramaticflatout", "weight": 1}, -# {"value": "dramaticflatinner", "weight": 1}, -) - -blurriness_selections = \ - percentbeveled_selections = Selections.from_dict( - {"value": 30, "weight": 10}, - {"value": 10, "weight": 10}, - {"value": 5, "weight": 10}, - {"value": 20, "weight": 10}, - {"value": 25, "weight": 10}, - {"value": 7, "weight": 10}, - {"value": "", "weight": 1}, -) -rotate_selections = \ - tilt_selections = Selections.from_dict( - {"value": 0, "weight": 200}, - {"value": 90, "weight": 2}, - {"value": 180, "weight": 2}, - {"value": 270, "weight": 2}, -) -flop_selections = flip_selections = Selections.from_dict( - {"value": "", "weight": 1}, - {"value": "true", "weight": 1}, -) - -filetype_selections = Selections.from_dict( - {"value": "png", "weight": 10}, - {"value": "jpg", "weight": 2}, - {"value": "gif", "weight": 2}, -) -gradienttype_selections = Selections.from_dict( - {"value": "canvas", "weight": 1}, - {"value": "gradient", "weight": 5}, - {"value": "radial", "weight": 1}, - {"value": "colorspace", "weight": 1}, - {"value": "plasmawash", "weight": 2}, - {"value": "gradientwash", "weight": 1}, - {"value": "mirrored", "weight": 0}, - {"value": "noise", "weight": 1}, -) diff --git a/ricky/impattern/__init__.py b/ricky/impattern/__init__.py index 63a540e..577623e 100755 --- a/ricky/impattern/__init__.py +++ b/ricky/impattern/__init__.py @@ -1 +1,12 @@ -from impattern import ImPattern +from ricky.im import Im +from ricky.impattern.params import ImPatternParams +from ricky.config import IMPATTERN_URL + +class ImPattern(Im): + def __init__(self): + self.url = IMPATTERN_URL + def params_init(self): + new_params = ImPatternParams() + #new_params = self.get_from_server() + new_params.api = self + return new_params diff --git a/ricky/impattern/impattern.py b/ricky/impattern/impattern.py deleted file mode 100755 index 577623e..0000000 --- a/ricky/impattern/impattern.py +++ /dev/null @@ -1,12 +0,0 @@ -from ricky.im import Im -from ricky.impattern.params import ImPatternParams -from ricky.config import IMPATTERN_URL - -class ImPattern(Im): - def __init__(self): - self.url = IMPATTERN_URL - def params_init(self): - new_params = ImPatternParams() - #new_params = self.get_from_server() - new_params.api = self - return new_params diff --git a/ricky/impattern/params.py b/ricky/impattern/params.py index b4a63ae..b2f9253 100644 --- a/ricky/impattern/params.py +++ b/ricky/impattern/params.py @@ -1,17 +1,17 @@ import re from ricky.params import Params from ricky.param import Param -from ricky.param.selection import Selection -from ricky.param.selections import Selections +from ricky.param.probability import Probability +from ricky.param.probabilities import Probabilities from ricky.param.username import Username from ricky.param.imageurl import ImageUrl from ricky.param.multiselect import MultiSelect from ricky.config import PATTERN_BASE_URL -class Pattern_UrlSelection(Selection): +class Pattern_UrlProbability(Probability): def __init__(self, **kwargs): - super(Pattern_UrlSelection, self).__init__(**kwargs) + super(Pattern_UrlProbability, self).__init__(**kwargs) @classmethod def from_name(cls, **kwargs): formatted = "{}/{}.png".format(PATTERN_BASE_URL, kwargs["value"]) @@ -22,12 +22,12 @@ class ImPatternParams(Params): self._params = [ Username(name="username", required=0), ImageUrl(name="image_url", required=1), - MultiSelect(name="pattern_url", required=1, selections=pattern_url_selections) + MultiSelect(name="pattern_url", required=1, probabilities=pattern_url_probabilities) ] -pattern_url_selections = Selections(*[ - Pattern_UrlSelection.from_name(weight=0, value=i) for i in range(1,100) ] + [ - Pattern_UrlSelection.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42) +pattern_url_probabilities = Probabilities(*[ + Pattern_UrlProbability.from_name(weight=0, value=i) for i in range(1,100) ] + [ + Pattern_UrlProbability.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42) ]) -pattern_url_selections.search("a10").weight = 20; +pattern_url_probabilities.search("a10").weight = 20; diff --git a/ricky/params.py b/ricky/params.py index 2f6ef33..869c82a 100644 --- a/ricky/params.py +++ b/ricky/params.py @@ -20,7 +20,9 @@ class Params(object): def __str__(self): """string representation""" - return pprint.pformat({"params": map(lambda x: vars(x), self._params)}) + return pprint.pformat( + {"params": map(lambda x: vars(x), self._params)} + ) def randomize(self): """assign random values to all params, taking into account weight""" @@ -29,7 +31,6 @@ class Params(object): continue param.randomize() - @property def api(self): """property setter for im api""" |
