#!/usr/local/bin/python2.7
# -*- coding: utf-8 -*-
"""
Intelligence Platform CLI Fabric File
"""

__author__    = 'Soonwoong Lee (soonwoong.lee@gmail.com)'
__license__   = 'Apache License'
__version__   = '0.2'

from fabric.api import *

@task
def send_message(msg, id=-36901391):
    """
    fab tg.send_message:'안녕하세요. TIP Bot 입니다.'
    """
    run('mkdir %s' % env.dir)
    with cd(env.dir):
        run('''cat <<EOF > tg_bot_request.py
# -*- coding: utf-8 -*-
import telegram
bot = telegram.Bot(token='112152357:AAGBdO_TGBagwQCsoGWm4EcZNv1CRwhJ0JA')
bot.sendMessage(chat_id=%(id)s, text='%(msg)s')
EOF''' % locals())
        cmd = 'python2.7 ./tg_bot_request.py 2>/dev/null'
        run(cmd)
        
@task
def send_photo(photo_path, id=-36901391):
    """
    fab tg.send_photo:https://telegram.org/img/t_logo.png
    """
    run('mkdir %s' % env.dir)
    with cd(env.dir):
        run('''cat <<EOF > tg_bot_request.py
# -*- coding: utf-8 -*-
import telegram
bot = telegram.Bot(token='112152357:AAGBdO_TGBagwQCsoGWm4EcZNv1CRwhJ0JA')
bot.sendPhoto(chat_id=%(id)s, photo='%(photo_path)s')
EOF''' % locals())
        cmd = 'python2.7 ./tg_bot_request.py 2>/dev/null'
        run(cmd)
    
@@ -842,32 +842,140 @@
  %25s' %25 env.dir)%0A
+    photo_path = 'open(%22' + photo_path + '%22, %22rb%22)' if 'http' not in photo_path else '%22' + photo_path + '%22'%0A
     with cd(env.
@@ -1175,17 +1175,16 @@
 , photo=
-'
 %25(photo_
@@ -1189,17 +1189,16 @@
 o_path)s
-'
 )%0AEOF'''

fix send_photo to send local file