123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- # GPLv3 or later
- # Colors are used to make the
- clr = {
- "norm":"\033[00m", # Reset to normal
- "bold":"\033[01m", # Bold Text
- "ital":"\033[03m", # Italic Text
- "undr":"\033[04m", # Underlined
- "blnk":"\033[05m", # Blinking
- # Text
- "tdbl":"\033[30m", # Dark Black
- "tdrd":"\033[31m", # Dark Red
- "tdgr":"\033[32m", # Dark Green
- "tdyl":"\033[33m", # Dark Yellow
- "tdbu":"\033[34m", # Dark Blue
- "tdma":"\033[35m", # Dark Magenta
- "tdcy":"\033[36m", # Dark Cyan
- "tdwh":"\033[37m", # Dark White
- "tbbl":"\033[90m", # Bright Black
- "tbrd":"\033[91m", # Bright Red
- "tbgr":"\033[92m", # Bright Green
- "tbyl":"\033[93m", # Bright Yellow
- "tbbu":"\033[94m", # Bright Blue
- "tbma":"\033[95m", # Bright Magenta
- "tbcy":"\033[96m", # Bright Cyan
- "tbwh":"\033[97m", # Bright White
- # Background
- "bdbl":"\033[40m", # Dark Black
- "bdrd":"\033[41m", # Dark Red
- "bdgr":"\033[42m", # Dark Green
- "bdyl":"\033[43m", # Dark Yellow
- "bdbu":"\033[44m", # Dark Blue
- "bdma":"\033[45m", # Dark Magenta
- "bdcy":"\033[46m", # Dark Cyan
- "bdwh":"\033[47m", # Dark White
- "bbbl":"\033[100m", # Bright Black
- "bbrd":"\033[101m", # Bright Red
- "bbgr":"\033[102m", # Bright Green
- "bbyl":"\033[103m", # Bright Yellow
- "bbbu":"\033[104m", # Bright Blue
- "bbma":"\033[105m", # Bright Magenta
- "bbcy":"\033[106m", # Bright Cyan
- "bbwh":"\033[108m" # Bright White
- }
- # A function that insures a specific width of the printed part
- def wdth(x, n, to_good=True):
- # Convert Data to String
- mode = "normal"
- if type(x) == bool and x == True:
- x = "V"
- mode = "bdgr"
- elif type(x) == bool and x == False:
- x = "X"
- mode = "bdrd"
- else:
- x = str(x)
- # Turn emogis
- #x = emote(x)
- # Some characters are too wide. They do not obey the
- # monospace of the terminal, thus making it not pretty.
- # This is the string of characters which are checked to
- good = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'’()*+,-./:;<=>?@[\]^_`{|}~ йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮёЁקראטוןםפשדגכעיחלךףזסבהנמצתץ"
- # let's filter the string
- y = x
-
- if to_good:
- x = ""
- for i in y:
- if i in good:
- x = x + i
- else:
- x = x + "▓"
- # Now let's print what we've got.
- if len(y) < n:
- fac = n-len(y)
- fac1 = int(round(fac/2))
- fac2 = fac1
- while fac1 + fac2 > fac:
- fac2 -=1
- while fac1 + fac2 < fac:
- fac2 +=1
- x = (" "*fac1)+x+(" "*fac2)
- elif len(y) > n:
- if n > 10:
- x = x[:n-3]+"..."
- else:
- x = x[:n]
- if mode == "normal":
- return x
- else:
- return clr[mode]+clr["bold"]+x+clr["norm"]
- def tsize():
- # This funtion will get the size of the terminal and
- # return it to the variables provided width, height
- # On some systems this may not work. So there is a
- # try function.
- try:
- # Getting the size of the terminal
- import os
- w, h = os.get_terminal_size()
- # Sometimes when the terminal width is either
- # even or odd. It breaks code for some other
- # thing written differenly. For example:
- # You may have an even width ( like 84 ) when
- # writing a function. And then it works on different
- # widths as well like 62 and 80 and 48. All of them
- # are still even. Then you scale the terminal to be
- # something off like 63 and the function breaks. You
- # have one character too much or one character too little.
- # This is why I do not want to have a difference. And
- # force width to be one less, if it's not divisible by 2.
- if not w % 2:
- w = w - 1
- return w, h
- except:
- # If, by any reason the terminal can't get it's size.
- # We want to return some size regardless.
- w = 60
- h = 20
- return w, h
-
- def table(data, number=True):
- # This function will present data in a pretty table thing.
- # So let's first of all get the size of the terminal
- w, h = tsize()
- if number:
- w = w - 4
- # Then let's draw the categories for this we need to extract
- # it's sizes. If there is no 'size' variable the sizes of
- # each category will be spread equally.
- size = [] # Here the size will go as pure character value.
- if "size" in data:
- for i in data["size"]:
- size.append(int(( w - 10 ) / sum(data["size"]) * i))
- while sum(size) < w - 10:
- size[-1] += 1
- # printing categories
- nb = ""
- if number:
- nb = " "
- s = " "+clr["bdma"]+" "+clr["tbwh"]+nb
- for n, item in enumerate(data["categories"]):
- s = s + wdth(item.upper(), size[n])
- print(s+clr["bdma"]+" "+clr["norm"])
- size[-1] += 1
- # printing items
- for b, i in enumerate(data["data"]):
- # dark bright sequence thingy
- if b % 2:
- d = "b"
- else:
- d = "d"
- nb = ""
- if number:
- nb = clr["tbwh"]+wdth(b,4)
- s = " "+clr["bdma"]+" "+nb+clr["norm"]+clr["b"+d+"bu"]#+clr["tbwh"]
- for n, item in enumerate(i):
- s = s +clr["b"+d+"bu"]+ clr["tbwh"]+wdth(item, size[n]-1)+clr["bdma"]+" "
- print(s+clr["norm"])
- def center(line, c="bdma", blink=False):
- # This funtiocn will bring a given string of text
- # in the center of the terminal with a nice backgroud
- # around it.
- w, h = tsize()
- if blink:
- blink = clr["blnk"]
- else:
- blink = ""
- if len(line) % 2:
- line = line + " "
- if len(line) < w - 11:
- print(" "+clr[c],
- wdth(" ", int((w-10)/2 - (len(line)/2))),
- clr["bold"]+clr["tbwh"]+blink+line,
- wdth(" ", int((w-10)/2 - (len(line)/2))-1),
- clr["norm"])
- else:
- print(" "+clr[c],
- clr["bold"]+clr["tbwh"]+blink+wdth(line,w-10),
- clr["norm"])
-
- def timestring(tleft):
- # This crazy function will convert the microsecond into something
- # a bit more usefull. Like 03:20:90.06 Kind a thing.
- tleftX = tleft
- tleft = int(tleftX)
- addend = tleftX - tleft
- valt = str(tleft)
- if tleft > 60 :
- le = tleft
- tleft = int(tleft / 60)
- le = le - int(tleft * 60)
- stleft = "0"*(2-len(str(tleft)))+str(tleft)
- sle = "0"*(2-len(str(le)))+str(le)
- valt = stleft+":"+ sle
- if tleft > 60 :
- lele = le
- le = tleft
- tleft = int(tleft / 60)
- le = le - int(tleft * 60)
- lele = (lele - le)
- if lele < 0:
- lele = int(lele * -1)
- stleft = "0"*(2-len(str(tleft)))+str(tleft)
- sle = "0"*(2-len(str(le)))+str(le)
- slele = "0"*(2-len(str(lele)))+str(lele)
- valt = stleft+":"+ sle + ":" + slele
- if tleft > 24 :
- le = tleft
- tleft = int(tleft / 24)
- le = le - int(tleft * 24)
- valt = str(tleft)+" DAYS AND "+ str(le) + " HRS"
- return valt# + "." + str(int(addend*100))
- def progress_bar(now, total, name=""):
- # This function will draw a pretty progress bar that fills up
- # one problem. It requires an empty print line after it. Or it
- # will start printing whatever in the same line as the progress
- # bar.
- # dimensions
- w, h = tsize()
- fullw = w - 8
- # string
- string = " "+str(int(round(now/total*100)))+"% "+str(now)+" / "+str(total)+" "+name
- #string = string+" "*(fullw-len(string))
- string = wdth(string, fullw)
- howfar = int(round(fullw / total * now))
- pstring = clr["tbwh"]+clr["bold"]+clr["bdcy"]+string[:howfar]+clr["bdma"]+string[howfar:]
- print("\r "+pstring, end=clr["norm"])
- def user_emoji(user, stuff):
- import datetime
-
- new_date_format = "%Y/%m/%d"
- today = datetime.datetime.strftime(datetime.datetime.today(), new_date_format)
- for d in range(400):
- yesterday = datetime.datetime.strftime(datetime.datetime.today()-datetime.timedelta(days=d+1), new_date_format)
- if yesterday in stuff.get("volume", {}):
- break
- try:
- v = stuff["volume"][yesterday]["average"]
- except:
- v = 20
- try:
- v = stuff["volume"][today]["average"]
- except:
- pass
-
- # Prints username with emoji and everything.get
- vs = "😭😢🥺😕🙂😀🤣" #emojis from sad to happy
- evil = "😇🥰😊🤔🤨😒😖😡😈" #level of evil emoji
- # getting average volume
- average = 0
- for i in stuff.get("volume", {}):
- for b in stuff.get("volume", {})[i].get("users", {}):
- if user in b:
- if not average:
- average = stuff.get("volume", {})[i].get("users", {})[b]
- else:
- average = ( average + stuff.get("volume", {})[i].get("users", {})[b] ) / 2
- average = v - average
- if average < 0:
- average = average * -1
- average = (average * -1) + 100
- take = int(round((len(vs)-1)*(average/100)))
- evilness = stuff.get("users", {}).get(user, {}).get("evil", 50)
- eviltake = int(round((len(evil)-1)*(evilness/100)))
- name = stuff.get("users", {}).get(user, {}).get("display_name", user)
-
- return evil[eviltake]+vs[take]+" "+name
|