@@ -13,46 +13,43 @@ def check_type(value: any, ty: type) -> bool:
1313
1414@dataclass
1515class BrokerItem :
16+ ts_start : str
17+ ts_end : str
1618 collector_id : str
1719 data_type : str
18- timestamp : int
1920 url : str
21+ rough_size : int
22+ exact_size : int
2023
2124
2225class Broker :
2326
24- def __init__ (self , api_url : str = "https://api.broker.bgpkit.com/v1 " , page_size : int = 100 ):
27+ def __init__ (self , api_url : str = "https://api.broker.bgpkit.com/v2 " , page_size : int = 100 ):
2528 self .base_url = api_url .strip ()
2629 self .page_size = int (page_size )
2730
2831 def query (self ,
29- start_ts : int = None ,
30- end_ts : int = None ,
31- collector : str = None ,
32+ ts_start : str = None ,
33+ ts_end : str = None ,
34+ collector_id : str = None ,
3235 project : str = None ,
3336 data_type : str = None ,
34- order : str = None ,
3537 print_url : bool = False ,
3638 ) -> [BrokerItem ]:
3739 params = []
38- if start_ts :
39- check_type (start_ts , int )
40- params .append (f"start_ts={ start_ts } " )
41- if end_ts :
42- check_type (end_ts , int )
43- params .append (f"end_ts={ end_ts } " )
44- if collector :
45- check_type (collector , str )
46- params .append (f"collector={ collector } " )
40+ if ts_start :
41+ params .append (f"ts_start={ ts_start } " )
42+ if ts_end :
43+ params .append (f"ts_end={ ts_end } " )
44+ if collector_id :
45+ check_type (collector_id , str )
46+ params .append (f"collector={ collector_id } " )
4747 if project :
4848 check_type (project , str )
4949 params .append (f"project={ project } " )
5050 if data_type :
5151 check_type (data_type , str )
5252 params .append (f"data_type={ data_type } " )
53- if order :
54- check_type (order , str )
55- params .append (f"order={ order } " )
5653 params .append (f"page_size={ self .page_size } " )
5754
5855 api_url = f"{ self .base_url } /search?" + "&" .join (params )
@@ -61,10 +58,10 @@ def query(self,
6158 data_items = []
6259 if print_url :
6360 print (api_url )
64- res = requests .get (api_url ).json ()[ "data" ]
61+ res = requests .get (api_url ).json ()
6562 while res :
6663 if res ["count" ] > 0 :
67- data_items .extend ([BrokerItem (** i ) for i in res ["items " ]])
64+ data_items .extend ([BrokerItem (** i ) for i in res ["data " ]])
6865
6966 if res ["count" ] < res ["page_size" ]:
7067 break
@@ -73,7 +70,7 @@ def query(self,
7370 query_url = f"{ api_url } &page={ page } "
7471 if print_url :
7572 print (query_url )
76- res = requests .get (query_url ).json ()[ "data" ]
73+ res = requests .get (query_url ).json ()
7774 else :
7875 break
7976
0 commit comments