Beracles
commited on
Commit
·
458f0bb
1
Parent(s):
70759aa
extract source from “hf_token”
Browse files- app.py +4 -2
- extract.py +13 -7
app.py
CHANGED
@@ -45,7 +45,7 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
45 |
"""
|
46 |
|
47 |
# reuse hf_token field as json string
|
48 |
-
token, user_name, redirect, _ = extract(hf_token)
|
49 |
if user_name is None:
|
50 |
user_name = "__fake__"
|
51 |
|
@@ -90,7 +90,7 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
90 |
else:
|
91 |
try:
|
92 |
assert "games" in service_list
|
93 |
-
if service == "games":
|
94 |
print(f"{beijing()} [{user_name}] [{game}] {nlp_command}")
|
95 |
client = Client(
|
96 |
url,
|
@@ -114,6 +114,8 @@ def run(hf_token, service, game, functionality, nlp_command):
|
|
114 |
outp["proxy-version"] = proxy_version
|
115 |
outp["user"] = user_name
|
116 |
outp["game"] = game
|
|
|
|
|
117 |
calling_start = beijing()
|
118 |
print(f"calling logger starts at {beijing()}")
|
119 |
app_util.call_logger(outp, identity, token)
|
|
|
45 |
"""
|
46 |
|
47 |
# reuse hf_token field as json string
|
48 |
+
token, user_name, redirect, source, _ = extract(hf_token)
|
49 |
if user_name is None:
|
50 |
user_name = "__fake__"
|
51 |
|
|
|
90 |
else:
|
91 |
try:
|
92 |
assert "games" in service_list
|
93 |
+
if service == "games":
|
94 |
print(f"{beijing()} [{user_name}] [{game}] {nlp_command}")
|
95 |
client = Client(
|
96 |
url,
|
|
|
114 |
outp["proxy-version"] = proxy_version
|
115 |
outp["user"] = user_name
|
116 |
outp["game"] = game
|
117 |
+
if source:
|
118 |
+
outp["source"] = source
|
119 |
calling_start = beijing()
|
120 |
print(f"calling logger starts at {beijing()}")
|
121 |
app_util.call_logger(outp, identity, token)
|
extract.py
CHANGED
@@ -1,29 +1,35 @@
|
|
1 |
import json
|
2 |
|
|
|
3 |
def extract(hf_token):
|
4 |
"""
|
5 |
-
Extract token, user, redirect, and info from input hf_token.
|
6 |
If hf_token is simple, it is the token itself.
|
7 |
"""
|
8 |
-
info = {}
|
9 |
try:
|
10 |
info = json.loads(hf_token)
|
11 |
except json.decoder.JSONDecodeError:
|
12 |
-
return hf_token, None, None, None
|
13 |
|
14 |
try:
|
15 |
-
token = info[
|
16 |
except KeyError:
|
17 |
token = None
|
18 |
|
19 |
try:
|
20 |
-
user = info[
|
21 |
except KeyError:
|
22 |
user = None
|
23 |
|
24 |
try:
|
25 |
-
redirect = info[
|
26 |
except KeyError:
|
27 |
redirect = None
|
28 |
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
|
3 |
+
|
4 |
def extract(hf_token):
|
5 |
"""
|
6 |
+
Extract token, user, redirect, source, and info from input hf_token.
|
7 |
If hf_token is simple, it is the token itself.
|
8 |
"""
|
9 |
+
info = {} # a copy of hf_token in json format
|
10 |
try:
|
11 |
info = json.loads(hf_token)
|
12 |
except json.decoder.JSONDecodeError:
|
13 |
+
return hf_token, None, None, None, None
|
14 |
|
15 |
try:
|
16 |
+
token = info["token"]
|
17 |
except KeyError:
|
18 |
token = None
|
19 |
|
20 |
try:
|
21 |
+
user = info["user"]
|
22 |
except KeyError:
|
23 |
user = None
|
24 |
|
25 |
try:
|
26 |
+
redirect = info["redirect"]
|
27 |
except KeyError:
|
28 |
redirect = None
|
29 |
|
30 |
+
try:
|
31 |
+
source = info["source"]
|
32 |
+
except KeyError:
|
33 |
+
source = None
|
34 |
+
|
35 |
+
return token, user, redirect, source, info
|