-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.py
116 lines (98 loc) Β· 3.18 KB
/
colors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from datetime import datetime
import re
class colors:
'''
Colors class:reset all colors with colors.reset; two
sub classes fg for foreground
and bg for background; use as colors.subclass.colorname.
i.e. colors.fg.red or colors.bg.greenalso, the generic bold, disable,
underline, reverse, strike through,
and invisible work with the main class i.e. colors.bold
'''
reset = '\033[0m'
bold = '\033[01m'
disable = '\033[02m'
underline = '\033[04m'
reverse = '\033[07m'
strikethrough = '\033[09m'
invisible = '\033[08m'
class fg:
black = '\033[30m'
red = '\033[31m'
green = '\033[32m'
orange = '\033[33m'
blue = '\033[34m'
purple = '\033[35m'
cyan = '\033[36m'
lightgrey = '\033[37m'
darkgrey = '\033[90m'
lightred = '\033[91m'
lightgreen = '\033[92m'
yellow = '\033[93m'
lightblue = '\033[94m'
pink = '\033[95m'
lightcyan = '\033[96m'
class bg:
black = '\033[40m'
red = '\033[41m'
green = '\033[42m'
orange = '\033[43m'
blue = '\033[44m'
purple = '\033[45m'
cyan = '\033[46m'
lightgrey = '\033[47m'
class unicodeChar():
class balls:
green = 'π’ '
orange = 'π '
red = 'π΄'
yellow = 'π‘ '
blue = 'π΅'
brown = 'π€ '
white = 'βͺ'
purple = 'π£ '
empty = 'βοΈ'
noentry = 'β'
class squares:
green = 'π© '
orange = 'π§ '
red = 'π₯ '
yellow = 'π¨ '
purple = 'πͺ '
blue = 'π¦ '
def removeAnsii(string):
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', string)
def pretty_date(time=False):
"""
Based on https://stackoverflow.com/questions/1551382/user-friendly-time-format-in-python
with some modifications
"""
diff = datetime.now().timestamp() - time
if diff < 86400:
if diff < 10:
return unicodeChar.balls.green + "just now"
if diff < 60:
return unicodeChar.squares.green + str(round(diff)) + " seconds ago"
if diff < 120:
return unicodeChar.balls.blue + "a minute ago"
if diff < 3600:
return unicodeChar.balls.yellow + str(round(diff / 60)) + " minutes ago"
if diff < 7200:
return unicodeChar.balls.orange + "an hour ago"
if diff < 86400:
return unicodeChar.balls.red + str(round(diff / 3600)) + " hours ago"
day_diff = diff / 86400
if day_diff > 1 and day_diff < 1.5: # 1.5 days
return unicodeChar.balls.empty + "Yesterday"
if day_diff < 7:
return unicodeChar.balls.noentry + str(round(day_diff)) + " days ago"
if day_diff < 31:
return unicodeChar.balls.noentry + str(round(day_diff / 7)) + " weeks ago"
if day_diff < 365:
return str(round(day_diff / 30)) + " months ago"
return unicodeChar.balls.noentry + str(round(day_diff / 365)) + " years ago"
def saveToFile(buffer, filename):
text_file=open(filename,"w")
text_file.write(buffer)
text_file.close()