Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_five_acccount_ids(self, test_server):
accounts = []
for i in range(1, 6):
payload = {"emailAddress": f"test{i}@example.com", "password": "1234567"}
res = test_server.post("/signup", data=ujson.dumps(payload))
resData = res.json()
accounts.append(resData["id"])
return accounts
def get_hash(obj):
return hashlib.shake_128(json.dumps(obj).encode("utf-8")).hexdigest(16)
def test_on_message_when_type_message(self):
redis, app, bus = self.get_bus()
handler_mock = Mock()
bus.throttling = {}
bus.handlers['events']['uuid'] = handler_mock
value = dumps({'type': 'test'})
bus.on_message(('message', 'events', value))
expect(handler_mock.called).to_be_true()
def write_data_to_file(output_file: Path, data: Any) -> None:
with open(output_file, "w") as f:
f.write(ujson.dumps(data, indent=4))
:param method: data process method: 'normal', 'call', 'ctrl'
:return: None
"""
if not data_pairs:
return
try:
for data_time, protocol_code, data_value in data_pairs:
map_key = 'HS:MAPPING:{}:{}:{}'.format(self.device_info['protocol'].upper(),
self.device_id, protocol_code)
term_item = self.redis_client.hgetall(map_key)
if not term_item:
logger.debug("DEVICE[%s] precess_data: can't found term_item, key=%s", self.device_id, map_key)
continue
if 'coefficient' in term_item and 'base_val' in term_item:
data_value = data_value * float(term_item['coefficient']) + float(term_item['base_val'])
json_data = json.dumps({
'device_id': self.device_id, 'term_id': term_item['term_id'], 'item_id': term_item['item_id'],
'time': data_time.isoformat(), 'value': data_value,
})
pub_channel = 'CHANNEL:DEVICE_{}:{}:{}:{}'.format(
method.upper(), self.device_id, term_item['term_id'], term_item['item_id'])
if method == 'data':
data_key = "{}:{}:{}".format(
self.device_id, term_item['term_id'], term_item['item_id'])
time_str = data_time.isoformat()
self.redis_client.hset("HS:DATA:{}".format(data_key), time_str, data_value)
self.redis_client.rpush("LST:DATA_TIME:{}".format(data_key), time_str)
rst = self.redis_client.publish(pub_channel, json_data)
logger.debug('pub to %s, val=%s, rst=%s', pub_channel, json_data, rst)
except Exception as e:
logger.exception(e)
Args:
listens : the listens to be written into the disk
temp_dir: the dir into which listens should be written
"""
for year in unwritten_listens:
for month in unwritten_listens[year]:
if year < 2002:
directory = temp_dir
filename = os.path.join(directory, 'invalid.json')
else:
directory = os.path.join(temp_dir, str(year))
filename = os.path.join(directory, '{}.json'.format(str(month)))
create_path(directory)
with open(filename, 'a') as f:
f.write('\n'.join([ujson.dumps(listen) for listen in unwritten_listens[year][month]]))
f.write('\n')
"media-src {}".format(' '.join(relay_hostnames)),
"font-src 'self' data: https://fonts.googleapis.com https://fonts.gstatic.com/",
"connect-src wss://websocket.rainwave.cc",
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com"
])
station_list = {}
for station_id in station_ids:
station_list[station_id] = {
"id": station_id,
"name": station_id_friendly[station_id],
"url": "{}{}/".format(get("base_site_url"), station_mount_filenames[station_id])
}
station_mounts[get_station(station_id, "stream_filename") + ".mp3"] = station_id
station_mounts[get_station(station_id, "stream_filename") + ".ogg"] = station_id
station_list_json = json.dumps(station_list, ensure_ascii=False)
build_number = get_build_number()
# add brand enrichments
if args.brand_info is not None:
do_brand_enrichments = True
brands = get_brand_info(args.brand_info)
else:
do_brand_enrichments = False
for conversation_payload in build_conversations(args.max_in_memory_value, args.input, db_name, drop_if_nonempty):
# optionally update enrichments in the conversation payload
if args.add_enrichments:
# add enrichments
conversation_payload = add_enrichments.add_enrichments(conversation_payload)
if do_brand_enrichments:
conversation_payload = add_enrichments.add_brand_enrichments(conversation_payload, brands)
print(ujson.dumps(conversation_payload))
def set_option(self, key, value):
if key and value:
options = self.get_options()
options[key] = value
self.options = json.dumps(options)