Best Python code snippet using yandex-tank
tgapi.py
Source:tgapi.py
...28 def __repr__(self):29 return f"bot<{self.__name}>"30 @with_info(_log_api, begin='', report_params=True)31 @log_exceptions32 def __post(self, command, params=None):33 r = post(self.url + command, params, self.proxy)34 if not r['ok']:35 raise Exception('Bad Requests')36 return r['result']37 def shutdown(self):38 del self39 # properties40 @property41 def token(self):42 return self.__token43 @property44 def proxy(self):45 return self.__proxy46 @property47 def url(self):48 return f"https://api.telegram.org/bot{self.__token}/"49 @property50 def name(self):51 return f"https://api.telegram.org/bot{self.__name}/"52 # API functions53 @with_return(User)54 def getMe(self):55 return self.__post('getMe')56 def getUpdates(self, **argv):57 params_table = {58 'offset': int,59 'limit': int,60 'timeout': int,61 'allowed_updates': list,62 }63 verify_params(params_table, argv)64 return [Update(x) for x in self.__post('getUpdates', argv)]65 def setWebhook(self, url, **argv):66 params_table = {67 'url': str,68 'certificate': InputFile,69 'ip_address': str,70 'max_connections': int,71 'allowed_updates': list,72 'drop_pending_updates': bool,73 }74 argv['url'] = url75 verify_params(params_table, argv)76 return self.__post('setWebhook', argv)77 def deleteWebhook(self, **argv):78 params_table = {79 'drop_pending_updates': bool,80 }81 verify_params(params_table, argv)82 return self.__post('deleteWebhook', argv)83 def getWebhookInfo(self):84 return WebhookInfo(self.__post('getWebhookInfo'))85 def sendMessage(self, chat_id, text, **argv):86 params_table = {87 'chat_id': [int, str],88 'text': str,89 'parse_mode': str,90 'entities': list,91 'disable_web_page_preview': bool,92 'disable_notification': bool,93 'protect_content': bool,94 'reply_to_message_id': int,95 'allow_sending_without_reply': bool,96 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],97 }98 argv['chat_id'] = chat_id99 argv['text'] = text100 verify_params(params_table, argv)101 return Message(self.__post('sendMessage', argv))102 def forwardMessage(self, chat_id, from_chat_id, message_id, **argv):103 params_table = {104 'chat_id': [int, str],105 'from_chat_id': [int, str],106 'disable_notification': bool,107 'protect_content': bool,108 'message_id': int,109 }110 argv['chat_id'] = chat_id111 argv['from_chat_id'] = from_chat_id112 argv['message_id'] = message_id113 verify_params(params_table, argv)114 return Message(self.__post('forwardMessage', argv))115 def copyMessage(self, chat_id, from_chat_id, message_id, **argv):116 params_table = {117 'chat_id': [int, str],118 'from_chat_id': [int, str],119 'message_id': int,120 'caption': str,121 'parse_mode': str,122 'caption_entities': list,123 'disable_notification': bool,124 'protect_content': bool,125 'reply_to_message_id': int,126 'allow_sending_without_reply': bool,127 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],128 }129 argv['chat_id'] = chat_id130 argv['from_chat_id'] = from_chat_id131 argv['message_id'] = message_id132 verify_params(params_table, argv)133 return MessageId(self.__post('copyMessage', argv))134 def sendPhoto(self, chat_id, photo, **argv):135 params_table = {136 'chat_id': [int, str],137 'photo': [InputFile, str],138 'caption': str,139 'parse_mode': str,140 'caption_entities': list,141 'disable_notification': bool,142 'protect_content': bool,143 'reply_to_message_id': int,144 'allow_sending_without_reply': bool,145 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],146 }147 argv['chat_id'] = chat_id148 argv['photo'] = photo149 verify_params(params_table, argv)150 return Message(self.__post('sendPhoto', argv))151 def sendAudio(self, chat_id, audio, **argv):152 params_table = {153 'chat_id': [int, str],154 'audio': [InputFile, str],155 'caption': str,156 'parse_mode': str,157 'caption_entities': list,158 'duration': int,159 'performer': str,160 'title': str,161 'thumb': [InputFile, str],162 'disable_notification': bool,163 'protect_content': bool,164 'reply_to_message_id': int,165 'allow_sending_without_reply': bool,166 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],167 }168 argv['chat_id'] = chat_id169 argv['audio'] = audio170 verify_params(params_table, argv)171 return Message(self.__post('sendAudio', argv))172 def sendDocument(self, chat_id, document, **argv):173 params_table = {174 'chat_id': [int, str],175 'document': [InputFile, str],176 'thumb': [InputFile, str],177 'caption': str,178 'parse_mode': str,179 'caption_entities': list,180 'disable_content_type_detection': bool,181 'disable_notification': bool,182 'protect_content': bool,183 'reply_to_message_id': int,184 'allow_sending_without_reply': bool,185 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],186 }187 argv['chat_id'] = chat_id188 argv['document'] = document189 verify_params(params_table, argv)190 return Message(self.__post('sendDocument', argv))191 def sendVideo(self, chat_id, video, **argv):192 params_table = {193 'chat_id': [int, str],194 'video': [InputFile, str],195 'duration': int,196 'width': int,197 'height': int,198 'thumb': [InputFile, str],199 'caption': str,200 'parse_mode': str,201 'caption_entities': list,202 'supports_streaming': bool,203 'disable_notification': bool,204 'protect_content': bool,205 'reply_to_message_id': int,206 'allow_sending_without_reply': bool,207 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],208 }209 argv['chat_id'] = chat_id210 argv['video'] = video211 verify_params(params_table, argv)212 return Message(self.__post('sendVideo', argv))213 def sendAnimation(self, chat_id, animation, **argv):214 params_table = {215 'chat_id': [int, str],216 'animation': [InputFile, str],217 'duration': int,218 'width': int,219 'height': int,220 'thumb': [InputFile, str],221 'caption': str,222 'parse_mode': str,223 'caption_entities': list,224 'disable_notification': bool,225 'protect_content': bool,226 'reply_to_message_id': int,227 'allow_sending_without_reply': bool,228 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],229 }230 argv['chat_id'] = chat_id231 argv['animation'] = animation232 verify_params(params_table, argv)233 return Message(self.__post('sendAnimation', argv))234 def sendVoice(self, chat_id, voice, **argv):235 params_table = {236 'chat_id': [int, str],237 'voice': [InputFile, str],238 'caption': str,239 'parse_mode': str,240 'caption_entities': list,241 'duration': int,242 'disable_notification': bool,243 'protect_content': bool,244 'reply_to_message_id': int,245 'allow_sending_without_reply': bool,246 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],247 }248 argv['chat_id'] = chat_id249 argv['voice'] = voice250 verify_params(params_table, argv)251 return Message(self.__post('sendVoice', argv))252 def sendVideoNote(self, chat_id, video_note, **argv):253 params_table = {254 'chat_id': [int, str],255 'video_note': [InputFile, str],256 'duration': int,257 'length': int,258 'thumb': [InputFile, str],259 'disable_notification': bool,260 'protect_content': bool,261 'reply_to_message_id': int,262 'allow_sending_without_reply': bool,263 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],264 }265 argv['chat_id'] = chat_id266 argv['video_note'] = video_note267 verify_params(params_table, argv)268 return Message(self.__post('sendVideoNote', argv))269 def sendMediaGroup(self, chat_id, media, **argv):270 params_table = {271 'chat_id': [int, str],272 'media': list,273 'disable_notification': bool,274 'protect_content': bool,275 'reply_to_message_id': int,276 'allow_sending_without_reply': bool,277 }278 argv['chat_id'] = chat_id279 argv['media'] = media280 verify_params(params_table, argv)281 return Message(self.__post('sendMediaGroup', argv))282 def sendLocation(self, chat_id, latitude, longitude, **argv):283 params_table = {284 'chat_id': [int, str],285 'latitude': float,286 'longitude': float,287 'horizontal_accuracy': float,288 'live_period': int,289 'heading': int,290 'proximity_alert_radius': int,291 'disable_notification': bool,292 'protect_content': bool,293 'reply_to_message_id': int,294 'allow_sending_without_reply': bool,295 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],296 }297 argv['chat_id'] = chat_id298 argv['latitude'] = latitude299 argv['longitude'] = longitude300 verify_params(params_table, argv)301 return Message(self.__post('sendLocation', argv))302 def editMessageLiveLocation(self, latitude, longitude, **argv):303 params_table = {304 'chat_id': [int, str],305 'message_id': int,306 'inline_message_id': str,307 'latitude': float,308 'longitude': float,309 'horizontal_accuracy': float,310 'heading': int,311 'proximity_alert_radius': int,312 'reply_markup': InlineKeyboardMarkup,313 }314 argv['latitude'] = latitude315 argv['longitude'] = longitude316 verify_params(params_table, argv)317 return self.__post('editMessageLiveLocation', argv)318 def stopMessageLiveLocation(self, **argv):319 params_table = {320 'chat_id': [int, str],321 'message_id': int,322 'inline_message_id': str,323 'reply_markup': InlineKeyboardMarkup,324 }325 verify_params(params_table, argv)326 return self.__post('stopMessageLiveLocation', argv)327 def sendVenue(self, chat_id, latitude, longitude, title, address, **argv):328 params_table = {329 'chat_id': [int, str],330 'latitude': float,331 'longitude': float,332 'title': str,333 'address': str,334 'foursquare_id': str,335 'foursquare_type': str,336 'google_place_id': str,337 'google_place_type': str,338 'disable_notification': bool,339 'protect_content': bool,340 'reply_to_message_id': int,341 'allow_sending_without_reply': bool,342 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],343 }344 argv['chat_id'] = chat_id345 argv['latitude'] = latitude346 argv['longitude'] = longitude347 argv['title'] = title348 argv['address'] = address349 verify_params(params_table, argv)350 return Message(self.__post('sendVenue', argv))351 def sendContact(self, chat_id, phone_number, first_name, **argv):352 params_table = {353 'chat_id': [int, str],354 'phone_number': str,355 'first_name': str,356 'last_name': str,357 'vcard': str,358 'disable_notification': bool,359 'protect_content': bool,360 'reply_to_message_id': int,361 'allow_sending_without_reply': bool,362 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],363 }364 argv['chat_id'] = chat_id365 argv['phone_number'] = phone_number366 argv['first_name'] = first_name367 verify_params(params_table, argv)368 return Message(self.__post('sendContact', argv))369 def sendPoll(self, chat_id, question, options, **argv):370 params_table = {371 'chat_id': [int, str],372 'question': str,373 'options': list,374 'is_anonymous': bool,375 'type': str,376 'allows_multiple_answers': bool,377 'correct_option_id': int,378 'explanation': str,379 'explanation_parse_mode': str,380 'explanation_entities': list,381 'open_period': int,382 'close_date': int,383 'is_closed': bool,384 'disable_notification': bool,385 'protect_content': bool,386 'reply_to_message_id': int,387 'allow_sending_without_reply': bool,388 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],389 }390 argv['chat_id'] = chat_id391 argv['question'] = question392 argv['options'] = options393 verify_params(params_table, argv)394 return Message(self.__post('sendPoll', argv))395 def sendDice(self, chat_id, **argv):396 params_table = {397 'chat_id': [int, str],398 'emoji': str,399 'disable_notification': bool,400 'protect_content': bool,401 'reply_to_message_id': int,402 'allow_sending_without_reply': bool,403 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],404 }405 argv['chat_id'] = chat_id406 verify_params(params_table, argv)407 return Message(self.__post('sendDice', argv))408 def sendChatAction(self, chat_id, action, **argv):409 params_table = {410 'chat_id': [int, str],411 'action': str,412 }413 argv['chat_id'] = chat_id414 argv['action'] = action415 verify_params(params_table, argv)416 return self.__post('sendChatAction', argv)417 def getUserProfilePhotos(self, user_id, **argv):418 params_table = {419 'user_id': int,420 'offset': int,421 'limit': int,422 }423 argv['user_id'] = user_id424 verify_params(params_table, argv)425 return UserProfilePhotos(self.__post('getUserProfilePhotos', argv))426 def getFile(self, file_id, **argv):427 params_table = {428 'file_id': str,429 }430 argv['file_id'] = file_id431 verify_params(params_table, argv)432 return File(self.__post('getFile', argv))433 def banChatMember(self, chat_id, user_id, **argv):434 params_table = {435 'chat_id': [int, str],436 'user_id': int,437 'until_date': int,438 'revoke_messages': bool,439 }440 argv['chat_id'] = chat_id441 argv['user_id'] = user_id442 verify_params(params_table, argv)443 return self.__post('banChatMember', argv)444 def unbanChatMember(self, chat_id, user_id, **argv):445 params_table = {446 'chat_id': [int, str],447 'user_id': int,448 'only_if_banned': bool,449 }450 argv['chat_id'] = chat_id451 argv['user_id'] = user_id452 verify_params(params_table, argv)453 return self.__post('unbanChatMember', argv)454 def restrictChatMember(self, chat_id, user_id, permissions, **argv):455 params_table = {456 'chat_id': [int, str],457 'user_id': int,458 'permissions': ChatPermissions,459 'until_date': int,460 }461 argv['chat_id'] = chat_id462 argv['user_id'] = user_id463 argv['permissions'] = permissions464 verify_params(params_table, argv)465 return self.__post('restrictChatMember', argv)466 def promoteChatMember(self, chat_id, user_id, **argv):467 params_table = {468 'chat_id': [int, str],469 'user_id': int,470 'is_anonymous': bool,471 'can_manage_chat': bool,472 'can_post_messages': bool,473 'can_edit_messages': bool,474 'can_delete_messages': bool,475 'can_manage_voice_chats': bool,476 'can_restrict_members': bool,477 'can_promote_members': bool,478 'can_change_info': bool,479 'can_invite_users': bool,480 'can_pin_messages': bool,481 }482 argv['chat_id'] = chat_id483 argv['user_id'] = user_id484 verify_params(params_table, argv)485 return self.__post('promoteChatMember', argv)486 def setChatAdministratorCustomTitle(self, chat_id, user_id, custom_title, **argv):487 params_table = {488 'chat_id': [int, str],489 'user_id': int,490 'custom_title': str,491 }492 argv['chat_id'] = chat_id493 argv['user_id'] = user_id494 argv['custom_title'] = custom_title495 verify_params(params_table, argv)496 return self.__post('setChatAdministratorCustomTitle', argv)497 def banChatSenderChat(self, chat_id, sender_chat_id, **argv):498 params_table = {499 'chat_id': [int, str],500 'sender_chat_id': int,501 }502 argv['chat_id'] = chat_id503 argv['sender_chat_id'] = sender_chat_id504 verify_params(params_table, argv)505 return self.__post('banChatSenderChat', argv)506 def unbanChatSenderChat(self, chat_id, sender_chat_id, **argv):507 params_table = {508 'chat_id': [int, str],509 'sender_chat_id': int,510 }511 argv['chat_id'] = chat_id512 argv['sender_chat_id'] = sender_chat_id513 verify_params(params_table, argv)514 return self.__post('unbanChatSenderChat', argv)515 def setChatPermissions(self, chat_id, permissions, **argv):516 params_table = {517 'chat_id': [int, str],518 'permissions': ChatPermissions,519 }520 argv['chat_id'] = chat_id521 argv['permissions'] = permissions522 verify_params(params_table, argv)523 return self.__post('setChatPermissions', argv)524 def exportChatInviteLink(self, chat_id, **argv):525 params_table = {526 'chat_id': [int, str],527 }528 argv['chat_id'] = chat_id529 verify_params(params_table, argv)530 return self.__post('exportChatInviteLink', argv)531 def createChatInviteLink(self, chat_id, **argv):532 params_table = {533 'chat_id': [int, str],534 'name': str,535 'expire_date': int,536 'member_limit': int,537 'creates_join_request': bool,538 }539 argv['chat_id'] = chat_id540 verify_params(params_table, argv)541 return ChatInviteLink(self.__post('createChatInviteLink', argv))542 def editChatInviteLink(self, chat_id, invite_link, **argv):543 params_table = {544 'chat_id': [int, str],545 'invite_link': str,546 'name': str,547 'expire_date': int,548 'member_limit': int,549 'creates_join_request': bool,550 }551 argv['chat_id'] = chat_id552 argv['invite_link'] = invite_link553 verify_params(params_table, argv)554 return ChatInviteLink(self.__post('editChatInviteLink', argv))555 def revokeChatInviteLink(self, chat_id, invite_link, **argv):556 params_table = {557 'chat_id': [int, str],558 'invite_link': str,559 }560 argv['chat_id'] = chat_id561 argv['invite_link'] = invite_link562 verify_params(params_table, argv)563 return ChatInviteLink(self.__post('revokeChatInviteLink', argv))564 def approveChatJoinRequest(self, chat_id, user_id, **argv):565 params_table = {566 'chat_id': [int, str],567 'user_id': int,568 }569 argv['chat_id'] = chat_id570 argv['user_id'] = user_id571 verify_params(params_table, argv)572 return self.__post('approveChatJoinRequest', argv)573 def declineChatJoinRequest(self, chat_id, user_id, **argv):574 params_table = {575 'chat_id': [int, str],576 'user_id': int,577 }578 argv['chat_id'] = chat_id579 argv['user_id'] = user_id580 verify_params(params_table, argv)581 return self.__post('declineChatJoinRequest', argv)582 def setChatPhoto(self, chat_id, photo, **argv):583 params_table = {584 'chat_id': [int, str],585 'photo': InputFile,586 }587 argv['chat_id'] = chat_id588 argv['photo'] = photo589 verify_params(params_table, argv)590 return self.__post('setChatPhoto', argv)591 def deleteChatPhoto(self, chat_id, **argv):592 params_table = {593 'chat_id': [int, str],594 }595 argv['chat_id'] = chat_id596 verify_params(params_table, argv)597 return self.__post('deleteChatPhoto', argv)598 def setChatTitle(self, chat_id, title, **argv):599 params_table = {600 'chat_id': [int, str],601 'title': str,602 }603 argv['chat_id'] = chat_id604 argv['title'] = title605 verify_params(params_table, argv)606 return self.__post('setChatTitle', argv)607 def setChatDescription(self, chat_id, **argv):608 params_table = {609 'chat_id': [int, str],610 'description': str,611 }612 argv['chat_id'] = chat_id613 verify_params(params_table, argv)614 return self.__post('setChatDescription', argv)615 def pinChatMessage(self, chat_id, message_id, **argv):616 params_table = {617 'chat_id': [int, str],618 'message_id': int,619 'disable_notification': bool,620 }621 argv['chat_id'] = chat_id622 argv['message_id'] = message_id623 verify_params(params_table, argv)624 return self.__post('pinChatMessage', argv)625 def unpinChatMessage(self, chat_id, **argv):626 params_table = {627 'chat_id': [int, str],628 'message_id': int,629 }630 argv['chat_id'] = chat_id631 verify_params(params_table, argv)632 return self.__post('unpinChatMessage', argv)633 def unpinAllChatMessages(self, chat_id, **argv):634 params_table = {635 'chat_id': [int, str],636 }637 argv['chat_id'] = chat_id638 verify_params(params_table, argv)639 return self.__post('unpinAllChatMessages', argv)640 def leaveChat(self, chat_id, **argv):641 params_table = {642 'chat_id': [int, str],643 }644 argv['chat_id'] = chat_id645 verify_params(params_table, argv)646 return self.__post('leaveChat', argv)647 def getChat(self, chat_id, **argv):648 params_table = {649 'chat_id': [int, str],650 }651 argv['chat_id'] = chat_id652 verify_params(params_table, argv)653 return Chat(self.__post('getChat', argv))654 def getChatAdministrators(self, chat_id, **argv):655 params_table = {656 'chat_id': [int, str],657 }658 argv['chat_id'] = chat_id659 verify_params(params_table, argv)660 return [ChatMember(x) for x in self.__post('getChatAdministrators', argv)]661 def getChatMemberCount(self, chat_id, **argv):662 params_table = {663 'chat_id': [int, str],664 }665 argv['chat_id'] = chat_id666 verify_params(params_table, argv)667 return self.__post('getChatMemberCount', argv)668 def getChatMember(self, chat_id, user_id, **argv):669 params_table = {670 'chat_id': [int, str],671 'user_id': int,672 }673 argv['chat_id'] = chat_id674 argv['user_id'] = user_id675 verify_params(params_table, argv)676 return [ChatMember(x) for x in self.__post('getChatMember', argv)]677 def setChatStickerSet(self, chat_id, sticker_set_name, **argv):678 params_table = {679 'chat_id': [int, str],680 'sticker_set_name': str,681 }682 argv['chat_id'] = chat_id683 argv['sticker_set_name'] = sticker_set_name684 verify_params(params_table, argv)685 return self.__post('setChatStickerSet', argv)686 def deleteChatStickerSet(self, chat_id, **argv):687 params_table = {688 'chat_id': [int, str],689 }690 argv['chat_id'] = chat_id691 verify_params(params_table, argv)692 return self.__post('deleteChatStickerSet', argv)693 def answerCallbackQuery(self, callback_query_id, **argv):694 params_table = {695 'callback_query_id': str,696 'text': str,697 'show_alert': bool,698 'url': str,699 'cache_time': int,700 }701 argv['callback_query_id'] = callback_query_id702 verify_params(params_table, argv)703 return self.__post('answerCallbackQuery', argv)704 def setMyCommands(self, commands, **argv):705 params_table = {706 'commands': list,707 'scope': BotCommandScope,708 'language_code': str,709 }710 argv['commands'] = commands711 verify_params(params_table, argv)712 return self.__post('setMyCommands', argv)713 def deleteMyCommands(self, **argv):714 params_table = {715 'scope': BotCommandScope,716 'language_code': str,717 }718 verify_params(params_table, argv)719 return self.__post('deleteMyCommands', argv)720 def getMyCommands(self, **argv):721 params_table = {722 'scope': BotCommandScope,723 'language_code': str,724 }725 verify_params(params_table, argv)726 return [BotCommand(x) for x in self.__post('getMyCommands', argv)]727 def editMessageText(self, text, **argv):728 params_table = {729 'chat_id': [int, str],730 'message_id': int,731 'inline_message_id': str,732 'text': str,733 'parse_mode': str,734 'entities': list,735 'disable_web_page_preview': bool,736 'reply_markup': InlineKeyboardMarkup,737 }738 argv['text'] = text739 verify_params(params_table, argv)740 return Message(self.__post('editMessageText', argv))741 def editMessageCaption(self, **argv):742 params_table = {743 'chat_id': [int, str],744 'message_id': int,745 'inline_message_id': str,746 'caption': str,747 'parse_mode': str,748 'caption_entities': list,749 'reply_markup': InlineKeyboardMarkup,750 }751 verify_params(params_table, argv)752 return Message(self.__post('editMessageCaption', argv))753 def editMessageMedia(self, media, **argv):754 params_table = {755 'chat_id': [int, str],756 'message_id': int,757 'inline_message_id': str,758 'media': InputMedia,759 'reply_markup': InlineKeyboardMarkup,760 }761 argv['media'] = media762 verify_params(params_table, argv)763 return Message(self.__post('editMessageMedia', argv))764 def editMessageReplyMarkup(self, **argv):765 params_table = {766 'chat_id': [int, str],767 'message_id': int,768 'inline_message_id': str,769 'reply_markup': InlineKeyboardMarkup,770 }771 verify_params(params_table, argv)772 return Message(self.__post('editMessageReplyMarkup', argv))773 def stopPoll(self, chat_id, message_id, **argv):774 params_table = {775 'chat_id': [int, str],776 'message_id': int,777 'reply_markup': InlineKeyboardMarkup,778 }779 argv['chat_id'] = chat_id780 argv['message_id'] = message_id781 verify_params(params_table, argv)782 return Poll(self.__post('stopPoll', argv))783 def deleteMessage(self, chat_id, message_id, **argv):784 params_table = {785 'chat_id': [int, str],786 'message_id': int,787 }788 argv['chat_id'] = chat_id789 argv['message_id'] = message_id790 verify_params(params_table, argv)791 return self.__post('deleteMessage', argv)792 def sendSticker(self, chat_id, sticker, **argv):793 params_table = {794 'chat_id': [int, str],795 'sticker': [InputFile, str],796 'disable_notification': bool,797 'protect_content': bool,798 'reply_to_message_id': int,799 'allow_sending_without_reply': bool,800 'reply_markup': [InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply],801 }802 argv['chat_id'] = chat_id803 argv['sticker'] = sticker804 verify_params(params_table, argv)805 return Message(self.__post('sendSticker', argv))806 def getStickerSet(self, name, **argv):807 params_table = {808 'name': str,809 }810 argv['name'] = name811 verify_params(params_table, argv)812 return StickerSet(self.__post('getStickerSet', argv))813 def uploadStickerFile(self, user_id, png_sticker, **argv):814 params_table = {815 'user_id': int,816 'png_sticker': InputFile,817 }818 argv['user_id'] = user_id819 argv['png_sticker'] = png_sticker820 verify_params(params_table, argv)821 return File(self.__post('uploadStickerFile', argv))822 def createNewStickerSet(self, user_id, name, title, emojis, **argv):823 params_table = {824 'user_id': int,825 'name': str,826 'title': str,827 'png_sticker': [InputFile, str],828 'tgs_sticker': InputFile,829 'webm_sticker': InputFile,830 'emojis': str,831 'contains_masks': bool,832 'mask_position': MaskPosition,833 }834 argv['user_id'] = user_id835 argv['name'] = name836 argv['title'] = title837 argv['emojis'] = emojis838 verify_params(params_table, argv)839 return self.__post('createNewStickerSet', argv)840 def addStickerToSet(self, user_id, name, emojis, **argv):841 params_table = {842 'user_id': int,843 'name': str,844 'png_sticker': [InputFile, str],845 'tgs_sticker': InputFile,846 'webm_sticker': InputFile,847 'emojis': str,848 'mask_position': MaskPosition,849 }850 argv['user_id'] = user_id851 argv['name'] = name852 argv['emojis'] = emojis853 verify_params(params_table, argv)854 return self.__post('addStickerToSet', argv)855 def setStickerPositionInSet(self, sticker, position, **argv):856 params_table = {857 'sticker': str,858 'position': int,859 }860 argv['sticker'] = sticker861 argv['position'] = position862 verify_params(params_table, argv)863 return self.__post('setStickerPositionInSet', argv)864 def deleteStickerFromSet(self, sticker, **argv):865 params_table = {866 'sticker': str,867 }868 argv['sticker'] = sticker869 verify_params(params_table, argv)870 return self.__post('deleteStickerFromSet', argv)871 def setStickerSetThumb(self, name, user_id, **argv):872 params_table = {873 'name': str,874 'user_id': int,875 'thumb': [InputFile, str],876 }877 argv['name'] = name878 argv['user_id'] = user_id879 verify_params(params_table, argv)880 return self.__post('setStickerSetThumb', argv)881 def answerInlineQuery(self, inline_query_id, results, **argv):882 params_table = {883 'inline_query_id': str,884 'results': list,885 'cache_time': int,886 'is_personal': bool,887 'next_offset': str,888 'switch_pm_text': str,889 'switch_pm_parameter': str,890 }891 argv['inline_query_id'] = inline_query_id892 argv['results'] = results893 verify_params(params_table, argv)894 return self.__post('answerInlineQuery', argv)895 def sendInvoice(self, chat_id, title, description, payload, provider_token, currency, prices, **argv):896 params_table = {897 'chat_id': [int, str],898 'title': str,899 'description': str,900 'payload': str,901 'provider_token': str,902 'currency': str,903 'prices': list,904 'max_tip_amount': int,905 'suggested_tip_amounts': list,906 'start_parameter': str,907 'provider_data': str,908 'photo_url': str,909 'photo_size': int,910 'photo_width': int,911 'photo_height': int,912 'need_name': bool,913 'need_phone_number': bool,914 'need_email': bool,915 'need_shipping_address': bool,916 'send_phone_number_to_provider': bool,917 'send_email_to_provider': bool,918 'is_flexible': bool,919 'disable_notification': bool,920 'protect_content': bool,921 'reply_to_message_id': int,922 'allow_sending_without_reply': bool,923 'reply_markup': InlineKeyboardMarkup,924 }925 argv['chat_id'] = chat_id926 argv['title'] = title927 argv['description'] = description928 argv['payload'] = payload929 argv['provider_token'] = provider_token930 argv['currency'] = currency931 argv['prices'] = prices932 verify_params(params_table, argv)933 return Message(self.__post('sendInvoice', argv))934 def answerShippingQuery(self, shipping_query_id, ok, **argv):935 params_table = {936 'shipping_query_id': str,937 'ok': bool,938 'shipping_options': list,939 'error_message': str,940 }941 argv['shipping_query_id'] = shipping_query_id942 argv['ok'] = ok943 verify_params(params_table, argv)944 return self.__post('answerShippingQuery', argv)945 def answerPreCheckoutQuery(self, pre_checkout_query_id, ok, **argv):946 params_table = {947 'pre_checkout_query_id': str,948 'ok': bool,949 'error_message': str,950 }951 argv['pre_checkout_query_id'] = pre_checkout_query_id952 argv['ok'] = ok953 verify_params(params_table, argv)954 return self.__post('answerPreCheckoutQuery', argv)955 def setPassportDataErrors(self, user_id, errors, **argv):956 params_table = {957 'user_id': int,958 'errors': list,959 }960 argv['user_id'] = user_id961 argv['errors'] = errors962 verify_params(params_table, argv)963 return self.__post('setPassportDataErrors', argv)964 def sendGame(self, chat_id, game_short_name, **argv):965 params_table = {966 'chat_id': int,967 'game_short_name': str,968 'disable_notification': bool,969 'protect_content': bool,970 'reply_to_message_id': int,971 'allow_sending_without_reply': bool,972 'reply_markup': InlineKeyboardMarkup,973 }974 argv['chat_id'] = chat_id975 argv['game_short_name'] = game_short_name976 verify_params(params_table, argv)977 return Message(self.__post('sendGame', argv))978 def setGameScore(self, user_id, score, **argv):979 params_table = {980 'user_id': int,981 'score': int,982 'force': bool,983 'disable_edit_message': bool,984 'chat_id': int,985 'message_id': int,986 'inline_message_id': str,987 }988 argv['user_id'] = user_id989 argv['score'] = score990 verify_params(params_table, argv)991 return Message(self.__post('setGameScore', argv))992 def getGameHighScores(self, user_id, **argv):993 params_table = {994 'user_id': int,995 'chat_id': int,996 'message_id': int,997 'inline_message_id': str,998 }999 argv['user_id'] = user_id1000 verify_params(params_table, argv)...
PayDay.py
Source:PayDay.py
1class Person:2 """3 """4 def __init__(self, name, surname, time=0):5 self._name = name6 self._surname = surname7 self._time = time89 def __str__(self):10 return f"{self._name} {self._surname}, {self._time}"1112 def _add_time_self(self, time):13 self._time += time141516class Employer(Person):17 """18 """19 global __PAYDAY20 __POST = "ШÑаÑнÑй ÑоÑÑÑдник"21 __PAYDAY = 120_0002223 def show_payday(self):24 if self._time > 160:25 self.__over_pay = __PAYDAY / 160 * (self._time - 160) * 226 print(self.__over_pay + __PAYDAY)27 else:28 print(__PAYDAY)293031class Freelancer(Person):32 """33 """34 global __PAYDAY, __POST35 __POST = "ФÑиланÑеÑ"36 __PAYDAY = 10003738 def __str__(self):39 return super().__str__() + f" {__POST}"4041 def show_payday(self):42 print(__PAYDAY * self._time)434445class Director(Person):46 """47 """48 global __PAYDAY, __POST, __AWARD49 __POST = "ÐиÑекÑоÑ"50 __PAYDAY = 200_00051 __AWARD = 20_0005253 def __str__(self):54 return super().__str__() + f" {__POST}"5556 def show_payday(self):57 if self._time > 160:58 print(__PAYDAY + __AWARD)59 else:60 print(__PAYDAY)616263 def check_has_employer(self, name, surname):64 for i in employers_list:65 if name.title() == i._name and surname.title() == i._surname:66 return True6768 return False6970 def add_employers(self, name, surname, post, time=0):71 if not self.check_has_employer(name, surname):72 if post.lower() == "диÑекÑоÑ":73 employers_list.append(Director(name, surname))74 elif post.lower() == "ÑÑиланÑеÑ":75 employers_list.append(Freelancer(name, surname))76 elif post.lower() == "ÑÑаÑнÑй ÑоÑÑÑдник":77 employers_list.append(Employer(name, surname))78 else:79 print("ÐÑÑной?")80 else:81 print("Такой ÑоÑÑÑдник Ñже еÑÑÑ!")8283 def add_time_others(self, name, surname, time):84 if self.check_has_employer(name, surname):85 for i in employers_list:86 if name.title() == i._name and surname.title() == i._surname:87 i._time += time88 else:89 print("Такого ÑоÑÑÑдника неÑ!")909192employers_list = [Director("ÐлÑдаÑ", "ШамÑиев", 100)]93ls = []9495name = input("ÐведиÑе имÑ: ")96surname = input("ÐведиÑе ÑамилиÑ: ")9798a = Director("Ðл", "Ша", 10)99a.show_payday()100a.add_employers("ÐлÑдаÑ", "ШамÑиев", "ÐиÑекÑоÑ")101a.add_employers("ÐлÑдаÑ1", "ШамÑиев1", "ÐиÑекÑоÑ")102a.add_time_others("ÐлÑдаÑ", "ШамÑиев", 3)103104for i in employers_list:105 ls.append({"ÐмÑ": i._name, "ФамилиÑ": i._surname, "ÐÑемÑ": i._time})106
...
CalcularBateriaPanel.py
Source:CalcularBateriaPanel.py
1import decimal2from uuid import UUID3from calculadora.models import( 4 BateriaModel,CalculoPanelModel,CalculoBateriaModel,ReporteModel5) 6class CalcularBateriaPanel:7 def __init__(self,post,token): 8 self.token = UUID(token,version=4)9 self.setPost(post)10 self.__setReporte()11 self.__setBateria()12 def setPost(self,post):13 if(post == ""):14 self.__post = self.__convertPost()15 else:16 self.__post = post17 def __convertPost(self):18 report = ReporteModel.objects.get(token=self.token)19 calculo = CalculoBateriaModel.objects.get(report=report)20 panel = CalculoPanelModel.objects.get(report=report)21 bateria = calculo.bateria22 return {23 "consumoDiario" : report.consumoDiario,24 "voltaje" : bateria.voltaje,25 "capacidad" : bateria.capacidad,26 "autonomia-dias": calculo.autonomiaDias,27 "hsp" : panel.hsp,28 "potencia-de-panel" : panel.potenciaDePanel,29 }30 def getPost(self):31 return self.__post32 def __setReporte(self):33 self.__calculo = ReporteModel(consumoDiario=decimal.Decimal(self.__post["consumoDiario"]),34 token=self.token35 )36 def __setBateria(self):37 self.__bateria = BateriaModel(voltaje=int(self.__post["voltaje"]),capacidad=int(self.__post["capacidad"]))38 def __corrienteNecesaria(self):39 try:40 result = decimal.Decimal(self.__calculo.consumoDiario/self.__bateria.voltaje)41 return result42 except ZeroDivisionError:43 return 044 except decimal.InvalidOperation:45 return 046 except ValueError:47 return 048 def __setCalcularBateria(self):49 self.__calcularBateria = CalculoBateriaModel(50 bateria=self.__bateria,51 report=self.__calculo,52 corrienteNecesaria= self.__corrienteNecesaria(),53 autonomiaDias=int(self.__post["autonomia-dias"]),54 ) 55#select 56 def __setCalculoPanel(self):57 if(self.__post["hsp"] == ""):58 self.__panel = CalculoPanelModel(report=self.__calculo,59 potenciaDePanel=decimal.Decimal(self.__post["potencia-de-panel"])60 )61 else:62 self.__panel = CalculoPanelModel(hsp=decimal.Decimal(self.__post["hsp"]),63 report=self.__calculo,64 potenciaDePanel=decimal.Decimal(self.__post["potencia-de-panel"])65 )66 def guardar(self):67 self.__calcularBateria.report.save() 68 self.__calcularBateria.bateria.save() 69 self.__calcularBateria.save()70 self.__panel.report.save()71 self.__panel.save()72 def calcularPanelYbateria(self):73 self.__setCalcularBateria()74 self.__setCalculoPanel()75 76 def getBateria(self):77 return self.__calcularBateria78 79 def getPanel(self):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!