diff options
| -rw-r--r-- | Pb_Api/ImPattern/Params.py | 14 | ||||
| -rw-r--r-- | Pb_Api/Param/__init__.py | 4 | ||||
| -rw-r--r-- | Pb_Api/Params.py | 56 | ||||
| -rw-r--r-- | Pb_Api/__init__.py | 1 | ||||
| -rw-r--r-- | test2.py | 9 |
5 files changed, 36 insertions, 48 deletions
diff --git a/Pb_Api/ImPattern/Params.py b/Pb_Api/ImPattern/Params.py index a046d5e..1d31645 100644 --- a/Pb_Api/ImPattern/Params.py +++ b/Pb_Api/ImPattern/Params.py @@ -17,24 +17,14 @@ class Pattern_Url_Option(Pb_Api_Param_Option): def from_name(cls, **kwargs): formatted = "{}/{}.png".format(PATTERN_BASE_URL, kwargs["value"]) return cls(weight=kwargs["weight"], value=formatted ) - -class Pattern_Url_Options: - def __init__(self, arr): - self._values = arr - def __iter__(self): - return self._values - def grep(self, s): - for i in self: - if re.match(s, i): - return i pattern_url_options = Pb_Api_Param_Options([ Pattern_Url_Option.from_name(weight=0, value=i) for i in range(1,100) ] + [ - Pattern_Url_Option.from_name(weight=0, value="A{}".format(i)) for i in range(0, 42) + Pattern_Url_Option.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42) ]) -pattern_url_options.search("A10").weight = 20; +pattern_url_options.search("a10").weight = 20; class ImPattern_Params(Pb_Api_Params): def __init__(self): diff --git a/Pb_Api/Param/__init__.py b/Pb_Api/Param/__init__.py index 362a3f7..58b3eb0 100644 --- a/Pb_Api/Param/__init__.py +++ b/Pb_Api/Param/__init__.py @@ -6,7 +6,7 @@ class Pb_Api_Param(object): self._value_default = None self.name = name self.required = required - self.is_ready = 0 #should I try that? + self.is_ready = 0 self.value = value self.set_by_user = set_by_user def __str__(self): @@ -20,7 +20,7 @@ class Pb_Api_Param(object): self._value = value if not self._value is None: self.is_ready = 1 - self.set_by_user = 1 #like that? yeah also need method for setting default value + self.set_by_user = 1 value = property(get_value, set_value) def default(self, value): diff --git a/Pb_Api/Params.py b/Pb_Api/Params.py index fff0696..9ab90a9 100644 --- a/Pb_Api/Params.py +++ b/Pb_Api/Params.py @@ -1,34 +1,34 @@ import pprint class Pb_Api_Params(object): - #so how do we need to change these? - def param(self, name): - for p in self.params: - if p.name == name: - return p - return None + def param(self, name): + for p in self.params: + if p.name == name: + return p + return None +# def __iter__(self): +# return iter(self.params) - def __str__(self): - 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) }) -#do we need to add a simple __iter__ attribute to that class so that map will work, or is it already -#iterating? it is already + def randomize(self): + for el in self.params: + if el.set_by_user: + continue + el.randomize() + + def __dict__(self): + return dict(self) + - - def randomize(self): - for el in self.params: - if el.set_by_user: - continue - el.randomize() - - - def is_ready(self): - for p in self.params: - if not p.is_ready(): - return 0 - return 1 - def as_hash(self): - result = {} - for p in self.params: - result[p.name] = p.value - return result + def is_ready(self): + for p in self.params: + if not p.is_ready(): + return 0 + return 1 + def as_hash(self): + result = {} + for p in self.params: + result[p.name] = p.value + return result diff --git a/Pb_Api/__init__.py b/Pb_Api/__init__.py index ced9983..1b89b9b 100644 --- a/Pb_Api/__init__.py +++ b/Pb_Api/__init__.py @@ -18,6 +18,7 @@ class Pb_Api: def post_request(self, url, params): params = urllib.urlencode(params) sys.stderr.write(params) + sys.stderr.write(url) 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", @@ -4,11 +4,8 @@ import pprint p = Pb_Api_ImPattern() params = p.params() -params.param("image_url").value = "http://hello" -print params +#params.param("image_url").value = "http://hello" +#print params params.randomize() pprint.pprint(params.as_hash()) -# well something like this how do you feel about it? seems right? yep looks good, need to go over ranomization and defaults a bit, but core is ready to use lets just look at randomization for a second? sure -# works, but i think need to reconsider default somehow, it should be something like set_by_user to make sure user set that, and not automated default, or something like that. why is it better to use set by user? well default doesn't say much about value, and in intialization we say that values passed is default, which is not really true. to find difference ( and make randomize() code clearer) it should be somehting like if not el.set_by_user: el.randomize() -# yeahh ok -# well like this, but need to check randomization, keep selecting 1.png weird +print p.call(params.as_hash()) |
