async def countall(client: Client, event: Command) -> None: """Stress DB in some way Examples: {cmd} """ waiting_message = await client.respond(event, 'AwangOWO DB') start_time = time.time() i = 0 async for dialog in client.iter_dialogs(): async for message in client.iter_messages(dialog, wait_time=0): try: result = client.db.query( 'For doc in BanList ' 'FILTER doc._key == @id ' 'RETURN doc', bind_vars={'id': str(message.sender_id)}) if not result: print('nope') print(f'{str(result)} at id {i}') i += 1 except: i += 1 stop_time = time.time() - start_time await client.respond(event, f'Took {stop_time:.02f}s and counted {str(i)}', reply=False) await waiting_message.delete()
def test_campaign_info_without_campaignId(self): data = {"customerId": self.customerId} data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success']) self.assertEqual(json['desc'], 'campaignId参数不能为空')
def test_account_balance_base(self): data = {"customerId": self.customerId} data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code'])
def test_campaign_info_base(self): data = {"customerId": self.customerId, "campaignId": self.campaignId} data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code']) self.assertEqual(str(json['result']['id']), str(data["campaignId"]))
def test_campaign_edit_budget_campaignid(self): data = { "customerId": self.customerId, "campaignId": RandomId.get_num(1000, 100000), "newval": "1000" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success'])
def test_campaign_list_sdate(self): data = { "customerId": self.customerId, "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url).send_request() json = request.json() self.assertEqual(0, json['code']) self.assertTrue(json['success'], msg='返回正常')
def test_creative_edit_list_base(self): data = { "customerId": self.customerId, "creativeIds": str(self.creativeId1) + "," + str(self.creativeId2), "newval": "2" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code'])
def test_report_audience_gender_data_base(self): data = { "customerId": self.customerId, "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code'])
def test_account_balance_base(self): data = {"agent": self.agentId} data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() if request: json = request.json() self.assertTrue(json['success']) for i in range(len(json['result']['list'])): for key, value in json['result']['list'][i].items(): if key == 'customerId' and value == self.customerId: self.assertTrue(True)
def test_creative_edit_bid_base(self): data = { "customerId": self.customerId, "creativeId": self.creativeId, "bidding": "{\"bid\":2,\"billingType\":1}" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() print(json) self.assertTrue(json['success']) self.assertEqual(0, json['code'])
def test_campaign_list_base(self): print("获取广告计划列表基础请求") data = { "customerId": self.customerId, "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(str(json['code']), str(0))
def test_campaign_edit_status_more_campaignid(self): data = { "customerId": self.customerId, "campaignIds": self.campaignId, "newval": "2" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code']) self.assertTrue(str(json['result'][0]['id']) in data['campaignIds'])
def test_account_edit_newDayThreshold_err(self): data = { "customerId": self.customerId, } shold = ('199', '199.99', '100000001', '100000000.01', '', ' ') for k in range(shold.__len__()): data.update({"newDayThreshold": shold[k]}) data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success']) self.assertEqual(20, json['code'])
async def main() -> None: """Register logger and components.""" config = Config() handler = TGChannelLogHandler(config.log_bot_token, config.log_channel_id) await handler.connect() tlog.addHandler(handler) client = Client(str(config.session_name), config.api_id, config.api_hash) # noinspection PyTypeChecker await client.start(config.phone) client.config = config client.kantek_version = __version__ client.plugin_mgr = PluginManager(client) client.plugin_mgr.register_all() logger.info('Connecting to Database') client.db = Database() await client.db.connect(config) tlog.info('Started Kantek v%s [%s]', __version__, helpers.link_commit(helpers.get_commit())) logger.info('Started Kantek v%s', __version__) if config.spamwatch_host and config.spamwatch_token: client.sw = SWClient(config.spamwatch_token, host=config.spamwatch_host) client.sw_url = config.spamwatch_host await client.run_until_disconnected()
def test_campaign_list_base_customerId_empty_1(self): print("获取广告计划列表customerId未传") data = { # "customerId": self.customerId, "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success']) self.assertEqual(str(json['code']), str(20)) self.assertEqual(str(json['msg']), str('参数错误')) self.assertEqual(str(json['desc']), str('customerId参数不能为空'))
def test_creative_test(self): data = { "customerId": self.customerId, "sdate": "2018-08-05", "edate": "2018-08-05" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) print(url) request = Client(url, method=self.method).send_request() json = request.json() print(json) self.assertTrue(json['success']) self.assertEqual(0, json['code']) self.log.debug("response " + str(json['result']))
def test_creative_edit_bid_creative_error(self): data = { "customerId": self.customerId, "bidding": "{\"bid\":2,\"billingType\":1}" } creative = ['', ' ', RandomId.get_num(1000, 10000)] data.update({"signId": self.signId}) for i in range(len(creative)): data.update({"creativeId": creative[i]}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() print(json) self.assertFalse(json['success'])
def test_campaign_list_base_customerId_empty_3(self): print("获取广告计划列表customerId与singId不匹配") data = { "customerId": '123', "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success']) self.assertEqual(str(json['code']), str(12)) self.assertEqual(str(json['msg']), str('错误的sign参数')) self.assertEqual(str(json['desc']), str('非法的账户信息'))
def run(self): from utils.client import Client from utils.crypto import HDPrivateKey client = Client() import_mnemonic = query_yes_no("Would you like to import an ethereum wallet using a mnemonic phrase?") if import_mnemonic: mnemonic = input("Enter mnemonic phrase: ") master_key = HDPrivateKey.master_key_from_mnemonic(mnemonic) else: master_key, mnemonic = HDPrivateKey.master_key_from_entropy() print("Generated wallet with mnemonic: %s" % mnemonic) client.config.attributes['mnemonic'] = mnemonic eth_net = self.query_network("Which ethereum network would you like to use?") print('Using ethereum network: %s' % eth_net) client.config.attributes['eth_net'] = eth_net default_gas_price = self.query_default_gas_price("Default gas price in gwei:") print('Using default gas price: %dgwei' % default_gas_price) client.config.attributes['default_gas_price'] = str(int(default_gas_price) * denoms.gwei) client.config.attributes['ipfs_gateway'] = '127.0.0.1' client.config.attributes['infura_token'] = 'nuux6RAf126jNtpRZJO0' client.config.write()
async def puge(client: Client, chat: Channel, msg: Message, args, event) -> None: """Purge all messages from the the point the command was sent to the message that was replied to. Arguments: `count`: Delete `count` messages Examples: {cmd} """ await msg.delete() if not msg.is_reply: if args: count = args[0] message_ids = [msg.id] async for m in client.iter_messages(chat, limit=count, offset_id=msg.id): message_ids.append(m.id) else: return else: reply_msg: Message = await msg.get_reply_message() if event.is_private: message_ids = await client.get_messages(chat, min_id=reply_msg.id, max_id=msg.id) else: message_ids = list(range(reply_msg.id, msg.id)) await client.delete_messages(chat, message_ids)
def test_campaign_list_kw(self): print('kw关键字正常校验') kw = ['', '商店', 100030663, 'hfdsajdkas', '1234hhh'] data = { "customerId": self.customerId, # "kw": "非商店", "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) for i in range(len(kw)): data.update({"kw": kw[i]}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url).send_request().json() self.assertTrue(request['success']) self.assertEqual(request['code'], 0) r = False # if kw[i] != '' or not isinstance(kw[i], int): # for j in range(len(request['result']['list'])): # for keys, values in request['result']['list'][j].items(): # if request['result']['list'][j] and keys == 'name' and kw[i] in values: # r = True # self.assertTrue(r) if request['result']['list']: for j in range(len(request['result']['list'])): for key, value in request['result']['list'][j].items(): if kw[i] != '' or not isinstance(kw[i], int): if key == 'name' and kw[i] in value: r = True if kw[i] != '' and isinstance(kw[i], int): if key == 'id' and kw[i] == value: r = True self.assertTrue(r)
def test_campaign_edit_budget_base(self): data = { "customerId": self.customerId, "campaignId": self.campaignId[RandomId.get_num(m=len(self.campaignId)) - 1], "newval": "1000" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code']) self.assertEqual(str(data['newval']), str(json['result']))
def __init__(self, parent=None, software=None): super(MainWindow, self).__init__(parent=parent) self.setupUi(self) # CONSTANTS self.user = getpass.getuser() self.software = software if self.software: mod = '.softs.%s.attachment' % self.software self.attachment_module = importlib.import_module(mod, 'client') # self.user = '******' # self.notif_sound = QtMultimedia.QSound( # os.path.join(SCRIPT_PATH, 'src', 'notification.wav')) self.commands = { 'fetch_messages': self.fetch_messages, 'fetch_users': self.fetch_users, 'new_message': self.new_message, } # CLIENT url = '%s:%s?user=%s&soft=%s' % (URL, PORT, self.user, self.software) self.client_manager = Client(url=url) # MAILBOX HEADER header_mailbox = QtWidgets.QHeaderView( QtCore.Qt.Horizontal, self.trw_mailbox) self.trw_mailbox.setHeader(header_mailbox) header_mailbox.setSectionResizeMode( 0, QtWidgets.QHeaderView.Stretch) header_mailbox.setSectionResizeMode( 1, QtWidgets.QHeaderView.ResizeToContents) header_mailbox.setSectionsClickable(True) # CASCADING STYLE SHEET self.set_style_sheet() # SIGNALS self.client_manager.client.textMessageReceived.connect( self._receive_data) self.pub_import_attachment.clicked.connect(self.import_attachment) self.pub_send.clicked.connect(self.send_message) self.lie_search_receiver.textChanged.connect(self.search_receiver) self.trw_mailbox.itemClicked.connect(self.show_message_from_mailbox) self.trw_mailbox.customContextMenuRequested.connect( self.context_menu_mailbox)
def test_campaign_edit_budget_newval(self): data = { "customerId": self.customerId, "campaignId": self.campaignId[RandomId.get_num(m=len(self.campaignId)) - 1], } data.update({"signId": self.signId}) n = ('-1', '199', '199.9', '100000000.99', '100000001', '', ' ') for k in n: data.update({"newval": k}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertFalse(json['success']) print(json)
def test_campaign_edit_status_base(self): self.campaignId = str(self.campaignId).split(',') data = { "customerId": self.customerId, "campaignIds": self.campaignId[RandomId.get_num(0, len(self.campaignId))], # "campaignIds": "100038746", "newval": "1" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code'])
def test_creative_edit_bid_bid_error(self): data = { "customerId": self.customerId, "creativeId": self.creativeId, "bidding": "{\"bid\":200,\"billingType\":1}" } data.update({"signId": self.signId}) bid = ['', '0.01', '1000', 't'] for i in range(len(bid)): data.update( {'bid': "{\"bid\":" + str(bid[i]) + ",\"billingType\":1}"}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() print(json) self.assertFalse(json['success'])
def test_group_list_base(self): data = { "customerId": self.customerId, "groupIds": self.groupId1 + ',' + self.groupId2, "newval": "2" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri+self.port), d=data) request = Client(url, method=self.method).send_request() json = request.json() self.assertTrue(json['success']) self.assertEqual(0, json['code']) for i in range(len(json['result'])): if json['result'][i]['id'] == self.groupId1 or json['result'][i]['id'] == self.groupId2: if data['newval'] == json['result'][i]['result']: self.assertTrue(True) else: self.assertFalse(False)
def test_campaign_list_status(self): data = { "customerId": self.customerId, "status": "1", "sdate": Time().count_datetime(self.time, self.sub), "edate": Time().count_datetime(self.time, self.sub) } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url).send_request() self.assertEqual(200, request.status_code)
def test_single(self): data = { "customerId": self.customerId, # "customerId": "12", # "campaignIds": "100000098,100000711,100001265", "kw": "100038745", "sdate": "2018-07-16", "edate": "2018-07-16" } data.update({"signId": self.signId}) url = GenerateURL().generate_url(u=str(self.uri + self.port), d=data) request = Client(url, method=self.method).send_request() j = request.json() # print(j) print(j) for i in range(len(j['result']['list'])): for key, values in j['result']['list'][i].items(): print(str(key) + ": " + str(values)) print('\n') # print(j['msg']) print(j['result']['list'])
def main(): # variables client = Client() args = parse_argv() # set default val of args args.path = '.' if args.path == None else args.path args.path = args.path[:-1] if args.path[-1] == '/' else args.path client.add(list=args.list, path=args.path) client.run(threads=args.threads) # check extension exts = list( set([ task['file'][task['file'].find('.') + 1:] for task in client.tasks ])) if len(exts) > 1: print('Inconsistent extension') exit() # merge into single video infiles = glob.glob('%s/*.%s' % (args.path, exts[0])) infiles.sort() with open('%s/%s.%s' % (args.path, args.outfile, exts[0]), 'wb') as output: for infile in infiles: with open(infile, 'rb') as input: output.write(input.read())