# Path: modules/utils/data.py
# def prepare_binary_from_url(url, verify=True):
#     try:
#         content = requests.get(url, timeout=(1, 3), verify=verify).content
#     except RequestException:
#         pass
#     else:
#         return BytesIO(content)


import twitter
from modules.utils.data import prepare_binary_from_url
    if not twitter_options:
        return 'Module is not configured. You must set `twitter_keys` in settings'
    api = getattr(bot, 'twitter_api', None)
    if api is None:
        api = bot.twitter_api = twitter.Api(
            consumer_key=twitter_options['consumer_key'],
            consumer_secret=twitter_options['consumer_secret'],
            access_token_key=twitter_options['access_token_key'],
            access_token_secret=twitter_options['access_token_secret']
        )

    message = kwargs['update']['message']

    reply = message.get('reply_to_message', None)

    media = None
    
    if reply is None:
        text = ' '.join(args)
    elif reply.get('photo'):
        file = reply.get('photo')[-1]
        file_id = file['file_id']
        data = {'file_id': file_id}
        file_info = bot.call(
            'getFile', 
            'GET', 
            data=data
        )
        file_path = file_info.get('file_path')
        file_url = "https://api.telegram.org/file/bot{}/{}".format(bot.settings.token, file_path)

# Path: modules/utils/data.py
# def prepare_binary_from_url(url, verify=True):
#     try:
#         content = requests.get(url, timeout=(1, 3), verify=verify).content
#     except RequestException:
#         pass
#     else:
#         return BytesIO(content)


# Path: modules/user_tweet.py
import twitter
from modules.utils.data import prepare_binary_from_url

    if not twitter_options:
        return 'Module is not configured. You must set `twitter_keys` in settings'
    api = getattr(bot, 'twitter_api', None)
    if api is None:
        api = bot.twitter_api = twitter.Api(
            consumer_key=twitter_options['consumer_key'],
            consumer_secret=twitter_options['consumer_secret'],
            access_token_key=twitter_options['access_token_key'],
            access_token_secret=twitter_options['access_token_secret']
        )

    message = kwargs['update']['message']

    reply = message.get('reply_to_message', None)

    media = None
    
    if reply is None:
        text = ' '.join(args)
    elif reply.get('photo'):
        file = reply.get('photo')[-1]
        file_id = file['file_id']
        data = {'file_id': file_id}
        file_info = bot.call(
            'getFile', 
            'GET', 
            data=data
        )
        file_path = file_info.get('file_path')
        file_url = "https://api.telegram.org/file/bot{}/{}".format(bot.settings.token, file_path)

        media = prepare_binary_from_url(file_url)