diff options
author | 2020-05-22 15:09:59 +0300 | |
---|---|---|
committer | 2020-06-09 09:30:10 +0300 | |
commit | e190fff1a49499fc9e07931c641d8d110c3a595b (patch) | |
tree | 22a03e72af0ce2bd6ad75102b1b324f20525586e /weather.py | |
parent | f050bced69122149fb4f39e0021a35c989a40f90 (diff) |
Working base class, hopefully final reworks for the services
Diffstat (limited to 'weather.py')
-rw-r--r-- | weather.py | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -1,26 +1,47 @@ import asyncio -from aglbaseservice import AGLBaseService +import json +from aglbaseservice import AGLBaseService, AFBResponse class WeatherService(AGLBaseService): service = 'agl-service-weather' parser = AGLBaseService.getparser() + parser.add_argument('--current', default=True, help='Request current weather state', action='store_true') parser.add_argument('--apikey', default=False, help='Request weather API Key', action='store_true') def __init__(self, ip, port=None): super().__init__(api='weather', ip=ip, port=port, service='agl-service-weather') + async def current_weather(self): + return await self.request('current_weather', "") + async def apikey(self): return await self.request('api_key', "") async def main(): args = WeatherService.parser.parse_args() - ws = await WeatherService(ip=args.ipaddr) + aws = await WeatherService(ip=args.ipaddr) + if args.current: + id = await aws.current_weather() + resp = AFBResponse(await aws.response()) + print(json.dumps(resp.data, indent=2)) + if args.apikey: - id = await ws.apikey() - resp = await ws.response() - print(resp[2]['response']['api_key']) + id = await aws.apikey() + resp = AFBResponse(await aws.response()) + print(resp.data['api_key']) + + if args.subscribe: + for event in args.subscribe: + id = await aws.subscribe(event) + print(f'Subscribed for event {event} with messageid {id}') + resp = AFBResponse(await aws.response()) + print(resp) + + if args.listener: + async for response in aws.listener(): + print(response) if __name__ == '__main__': loop = asyncio.get_event_loop() |