nonebot2/apiclient.py

22 lines
459 B
Python
Raw Normal View History

2016-12-03 22:41:12 +08:00
import os
2016-12-02 22:24:19 +08:00
import requests
class ApiClient:
def __init__(self, base_url):
self.url = base_url
def __getattr__(self, item):
newclient = ApiClient(self.url + '/' + item)
return newclient
def __call__(self, *args, **kwargs):
2016-12-03 17:16:16 +08:00
try:
return requests.get(self.url, params=kwargs)
except requests.exceptions.ConnectionError:
return None
2016-12-02 22:24:19 +08:00
2016-12-03 22:41:12 +08:00
client = ApiClient(os.environ.get('QQ_API_URL'))