-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathothers.py
67 lines (53 loc) · 1.78 KB
/
others.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
from asteval import Interpreter
from io import StringIO
import arrow
import base64
def maths(exp):
output = StringIO()
error = StringIO()
aeval = Interpreter(writer=output,err_writer=error)
aeval(f'x = {exp}')
aeval('print(x)')
res = output.getvalue()
if res == "":
return None
else:
return res
def timeanddate():
utc = arrow.utcnow()
return f"\
**UTC** __{utc.format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Athens** __{utc.to('Europe/Athens').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Kolkata** __{utc.to('Asia/Kolkata').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Maseru** __{utc.to('Africa/Maseru').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Moscow** __{utc.to('Europe/Moscow').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Melbourne** __{utc.to('Australia/Melbourne').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**NewYork** __{utc.to('America/New_York').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
**Shanghai** __{utc.to('Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss ZZ')}__\n\
"
def pyrun(code):
output = StringIO()
error = StringIO()
aeval = Interpreter(writer=output,err_writer=error)
aeval(code)
res = output.getvalue()
if res == "":
er = error.getvalue()
if er == "":
return "__Nothing is Printed to STDOUT__"
else:
return er
else:
return res
def b64e(string):
return base64.b64encode(string.encode("ascii")).decode("ascii")
def b64d(string):
return base64.b64decode(string.encode("ascii")).decode("ascii")
def b2img(data,name):
ima = base64.b64decode(data.split('base64,')[-1])
with open(name,"wb") as file:
file.write(ima)
return name
def img2b(file):
with open(file, "rb") as ima:
return base64.b64encode(ima.read()).decode('utf-8')