def file_upload_success(result, user_data): file_id = str(user_data.get(Attr.file_id, None)) file_url = str(user_data.get(Attr.url)) access_hash = str(user_data.get(Attr.user_id, None)) user_data = user_data[UserData.kwargs] user_peer = user_data[UserData.user_peer] my_logger = user_data[UserData.logger] bot = user_data[UserData.bot] my_logger.info(LogText.successful_report_upload, extra={ UserData.user_id: user_peer.peer_id, UserData.file_url: file_url }) file_size = os.path.getsize('files/{}.csv'.format(user_peer.peer_id)) doc_message = DocumentMessage( file_id=file_id, access_hash=access_hash, name=BotConfig.receipts_report_name, file_size=file_size, mime_type=MimeType.csv, caption_text=TextMessage(text=ReadyText.receipts_report)) kwargs = { UserData.user_peer: user_peer, UserData.doc_message: doc_message, UserData.report_attempt: SendingAttempt.first, UserData.logger: my_logger, UserData.bot: bot } bot.send_message(doc_message, user_peer, success_callback=receipt_report_success, failure_callback=receipt_report_failure, kwargs=kwargs)
def success_upload_document(user_data, server_response): file_id = str(server_response.get("file_id", None)) access_hash = str(server_response.get("user_id", None)) document_message = DocumentMessage( file_id=file_id, access_hash=access_hash, name=name, file_size=file_size, mime_type=BotConfig.excel_mime_type, caption_text=TextMessage(text=name), file_storage_version=1) admin_list = get_admin_peers() for admin in admin_list: kwargs = { "user_peer": admin, "step_name": 'excel_report', "succedent_message": None, "message": document_message, "attempt": 1, "bot": bot } bot.send_message(message=document_message, peer=admin, success_callback=step_success, failure_callback=step_failure, kwargs=kwargs)
def success_upload_document(user_data, server_response): file_id = str(server_response.get("file_id", None)) access_hash = str(server_response.get("user_id", None)) document_message = DocumentMessage(file_id=file_id, access_hash=access_hash, name=name, file_size=file_size, mime_type=mime_type, caption_text=TextMessage(text=caption_text), file_storage_version=file_storage_version) self.respond(update=update, message=document_message, success_callback=success_callback, failure_callback=failure_callback, kwargs=kwargs)
def file_upload_success(result, user_data): print("u success : ", result) print(user_data) file_id = user_data.get("file_id", None) user_id = user_data.get("user_id", None) url = user_data.get("url", None) dup = user_data.get("dup", None) print("during...") messsage = DocumentMessage( file_id, user_id, "excel.xlsx", 10, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", caption_text=TextMessage("لیست پرداختی ها :::")) dispatcher.bot.send_message(messsage, user, success_callback=success, failure_callback=failure)
def get_file_message(self): if self.file_access_hash is not None and self.file_id is not None: if self.mimetype.startswith("image/"): return PhotoMessage(file_id=self.file_id, access_hash=self.file_access_hash, name=self.name, file_size=sys.getsizeof(self.file), mime_type=self.mimetype, caption_text=TextMessage(self.caption), file_storage_version=1, thumb=None) else: return DocumentMessage(file_id=self.file_id, access_hash=self.file_access_hash, name=self.name, file_size=sys.getsizeof(self.file), mime_type=self.mimetype, caption_text=TextMessage(text=self.caption), file_storage_version=1) else: return None
def full_report_upload_success(result, user_data): file_id = str(user_data.get(UserData.file_id, None)) file_url = str(user_data.get(UserData.url)) access_hash = str(user_data.get(UserData.user_id, None)) user_data = user_data[UserData.kwargs] bot = user_data[UserData.bot] user_peer = user_data[UserData.user_peer] record_changes_num = user_data[UserData.record_changes_num] my_logger.info(LogMessage.successful_report_upload, extra={UserData.file_url: file_url, "tag": "info"}) file_size = os.path.getsize(BotConfig.reports_route + BotConfig.full_report_filename) doc_message = DocumentMessage(file_id=file_id, access_hash=access_hash, name=BotConfig.full_report_filename, file_size=file_size, mime_type=MimeType.xlsx, caption_text=TextMessage(BotMessage.full_report_body.format( record_changes_num[0], record_changes_num[1], record_changes_num[2], record_changes_num[3], record_changes_num[4], record_changes_num[5], record_changes_num[6], record_changes_num[7]))) # loop.call_soon(send_message, message, admin_peer) kwargs = {UserData.user_peer: user_peer, UserData.doc_message: doc_message, UserData.report_attempt: SendingAttempt.first, UserData.logger: my_logger, UserData.bot: bot} bot.send_message(doc_message, user_peer, success_callback=report_success, failure_callback=report_failure, kwargs=kwargs)