Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/isida/vi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaliyS <hetleven@yandex.ua>2017-02-27 22:54:28 +0300
committerVitaliyS <hetleven@yandex.ua>2017-02-27 22:54:28 +0300
commit54a58c1f4fe3c0f99d435886d269b9a0e9593827 (patch)
tree165f283c7367a9771f08724bf5c3aa24927d1fe5
parent0d8d87d353dbe56cab7b4cd4a1bcda8b71c99abf (diff)
upd: new function - send_photo
-rw-r--r--kernel.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel.py b/kernel.py
index a1fcab1..92a5828 100644
--- a/kernel.py
+++ b/kernel.py
@@ -474,6 +474,27 @@ def send_msg(raw_in, msg, parse_mode = 'HTML', custom = None):
else:
return True
+# Send photo
+def send_photo(raw_in, photo, caption=None, custom = None):
+ global LAST_MESSAGE, TIMEOUT
+ MSG = { 'chat_id': raw_in['message']['chat'].get('id','') }
+ FLS = {'photo': (photo, open(photo, "rb"))}
+ if caption:
+ MSG['caption'] = caption
+ if custom:
+ for t in custom.keys():
+ MSG[t] = custom[t]
+ request = requests.post(API_URL % 'sendPhoto', data=MSG, files=FLS)
+ LAST_MESSAGE = time.time()
+ TIMEOUT = MIN_TIMEOUT
+ if not request.status_code == 200:
+ pprint('*** Error code on sendPhoto: %s' % request.status_code, 'red')
+ pprint('Raw_in dump:\n%s' % json.dumps(raw_in, indent=2, separators=(',', ': ')), 'red')
+ pprint('Data dump:\n%s' % json.dumps(MSG, indent=2, separators=(',', ': ')), 'red')
+ return False
+ else:
+ return True
+
# Open web page
def get_opener(page_name, parameters=None):
socket.setdefaulttimeout(www_get_timeout)