randydev commited on
Commit
0321ef2
·
verified ·
1 Parent(s): 9cc87ab

Create custom.py

Browse files
Files changed (1) hide show
  1. Akeno/utils/custom.py +95 -0
Akeno/utils/custom.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import math
3
+ import os
4
+ import re
5
+ import sys
6
+ import time
7
+ from os import getenv
8
+ from traceback import format_exc
9
+ from urllib.parse import unquote
10
+ from urllib.request import urlretrieve
11
+ from telegraph import Telegraph, exceptions, upload_file
12
+
13
+ def QuoteApi(user_id, first_name, link, text):
14
+ json = {
15
+ "type": "quote",
16
+ "format": "webp",
17
+ "backgroundColor": "#1b1429",
18
+ "width": 512,
19
+ "height": 768,
20
+ "scale": 2,
21
+ "messages": [
22
+ {
23
+ "entities": [],
24
+ "avatar": True,
25
+ "from": {
26
+ "id": user_id,
27
+ "name": first_name,
28
+ "photo": {
29
+ "url": link
30
+ }
31
+ },
32
+ "text": text,
33
+ "replyMessage": {}
34
+ }
35
+ ]
36
+ }
37
+ return json
38
+
39
+ def get_telegraph_link(media):
40
+ try:
41
+ response = upload_file(media)
42
+ except exceptions.TelegraphException as exc:
43
+ return
44
+ return response
45
+
46
+ def humanbytes(size):
47
+ if not size:
48
+ return "0 B"
49
+ for unit in ["", "K", "M", "G", "T"]:
50
+ if size < 1024:
51
+ break
52
+ size /= 1024
53
+ if isinstance(size, int):
54
+ size = f"{size}{unit}B"
55
+ elif isinstance(size, float):
56
+ size = f"{size:.2f}{unit}B"
57
+ return size
58
+
59
+ def _fix_logging(handler):
60
+ handler._builtin_open = open
61
+
62
+ def _new_open(self):
63
+ open_func = self._builtin_open
64
+ return open_func(self.baseFilename, self.mode)
65
+
66
+ setattr(handler, "_open", _new_open)
67
+
68
+ def _ask_input():
69
+ def new_input(*args, **kwargs):
70
+ raise EOFError("args=" + str(args) + ", kwargs=" + str(kwargs))
71
+
72
+ __builtins__["input"] = new_input
73
+
74
+ def where_hosted():
75
+ if os.getenv("DYNO"):
76
+ return "heroku"
77
+ if os.getenv("RAILWAY_STATIC_URL"):
78
+ return "railway"
79
+ if os.getenv("OKTETO_TOKEN"):
80
+ return "okteto"
81
+ if os.getenv("KUBERNETES_PORT"):
82
+ return "qovery | kubernetes"
83
+ if os.getenv("RUNNER_USER") or os.getenv("HOSTNAME"):
84
+ return "github actions"
85
+ if os.getenv("ANDROID_ROOT"):
86
+ return "termux"
87
+ if os.getenv("FLY_APP_NAME"):
88
+ return "fly.io"
89
+ return "local"
90
+
91
+ if int(v) < 10:
92
+ _fix_logging(FileHandler)
93
+
94
+ if where_hosted() == "local":
95
+ _ask_input()