-
Notifications
You must be signed in to change notification settings - Fork 1
/
libjmf.py
137 lines (123 loc) · 3.38 KB
/
libjmf.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import html.parser
import shutil
import math
import datetime
from .config import *
h = html.parser.HTMLParser()
def center(s, pattern):
'''
This creates a bar across the entire page with s in the middle.
It is complex to ensure symmetry regardless of window/pattern size.
The right end of the pattern will always butt against string s.
The outer edges depend on the total number of columns.
1. Figure out how much room both sides have to fill.
2. Fill (possibly overfill if len(unit) > 1) both sides with
pattern in the same direction.
3. Trim both from left if they overfill.
4. Add extra character to right's left if total chars to fill is odd.
--> If we are trimming, do this by reducing trim by one.
--> If no trimming, do this by actually adding a character.
5. Flip right side for mirror effect.
'''
split_me = shutil.get_terminal_size().columns - len(s)
fit_in = int(split_me/2)
shrink_me = int(math.ceil(fit_in/(len(pattern)))) * pattern
trim_both = len(shrink_me) - fit_in
add_one = split_me%2
more = pattern[len(pattern)-add_one:] * (trim_both == 0)
right_start = trim_both - add_one * (trim_both != 0)
left = shrink_me[trim_both:]
right = more + shrink_me[right_start:]
return left + s + right[::-1]
def repeat(function, times):
for i in range(times):
function()
def legible(size):
for unit in ['B','KiB','MiB','GiB','TiB','PiB']:
if abs(size) < 1024:
return '{0:.1f}'.format(size).rstrip('0').rstrip('.') + ' ' + unit
size /= 1024.0
def yn(prompt, preferred='neither'):
force = preferred.lower() == 'y' or preferred.lower() == 'n'
if force:
preference = preferred.lower() == 'y'
yn_prompt = (preference*' [Y, n]: ') + ((not preference)*' [y, N]: ')
else:
yn_prompt = [y, n]
while 1:
yn = input(prompt + yn_prompt)
yes = yn.lower() == 'y' or yn.lower() == 'yes'
no = yn.lower() == 'n' or yn.lower() == 'no'
confused = not no and not yes
if not confused:
return yes
elif force:
return preference
else:
print('You must select either yes or no.')
def unBB(text):
fixed = ''
silent = False
for char in text:
if char == '[':
silent = True
elif char == ']':
silent = False
elif silent == False:
fixed += char
return fixed
def parse_bars(string):
organized = {}
letter_list = []
for letter in string:
if letter != '|':
letter_list.append(letter)
else:
organized[''.join(letter_list)] = 1
letter_list = []
organized[''.join(letter_list)] = 1
return organized
def unindex(index):
undone = []
for identifier in index:
undone.append(index[identifier])
return undone
def now():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
def log_print(s, quiet=False):
log_file = open(config+'jmf.log', 'a')
time = str(now())
if interactive:
prefix = time + ' - Interactive - '
else:
prefix = time + ' - @@@ Service - '
log_file.write(prefix + s + '\n')
log_file.close()
if 'match:' in s.lower():
match_file = open(config+'match.log', 'a')
match_file.write(time + s + '\n')
match_file.close()
if not quiet:
print(s)
def init():
if not os.path.exists(config):
os.makedirs(config)
class Blank(): pass
class c():
# rgb
r = '\033[91m'
g = '\033[92m'
b = '\033[94m'
# cym
c = '\033[96m'
y = '\033[93m'
m = '\033[95m'
# misc
p = '\033[95m' # purple
w = '\033[97m' # white
grey = '\033[90m' # grey
k = '\033[90m' # black
d = '\033[99m' # default
bold = '\033[1m'
ul = '\033[4m'
end = '\033[0m'