def send_tweet(bot, update): user_peer = update.get_effective_user() user_id = user_peer.peer_id tweet_text = update.get_effective_message().text user = get_user(user_id=user_id) if send_tweet_api(final_oauth_token=user.final_oauth_token, final_oauth_token_secret=user.final_oauth_token_secret, tweet_text=tweet_text): general_message = TextMessage(ReadyMessage.success_tweet) else: general_message = TextMessage(ReadyMessage.fail_tweet) btn_list = [ TemplateMessageButton(text=TMessage.back, value=TMessage.back, action=0) ] template_message = TemplateMessage(general_message=general_message, btn_list=btn_list) kwargs = { "message": template_message, "user_peer": user_peer, "try_times": 1 } bot.send_message(template_message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) dispatcher.finish_conversation(update)
def get_tweet_text(bot, update): user_peer = update.get_effective_user() user_id = user_peer.peer_id user = get_user(user_id=user_id) if not check_user_registration(update, user_peer, user): return 0 general_message = TextMessage(ReadyMessage.send_text_twitter) btn_list = [ TemplateMessageButton(text=TMessage.cancel, value=TMessage.cancel, action=0) ] template_message = TemplateMessage(general_message=general_message, btn_list=btn_list) kwargs = { "message": template_message, "user_peer": user_peer, "try_times": 1 } bot.send_message(template_message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) dispatcher.register_conversation_next_step_handler(update, [ CommandHandler("info", info), MessageHandler(TextFilter(), send_tweet), MessageHandler(DefaultFilter(), start_conversation) ])
def get_search_text(bot, update): user_peer = update.get_effective_user() user_id = user_peer.peer_id user = get_user(user_id=user_id) if not check_user_registration(update, user_peer, user): return 0 text_message = TextMessage(ReadyMessage.send_search_text) kwargs = {"message": text_message, "user_peer": user_peer, "try_times": 1} bot.send_message(text_message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) dispatcher.register_conversation_next_step_handler(update, [ CommandHandler("info", info), MessageHandler(TextFilter(), search_tweets), MessageHandler(DefaultFilter(), start_conversation) ])
def search_tweets(bot, update): user_peer = update.get_effective_user() user_id = user_peer.peer_id query = update.get_effective_message().text user = get_user(user_id=user_id) statuses = search_api( final_oauth_token=user.final_oauth_token, final_oauth_token_secret=user.final_oauth_token_secret, query=query) for status in statuses: media_url = status.get("media_url", None) height = status.get("height") width = status.get("width") if media_url: print("meddddddddddddiiiiiiiiiiiiiaaaaaaaaaaa") print(media_url) def file_upload_success(result, user_data): print("upload was successful : ", result) print(user_data) file_id = str(user_data.get("file_id", None)) access_hash = str(user_data.get("user_id", None)) file_size = str(user_data.get("file_size", None)) photo_message = PhotoMessage( file_id=file_id, access_hash=access_hash, name="Bale", file_size='11337', mime_type="image/jpeg", caption_text=TextMessage(text="Bale"), file_storage_version=1, thumb=None) bot.send_message(photo_message, user_peer, success_callback=success, failure_callback=failure) bot.upload_file(file="media_url", file_type="file", success_callback=file_upload_success, failure_callback=failure) message = TextMessage( ReadyMessage.tweet_message.format( status.get("text"), status.get("tweet_link"), status.get("name"), status.get("screen_name"), eng_to_arabic_number(status.get("favorite_count")), eng_to_arabic_number(status.get("retweet_count")), )) kwargs = {"message": message, "user_peer": user_peer, "try_times": 1} bot.send_message(message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) dispatcher.finish_conversation(update)
def get_home_time_line(bot, update): user_peer = update.get_effective_user() user_id = user_peer.peer_id user = get_user(user_id=user_id) if not check_user_registration(update, user_peer, user): return 0 time_line = get_home_time_line( final_oauth_token=user.final_oauth_token, final_oauth_token_secret=user.final_oauth_token_secret) a = 1 for tweet in time_line: media_dict = tweet.get("media_dict") if media_dict: print("meddddddddddddiiiiiiiiiiiiiaaaaaaaaaaa") media_url = media_dict.get("media_url") print(media_url) # import ast # media_url = ast.literal_eval(media_url) print(media_url) height = media_url.get("height") width = media_url.get("width") def file_upload_success(result, user_data): print("upload was successful : ", result) print(user_data) file_id = str(user_data.get("file_id", None)) access_hash = str(user_data.get("user_id", None)) file_size = str(user_data.get("file_size", None)) photo_message = PhotoMessage( file_id=file_id, access_hash=access_hash, name="Bale", file_size='11337', mime_type="image/jpeg", caption_text=TextMessage(text="Bale"), file_storage_version=1, thumb=None) bot.send_message(photo_message, user_peer, success_callback=success, failure_callback=failure) bot.upload_file(file="media_url", file_type="file", success_callback=file_upload_success, failure_callback=failure) message = TextMessage( ReadyMessage.tweet_message.format( tweet.get("text"), tweet.get("tweet_link"), tweet.get("name"), tweet.get("screen_name"), eng_to_arabic_number(tweet.get("favorite_count")), eng_to_arabic_number(tweet.get("retweet_count")), eng_to_arabic_number(tweet.get("datetime")))) if a == len(time_line): btn_list = [ TemplateMessageButton(text=TMessage.show_more, value=TMessage.show_more, action=0) ] template_message = TemplateMessage(general_message=message, btn_list=btn_list) kwargs = { "message": template_message, "user_peer": user_peer, "try_times": 1 } bot.send_message(template_message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) break kwargs = {"message": message, "user_peer": user_peer, "try_times": 1} bot.send_message(message, user_peer, success_callback=success, failure_callback=failure, kwargs=kwargs) a += 1 dispatcher.finish_conversation(update)