def create_command(self, command, config): def each(value, key): nonlocal command key = '--' + key if key == '--port': key = '-p' if key == '--daemon': key = '-d' if isinstance(value, list): def each(value): nonlocal key, command if isinstance(value, bool): if value: command = command + ' ' + key else: command = command + ' ' + key + ' "' + value + '"' _.for_each(value, each) else: if isinstance(value, bool): if value: command = command + ' ' + key else: command = command + ' ' + key + ' "' + value + '"' _.for_each(config, each) return command
def readUser(self): # version 1.0 consider 1 account in host try: col = "id" rs = self.db.execute("SELECT " + col + " FROM User limit 1") def parser(r): self.id = r[0] _.for_each(rs, parser) return {"res": True} except Exception as e: return {"e": e}
def __call__(self, request): response = self.get_response(request) if response.status_code != 302: def remove_session(key): try: del request.session[key] except KeyError: pass pydash.for_each(['_old_input', '_errors'], remove_session) return response
def on_settings_changed(self, section, name, value): """ Implemented from SettingsProvider. """ if section == "MinimapNotifications": if name == "enabled": self.__enabled = value _.for_each(database.get_all_vehicles(), lambda v: self.__render_to_minimap(v)) if name == "self_enabled": self.__self_enabled = value self.__render_to_minimap(database.get_my_vehicle()) if name == "action": self.__action = value if name == "repeat_interval": self.__interval = value
def sync(self, notes): try: if not notes: print("is Empty") return {"res": True} if not notes: return print("given 1 args(type=dict)") if not (type(notes) is dict): return print("args must be a dict") # question to user before processing sync self.db.execute('DELETE FROM Note') # clean self.conn.commit() # insert format { Text, WindowPosition, Id, ParentId, Theme, CreatedAt, UpdatedAt } # self.readUser() self.temp = notes print("update") def parser(k): cols = [ "Text", "WindowPosition", "Id", "ParentId", "Theme", "CreatedAt", "UpdatedAt" ] parms = [ self.temp[k]['Text'], self.temp[k]['WindowPosition'], uuid.uuid1(), self.id, self.temp[k]['Theme'], int(time.time()), int(time.time()) ] for index in range(0, len(parms)): parms[index] = "'{0}'".format(parms[index]) if self.debug: for index in range(0, len(cols)): print(cols[index], " = ", parms[index]) sql = "INSERT INTO Note ({0}) VALUES ({1})".format( _.join(cols, ','), _.join(parms, ",")) print("sql", sql) self.db.execute(sql) self.conn.commit() _.for_each(_.keys(notes), parser) print("sync") self.temp = None return {"res": True} except Exception as e: print("{0} sync, check this {0}".format(__file__, e)) return {"res": False}
def get_test_case_id(self, test_result): test_case = self.get_test_case_from_test_result(test_result) conf_file = test_case[ 'conf_file'] if 'conf_file' in test_case else self.get_conf_from_store( test_case) if not conf_file: return if "conf/" in conf_file: conf_file = conf_file.replace("conf/", '') test_cases = self.get_test_cases_from_conf(conf_file) test_cases_clone = pydash.clone_deep(test_cases) def remove_group(x): pydash.unset(x, 'GROUP') pydash.unset(x, 'commented') pydash.unset(x, 'testLine') test_cases_dict_without_groups = pydash.for_each( test_cases_clone, remove_group) callback = lambda x: set(x.items()).issubset(set(test_case.items())) index = pydash.find_index(test_cases_dict_without_groups, callback) if index == -1: return None name = test_cases[index] self.remove_unwanted_fields(name) return hashlib.md5(json.dumps(name, sort_keys=True)).hexdigest()
def convert(self, items): try: notes = {} def parser(r): self.noteCnt += 1 notes.update({ str(self.noteCnt): { "Text": r[0], "WindowPosition": r[1], "Theme": r[2] } }) _.for_each(items, parser) return {"res": notes} except Exception as e: return {"e": e}
def test_for_each(case, expected): assert _.for_each(*case) == expected
for page in range(0, 10): req_string = "https://api.github.com/search/users?page=" + str( page) + "&q=johnson&per_page=500" johnsons.append( requests.get(req_string, headers={ 'Authorization': 'token 6ca2047ccbab4ad1a2f472e35e2e659c8861bfb7' }).json()) print("got Johnsons") return (smiths, johnsons) (smiths, johnsons) = getPages() smithlogins = [] for page in smiths: pydash.for_each(page['items'], lambda x: smithlogins.append(x['login'])) johnsonlogins = [] for page in johnsons: pydash.for_each(page['items'], lambda x: johnsonlogins.append(x['login'])) logins = smithlogins + johnsonlogins loginstr = "\n".join(logins) resultfile = open('./data/github-users.csv', 'w') resultfile.write(loginstr) resultfile.close()
req_string = "https://api.github.com/search/users?page="+str(page)+"&q=smith&per_page=500" smiths.append(requests.get(req_string, headers = {'Authorization': 'token 6ca2047ccbab4ad1a2f472e35e2e659c8861bfb7'}).json()) print("got Smiths") print("Getting Johnsons...") johnsons = [] for page in range(0, 10): req_string = "https://api.github.com/search/users?page="+str(page)+"&q=johnson&per_page=500" johnsons.append(requests.get(req_string, headers = {'Authorization': 'token 6ca2047ccbab4ad1a2f472e35e2e659c8861bfb7'}).json()) print("got Johnsons") return (smiths, johnsons) (smiths, johnsons) = getPages() smithlogins = [] for page in smiths: pydash.for_each(page['items'], lambda x: smithlogins.append(x['login'])) johnsonlogins = [] for page in johnsons: pydash.for_each(page['items'], lambda x: johnsonlogins.append(x['login'])) logins = smithlogins + johnsonlogins loginstr = "\n".join(logins) resultfile = open('./data/github-users.csv', 'w') resultfile.write(loginstr) resultfile.close()