12 lines
797 B
Python
Executable File
12 lines
797 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Search only your own a2a history, authenticated with your guest key."""
|
|
import argparse,json,os,urllib.parse,urllib.request
|
|
p=argparse.ArgumentParser(); p.add_argument('query',nargs='?',default=''); p.add_argument('--with',dest='peer'); p.add_argument('--recent',type=int,default=30); a=p.parse_args()
|
|
url=os.environ['A2A_API']+'/v1/history?'+urllib.parse.urlencode({'limit':min(max(a.recent,1),200)})
|
|
req=urllib.request.Request(url,headers={'X-API-KEY':os.environ['A2A_AGENT_KEY']})
|
|
with urllib.request.urlopen(req,timeout=30) as r: rows=json.load(r).get('messages',[])
|
|
for m in rows:
|
|
if a.peer and a.peer not in [m.get('from_agent'),m.get('to_agent')]: continue
|
|
if a.query.lower() not in m.get('message','').lower(): continue
|
|
print(json.dumps(m,ensure_ascii=False))
|