Completed
Push — master ( d605a1...1292a2 )
by Anas
01:36
created

liquid()   D

Complexity

Conditions 8

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
c 1
b 0
f 0
dl 0
loc 29
rs 4
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from modules.get_image import get_image
4
import subprocess
5
import datetime
6
import yaml
7
8
# import path
9
with open("config.yml", "r") as f:
10
    path = yaml.load(f)["path"]["liquid"]
11
12
13
# get image, then rescale
14
def liquid(bot, update):
15
    if update.message.reply_to_message is not None:
16
        parts = update.message.text.split(" ", 1)
17
    else:
18
        parts = update.message.caption.split(" ", 1)
19
    if len(parts) == 1:
20
        power = 60
21
    else:
22
        try:
23
            power = int(parts[1])
24
        except:
25
            update.message.reply_text("Paremeter needs to be a number!")
26
            return
27
        if power > 100 or power < 1:
28
            update.message.reply_text("Baka, make it from 1 to 100!")
29
            return
30
    try:
31
        get_image(bot, update, path)
32
    except:
33
        update.message.reply_text("I can't get the image! :(")
34
        return
35
    id = subprocess.Popen("identify " + path + "original.jpg", stdout=subprocess.PIPE).communicate()[0]
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
36
    res = str(id.split()[2])[2:-1]
37
    size = str(100 - (power / 1.3))
38
    x = "convert " + path + "original.jpg -liquid-rescale " + size + "%x" + size + "% -resize " + res + "! " + path + "liquid.jpg"
39
    subprocess.run(x, shell=True)
40
    with open(path + "liquid.jpg", "rb") as f:
41
        update.message.reply_photo(f)
42
    print(datetime.datetime.now(), ">>>", "Done liquid rescale", ">>>", update.message.from_user.username)
43