Completed
Branch external-img-dl (74a600)
by Anas
01:17
created

meme()   B

Complexity

Conditions 6

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 6
c 4
b 0
f 1
dl 0
loc 23
rs 7.6949
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from modules.get_image import get_image
4
from modules.memegenerator import make_meme
5
import datetime
6
import yaml
7
8
# import paths
9
with open("config.yml", "r") as f:
10
    meme_folder = yaml.load(f)["path"]["memes"]
11
12
13
def meme(bot, update):
14
    meme_splitter = "@"
15
    if update.message.reply_to_message is not None:
16
        initial_text = "".join(update.message.text[6:]).upper()
17
    else:
18
        initial_text = "".join(update.message.caption[6:]).upper()
19
    split_text = initial_text.split(meme_splitter)
20
    try:
21
        get_image(bot, update, meme_folder)
22
    except:
23
        update.message.reply_text("Can't get the image! :(")
24
        return
25
    if split_text[0] == "":
26
        update.message.reply_text("Type in some text!")
27
        return
28
    elif len(split_text) > 1:
29
        make_meme(split_text[0], split_text[1], meme_folder+"original.jpg")
30
    else:
31
        make_meme("", split_text[0], meme_folder+"original.jpg")
32
    with open(meme_folder+"meme.jpg", "rb") as f:
33
        update.message.reply_photo(f)
34
    print (datetime.datetime.now(), ">>>", "Done meme", ">>>",
35
           update.message.from_user.username)