示例#1
0
def get_me(chat_id) -> str:
    logging.info("Get me!")
    try:
        api = __connect_twitter(decrypt_to_auth(chat_id))
        name = api.VerifyCredentials().name
        user_id = api.VerifyCredentials().screen_name
        response = f"[{name}](https://twitter.com/{user_id})"
    except Exception as e:
        logging.error(traceback.format_exc())
        response = {"error": str(e)}

    return response
示例#2
0
def download_video_from_id(chat_id, tweet_id):
    try:
        api = __connect_twitter(decrypt_to_auth(chat_id))

        logging.info("Getting video tweets......")
        status = api.GetStatus(tweet_id)
        url = __get_video_url(status.AsDict())
        response = __download_from_url(url)
    except Exception as e:
        logging.error(traceback.format_exc())
        response = {"error": str(e)}

    return response
示例#3
0
def is_video_tweet(chat_id, text) -> str:
    # will return an id
    tweet_id = __get_tweet_id_from_url(text)
    logging.info("tweet id is %s", tweet_id)
    result = ""
    try:
        api = __connect_twitter(decrypt_to_auth(chat_id))
        logging.info("Getting video tweets......")
        status = api.GetStatus(tweet_id)
        url = __get_video_url(status.AsDict())
        if url:
            result = tweet_id
    except Exception:
        logging.debug(traceback.format_exc())

    return result
示例#4
0
def delete_tweet(message) -> dict:
    logging.info("Deleting tweet for someone...")
    chat_id = message.chat.id
    tweet_id = __get_tweet_id_from_reply(message)
    if not tweet_id:
        return {"error": "Which tweet do you want to delete? This does not seem like a valid tweet message."}

    try:
        api = __connect_twitter(decrypt_to_auth(chat_id))
        logging.info("Deleting......")
        status = api.DestroyStatus(tweet_id)
        response = status.AsDict()
    except Exception as e:
        logging.error(traceback.format_exc())
        response = {"error": str(e)}

    return response
示例#5
0
def send_tweet(message, pic=None) -> dict:
    logging.info("Preparing tweet for someone...")
    chat_id = message.chat.id
    text = message.text or message.caption
    if not text:
        text = ""
    tweet_id = __get_tweet_id_from_reply(message)
    try:
        api = __connect_twitter(decrypt_to_auth(chat_id))
        logging.info("Tweeting...")
        status = api.PostUpdate(text, media=pic, in_reply_to_status_id=tweet_id)
        logging.info("Tweeted")
        response = status.AsDict()
    except Exception as e:
        logging.error(traceback.format_exc())
        response = {"error": str(e)}

    return response