1
|
|
|
#!/usr/bin/python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup |
4
|
|
|
from modules.get_image import get_image |
5
|
|
|
import modules.instagram_filters |
6
|
|
|
import inspect |
7
|
|
|
import yaml |
8
|
|
|
import datetime |
9
|
|
|
|
10
|
|
|
# import path |
11
|
|
|
with open("config.yml", "r") as f: |
12
|
|
|
instagram_folder = yaml.load(f)["path"]["instagram"] |
13
|
|
|
|
14
|
|
|
filters = [] |
15
|
|
|
all_funcs = inspect.getmembers(modules.instagram_filters, inspect.isfunction) |
16
|
|
|
for i in range(0, len(all_funcs)): |
17
|
|
|
if all_funcs[i][0].startswith("filt_"): |
18
|
|
|
filters.append(all_funcs[i][0]) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def instagram(bot, update): |
22
|
|
|
try: |
23
|
|
|
get_image(bot, update, instagram_folder) |
24
|
|
|
except: |
25
|
|
|
update.message.reply_text("I can't get the image! :(") |
26
|
|
|
return |
27
|
|
|
instagram_key_list = [] |
28
|
|
|
for i in filters: |
29
|
|
|
instagram_key = InlineKeyboardButton(str(i)[5:], callback_data=i) |
30
|
|
|
instagram_key_list.append(instagram_key) |
31
|
|
|
row_split = lambda list, size, acc=[]: (row_split(list[size:], size, acc + [list[:size]]) if list else acc) |
32
|
|
|
rows = row_split(instagram_key_list, 3) |
33
|
|
|
instagram_keyboard = rows |
34
|
|
|
instagram_reply_markup = InlineKeyboardMarkup(instagram_keyboard) |
35
|
|
|
update.message.reply_text("Available filters are:", reply_markup=instagram_reply_markup) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def instagram_button(bot, update): |
39
|
|
|
instagram_query = update.callback_query |
40
|
|
|
chosen_filter = update.callback_query.data |
41
|
|
|
filter_name = str(chosen_filter)[5:] |
42
|
|
|
bot.editMessageText(text="Selected filter: %s\nProcessing..." |
43
|
|
|
% filter_name, |
44
|
|
|
chat_id=instagram_query.message.chat_id, |
45
|
|
|
message_id=instagram_query.message.message_id) |
46
|
|
|
try: |
47
|
|
|
getattr(modules.instagram_filters, chosen_filter)(instagram_folder) |
48
|
|
|
except: |
49
|
|
|
raise Exception("Instagram error") |
50
|
|
|
with open(instagram_folder + filter_name + ".jpg", "rb") as f: |
51
|
|
|
bot.sendPhoto(instagram_query.message.chat_id, f) |
52
|
|
|
print (datetime.datetime.now(), ">>>", "Sent instagram photo", ">>>", instagram_query.message.from_user.username) |
53
|
|
|
|