-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathversion.py
51 lines (38 loc) · 1.19 KB
/
version.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
import json
import platform
import sys
from functools import lru_cache
VERSION = "0.13.0"
def get_os_version() -> str:
os_name = platform.system().lower()
if os_name == "darwin":
os_name = "macos"
if os_name == "macos":
os_version = platform.mac_ver()[0]
elif os_name == "windows":
os_version = platform.win32_ver()[0]
elif os_name == "linux":
try:
import distro
os_version = distro.version(pretty=False, best=True)
except ImportError:
os_version = platform.release()
else:
os_version = platform.release()
return os_version
@lru_cache(maxsize=1)
def user_agent():
python_version = ".".join(map(str, sys.version_info[:2]))
os_name = platform.system().lower()
os_version = get_os_version()
return f"cozepy/{VERSION} python/{python_version} {os_name}/{os_version}".lower()
@lru_cache(maxsize=1)
def coze_client_user_agent() -> str:
ua = {
"version": VERSION,
"lang": "python",
"lang_version": ".".join(map(str, sys.version_info[:2])),
"os_name": platform.system().lower(),
"os_version": get_os_version(),
}
return json.dumps(ua)