diff --git a/facet/cli.py b/facet/cli.py index 89b64fe..b187912 100644 --- a/facet/cli.py +++ b/facet/cli.py @@ -1,9 +1,11 @@ +import asyncio +import json import os import shutil import subprocess import sys -import json +import aiohttp from facet import settings from facet.cli_dispatch import Dispatcher @@ -186,9 +188,18 @@ def fetch(self, options): else: include_inactive = options.get('--all') facets = Facet.get_all(include_inactive) - for facet in facets: - facet.fetch() - print(facet.format()) + + async def fetch_all_facets(): + conn = aiohttp.TCPConnector(ssl=False) + async with aiohttp.ClientSession(connector=conn) as session: + coros = [facet._fetch_async(session) for facet in facets] + await asyncio.wait(coros) + + event_loop = asyncio.new_event_loop() + try: + event_loop.run_until_complete(fetch_all_facets()) + finally: + event_loop.close() def follow(self, options): """ diff --git a/facet/core.py b/facet/core.py index c4be3e5..1efdb89 100644 --- a/facet/core.py +++ b/facet/core.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- +import asyncio import json import subprocess from os import listdir from os import path +import aiohttp import requests import yaml @@ -77,14 +79,27 @@ def apply_patch(self, patch): self.write_config(config) def fetch(self): + async def _fetch(): + conn = aiohttp.TCPConnector(ssl=False) + async with aiohttp.ClientSession(connector=conn) as session: + await self._fetch_async(session) + + event_loop = asyncio.new_event_loop() + try: + event_loop.run_until_complete(_fetch()) + finally: + event_loop.close() + + async def _fetch_async(self, session): if not self.jira: return - resp = requests.get(self.jira_json_url) + resp = await session.get(self.jira_json_url) resp.raise_for_status() - _json = resp.json() + _json = await resp.json() assert _json with open(self.jira_data_file, 'w') as fp: dump_json(_json, fp) + print(self.format()) def format(self): if self.jira: diff --git a/setup.py b/setup.py index 7e12e36..9860047 100644 --- a/setup.py +++ b/setup.py @@ -22,9 +22,9 @@ ], }, install_requires=[ + 'aiohttp', 'clint', 'docopt', 'pyyaml', - 'requests', ], )