How to use write_json method in localstack

Best Python code snippet using localstack_python

tune.py

Source:tune.py Github

copy

Full Screen

1from selfdrive.kegman_conf import kegman_conf2import subprocess3import os4BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../"))5letters = { "a":[ "###", "# #", "###", "# #", "# #"], "b":[ "###", "# #", "###", "# #", "###"], "c":[ "###", "#", "#", "#", "###"], "d":[ "##", "# #", "# #", "# #", "##"], "e":[ "###", "#", "###", "#", "###"], "f":[ "###", "#", "###", "#", "#"], "g":[ "###", "# #", "###", " #", "###"], "h":[ "# #", "# #", "###", "# #", "# #"], "i":[ "###", " #", " #", " #", "###"], "j":[ "###", " #", " #", " #", "##"], "k":[ "# #", "##", "#", "##", "# #"], "l":[ "#", "#", "#", "#", "###"], "m":[ "# #", "###", "###", "# #", "# #"], "n":[ "###", "# #", "# #", "# #", "# #"], "o":[ "###", "# #", "# #", "# #", "###"], "p":[ "###", "# #", "###", "#", "#"], "q":[ "###", "# #", "###", " #", " #"], "r":[ "###", "# #", "##", "# #", "# #"], "s":[ "###", "#", "###", " #", "###"], "t":[ "###", " #", " #", " #", " #"], "u":[ "# #", "# #", "# #", "# #", "###"], "v":[ "# #", "# #", "# #", "# #", " #"], "w":[ "# #", "# #", "# #", "###", "###"], "x":[ "# #", " #", " #", " #", "# #"], "y":[ "# #", "# #", "###", " #", "###"], "z":[ "###", " #", " #", "#", "###"], " ":[ " "], "1":[ " #", "##", " #", " #", "###"], "2":[ "###", " #", "###", "#", "###"], "3":[ "###", " #", "###", " #", "###"], "4":[ "#", "#", "# #", "###", " #"], "5":[ "###", "#", "###", " #", "###"], "6":[ "###", "#", "###", "# #", "###"], "7":[ "###", " # ", " #", " #", "#"], "8":[ "###", "# #", "###", "# #", "###"], "9":[ "###", "# #", "###", " #", "###"], "0":[ "###", "# #", "# #", "# #", "###"], "!":[ " # ", " # ", " # ", " ", " # "], "?":[ "###", " #", " ##", " ", " # "], ".":[ " ", " ", " ", " ", " # "], "]":[ " ", " ", " ", " #", " # "], "/":[ " #", " #", " # ", "# ", "# "], ":":[ " ", " # ", " ", " # ", " "], "@":[ "###", "# #", "## ", "# ", "###"], "'":[ " # ", " # ", " ", " ", " "], "#":[ " # ", "###", " # ", "###", " # "], "-":[ " ", " ","###"," "," "] }6# letters stolen from here: http://www.stuffaboutcode.com/2013/08/raspberry-pi-minecraft-twitter.html7def print_letters(text):8 bigletters = []9 for i in text:10 bigletters.append(letters.get(i.lower(),letters[' ']))11 output = ['']*512 for i in range(5):13 for j in bigletters:14 temp = ' '15 try:16 temp = j[i]17 except:18 pass19 temp += ' '*(5-len(temp))20 temp = temp.replace(' ',' ')21 temp = temp.replace('#','@')22 output[i] += temp23 return '\n'.join(output)24import sys, termios, tty, os, time25def getch():26 fd = sys.stdin.fileno()27 old_settings = termios.tcgetattr(fd)28 try:29 tty.setraw(sys.stdin.fileno())30 ch = sys.stdin.read(1)31 finally:32 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)33 return ch34button_delay = 0.235kegman = kegman_conf()36kegman.conf['tuneGernby'] = "1"37#kegman.write_config(kegman.conf)38param = ["Kp", "Ki", "Kf", "Kp2", "Ki2", "Kf2", "steerRatio", "steerRateCost", \39 "sR_boost", "sR_BP0", "sR_BP1", "sR_time", \40 "sR_Kp", "sR_Ki", "sR_Kf", \41 "sR_Kp2", "sR_Ki2", "sR_Kf2"]42j = 043while True:44 print ("")45 print (print_letters(param[j][0:9]))46 print ("")47 print (print_letters(kegman.conf[param[j]]))48 print ("")49 print ("1,3,5,7,r to incr 0.1,0.05,0.01,0.001,0.00001")50 print ("a,d,g,j,v to decr 0.1,0.05,0.01,0.001,0.00001")51 print ("P,I,B,R,K to decr kp,ki,sR_boost,steerRatio,sR_Kp")52 print ("0 / L to make the value 0 / 1")53 print ("press SPACE / m for next /prev parameter")54 print ("press z to quit")55 char = getch()56 write_json = False57 if (char == "P"):58 j = 059 elif (char == "I"):60 j = 161 elif (char == "R"):62 j = 363 elif (char == "B"):64 j = 565 elif (char == "K"):66 j = 967 if (char == "v"):68 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) - 0.00001),5))69 write_json = True70 if (char == "r"):71 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) + 0.00001),5))72 write_json = True73 74 if (char == "7"):75 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) + 0.001),5))76 write_json = True77 if (char == "5"):78 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) + 0.01),5))79 write_json = True80 elif (char == "3"):81 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) + 0.05),5))82 write_json = True83 elif (char == "1"):84 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) + 0.1),5))85 write_json = True86 elif (char == "j"):87 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) - 0.001),5))88 write_json = True89 elif (char == "g"):90 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) - 0.01),5))91 write_json = True92 elif (char == "d"):93 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) - 0.05),5))94 write_json = True95 elif (char == "a"):96 kegman.conf[param[j]] = str(round((float(kegman.conf[param[j]]) - 0.1),5))97 write_json = True98 elif (char == "0"):99 kegman.conf[param[j]] = "0"100 write_json = True101 elif (char == "l"):102 kegman.conf[param[j]] = "1"103 write_json = True104 elif (char == " "):105 if j < len(param) - 1:106 j = j + 1107 else:108 j = 0109 elif (char == "m"):110 if j > 0:111 j = j - 1112 else:113 j = len(param) - 1114 elif (char == "z"):115 #process.kill()116 exit(1) 117 break118 if float(kegman.conf['tuneGernby']) != 1 and float(kegman.conf['tuneGernby']) != 0:119 kegman.conf['tuneGernby'] = "1"120 if float(kegman.conf['Ki']) < 0 and float(kegman.conf['Ki']) != -1:121 kegman.conf['Ki'] = "0"122 if float(kegman.conf['Ki']) > 2:123 kegman.conf['Ki'] = "2"124 if float(kegman.conf['Ki2']) < 0 and float(kegman.conf['Ki2']) != -1:125 kegman.conf['Ki2'] = "0"126 if float(kegman.conf['Ki2']) > 2:127 kegman.conf['Ki2'] = "2" 128 if float(kegman.conf['Kp']) < 0 and float(kegman.conf['Kp']) != -1:129 kegman.conf['Kp'] = "0"130 if float(kegman.conf['Kp']) > 3:131 kegman.conf['Kp'] = "3"132 if float(kegman.conf['Kp2']) < 0 and float(kegman.conf['Kp2']) != -1:133 kegman.conf['Kp2'] = "0"134 if float(kegman.conf['Kp2']) > 3:135 kegman.conf['Kp2'] = "3" 136 if float(kegman.conf['Kf']) > 0.01:137 kegman.conf['Kf'] = "0.01" 138 139 if float(kegman.conf['Kf']) < 0:140 kegman.conf['Kf'] = "0"141 if float(kegman.conf['Kf2']) > 0.01:142 kegman.conf['Kf2'] = "0.01" 143 144 if float(kegman.conf['Kf2']) < 0:145 kegman.conf['Kf2'] = "0"146 147 if float(kegman.conf['sR_Kp']) < 0:148 kegman.conf['sR_Kp'] = "0" 149 if float(kegman.conf['sR_Kp']) > 3:150 kegman.conf['sR_Kp'] = "3"151 if float(kegman.conf['sR_Kp2']) < 0:152 kegman.conf['sR_Kp2'] = "0" 153 if float(kegman.conf['sR_Kp2']) > 3:154 kegman.conf['sR_Kp2'] = "3" 155 if float(kegman.conf['sR_Ki']) < 0:156 kegman.conf['sR_Ki'] = "0" 157 if float(kegman.conf['sR_Ki']) > 2:158 kegman.conf['sR_Ki'] = "2" 159 if float(kegman.conf['sR_Ki2']) < 0:160 kegman.conf['sR_Ki2'] = "0" 161 if float(kegman.conf['sR_Ki2']) > 2:162 kegman.conf['sR_Ki2'] = "2" 163 if float(kegman.conf['sR_Kf']) > 0.01:164 kegman.conf['sR_Kf'] = "0.01" 165 166 if float(kegman.conf['sR_Kf']) < 0:167 kegman.conf['sR_Kf'] = "0" 168 if float(kegman.conf['sR_Kf2']) > 0.01:169 kegman.conf['sR_Kf2'] = "0.01" 170 171 if float(kegman.conf['sR_Kf2']) < 0:172 kegman.conf['sR_Kf2'] = "0"173 174 175 if float(kegman.conf['steerRatio']) < 1 and float(kegman.conf['steerRatio']) != -1:176 kegman.conf['steerRatio'] = "1"177 178 if float(kegman.conf['steerRateCost']) < 0.01 and float(kegman.conf['steerRateCost']) != -1:179 kegman.conf['steerRateCost'] = "0.01"180 181 if float(kegman.conf['deadzone']) < 0:182 kegman.conf['deadzone'] = "0"183 184 185 if float(kegman.conf['sR_boost']) < 0:186 kegman.conf['sR_boost'] = "0"187 188 if float(kegman.conf['sR_BP0']) < 0:189 kegman.conf['sR_BP0'] = "0"190 191 if float(kegman.conf['sR_BP1']) < 0:192 kegman.conf['sR_BP1'] = "0"193 194 if float(kegman.conf['sR_time']) < 0.1:195 kegman.conf['sR_time'] = "0.1"196 #if float(kegman.conf['Kf']) < 0.00001:197 kegman.conf['Kf'] = str("{:.5f}".format(float(kegman.conf['Kf'])))198 kegman.conf['sR_Kf'] = str("{:.5f}".format(float(kegman.conf['sR_Kf'])))199 if write_json:200 kegman.write_config(kegman.conf)201 time.sleep(button_delay)202else:203 exit(1)...

Full Screen

Full Screen

group.py

Source:group.py Github

copy

Full Screen

...6class DoUpdateGroupHandler(TPBaseJsonHandler):7 def post(self):8 args = self.get_argument('args', None)9 if args is None:10 return self.write_json(TPE_PARAM)11 try:12 args = json.loads(args)13 except:14 return self.write_json(TPE_JSON_FORMAT)15 try:16 gtype = int(args['gtype'])17 gid = int(args['gid'])18 name = args['name']19 desc = args['desc']20 except:21 return self.write_json(TPE_PARAM)22 if gid == -1:23 err, _ = group.create(self, gtype, name, desc)24 else:25 err = group.update(self, gid, name, desc)26 self.write_json(err)27class DoLockGroupHandler(TPBaseJsonHandler):28 def post(self):29 args = self.get_argument('args', None)30 if args is None:31 return self.write_json(TPE_PARAM)32 try:33 args = json.loads(args)34 except:35 return self.write_json(TPE_JSON_FORMAT)36 try:37 gtype = args['gtype']38 glist = args['glist']39 except:40 return self.write_json(TPE_PARAM)41 err = group.update_groups_state(self, gtype, glist, TP_STATE_DISABLED)42 self.write_json(err)43class DoUnlockGroupHandler(TPBaseJsonHandler):44 def post(self):45 args = self.get_argument('args', None)46 if args is None:47 return self.write_json(TPE_PARAM)48 try:49 args = json.loads(args)50 except:51 return self.write_json(TPE_JSON_FORMAT)52 try:53 gtype = args['gtype']54 glist = args['glist']55 except:56 return self.write_json(TPE_PARAM)57 err = group.update_groups_state(self, gtype, glist, TP_STATE_NORMAL)58 self.write_json(err)59class DoRemoveGroupHandler(TPBaseJsonHandler):60 def post(self):61 args = self.get_argument('args', None)62 if args is None:63 return self.write_json(TPE_PARAM)64 try:65 args = json.loads(args)66 except:67 return self.write_json(TPE_JSON_FORMAT)68 try:69 gtype = args['gtype']70 glist = args['glist']71 except:72 return self.write_json(TPE_PARAM)73 err = group.remove(self, gtype, glist)74 self.write_json(err)75class DoAddMembersHandler(TPBaseJsonHandler):76 def post(self):77 args = self.get_argument('args', None)78 if args is None:79 return self.write_json(TPE_PARAM)80 try:81 args = json.loads(args)82 except:83 return self.write_json(TPE_JSON_FORMAT)84 try:85 gtype = int(args['gtype'])86 gid = int(args['gid'])87 members = args['members']88 except:89 return self.write_json(TPE_PARAM)90 err = group.add_members(gtype, gid, members)91 self.write_json(err)92class DoRemoveMembersHandler(TPBaseJsonHandler):93 def post(self):94 args = self.get_argument('args', None)95 if args is None:96 return self.write_json(TPE_PARAM)97 try:98 args = json.loads(args)99 except:100 return self.write_json(TPE_JSON_FORMAT)101 try:102 gtype = int(args['gtype'])103 gid = int(args['gid'])104 members = args['members']105 except:106 return self.write_json(TPE_PARAM)107 err = group.remove_members(gtype, gid, members)108 self.write_json(err)109class DoGetGroupsHandler(TPBaseJsonHandler):110 def post(self):111 # ret = self.check_privilege(TP_PRIVILEGE_USER_GROUP)112 # if ret != TPE_OK:113 # return114 args = self.get_argument('args', None)115 if args is None:116 return self.write_json(TPE_PARAM)117 try:118 args = json.loads(args)119 except:120 return self.write_json(TPE_JSON_FORMAT)121 # print('---get groups:', args)122 sql_filter = {}123 sql_order = dict()124 sql_order['name'] = 'id'125 sql_order['asc'] = True126 sql_limit = dict()127 sql_limit['page_index'] = 0128 sql_limit['per_page'] = 25129 sql_restrict = args['restrict'] if 'restrict' in args else {}130 sql_exclude = args['exclude'] if 'exclude' in args else {}131 try:132 tmp = list()133 _filter = args['filter']134 for i in _filter:135 if i == 'search':136 _x = _filter[i].strip()137 if len(_x) == 0:138 tmp.append(i)139 continue140 for i in tmp:141 del _filter[i]142 sql_filter.update(_filter)143 # sql_filter.update(args['filter'])144 _limit = args['limit']145 if _limit['page_index'] < 0:146 _limit['page_index'] = 0147 if _limit['per_page'] < 10:148 _limit['per_page'] = 10149 if _limit['per_page'] > 100:150 _limit['per_page'] = 100151 sql_limit.update(_limit)152 _order = args['order']153 if _order is not None:154 sql_order['name'] = _order['k']155 sql_order['asc'] = _order['v']156 except:157 return self.write_json(TPE_PARAM)158 err, total_count, page_index, row_data = group.get_groups(sql_filter, sql_order, sql_limit, sql_restrict, sql_exclude)159 ret = dict()160 ret['page_index'] = page_index161 ret['total'] = total_count162 ret['data'] = row_data...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful