2934473770
- UpstreamClient & Sub2ApiWebsiteClient: add __enter__/__exit__ - Convert all call sites to `with Client(...) as c:` pattern - Remove unused `upstream_name`/`upstream_base_url` locals in scheduler - Fix stale _decimal_str→decimal_string in _rate_from_group
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import json
|
|
import sys
|
|
import logging
|
|
from app.services.upstream_client import UpstreamClient
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
def main():
|
|
with UpstreamClient(
|
|
base_url="http://170.106.100.210:55555",
|
|
api_prefix="",
|
|
auth_type="bearer",
|
|
auth_config={"token": ""}, # We don't have token, but /api/group/ in some new-api may be open, or fail with 401
|
|
timeout=10.0,
|
|
) as client:
|
|
try:
|
|
groups = client.get_available_groups("/api/group/")
|
|
print("Groups:", groups)
|
|
except Exception as e:
|
|
print("Groups Error:", e)
|
|
|
|
try:
|
|
rates = client.get_group_rates("/api/option/?key=GroupRatio")
|
|
print("Rates:", rates)
|
|
except Exception as e:
|
|
print("Rates Error:", e)
|
|
|
|
try:
|
|
from app.services.upstream_client import _extract_rates_map, _unwrap_list
|
|
print("Unwrapped Groups:", _unwrap_list(groups))
|
|
print("Extracted Rates:", _extract_rates_map(rates))
|
|
except Exception as e:
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main()
|