INNER CODE UNIT · Python
get_summary
kblin/ncbi-genome-download · ncbi_genome_download/core.py:404
def get_summary(section, domain, uri, use_cache):
"""Get the assembly_summary.txt file from NCBI and return a StringIO object for it."""
logger = logging.getLogger("ncbi-genome-download")
logger.debug('Checking for a cached summary file')
cachefile = "{section}_{domain}_assembly_summary.txt".format(section=section, domain=domain)
full_cachefile = os.path.join(CACHE_DIR, cachefile)
if use_cache and os.path.exists(full_cachefile) and \
datetime.now(timezone.utc) - datetime.fromtimestamp(
os.path.getmtime(full_cachefile), tz=timezone.utc) < timedelta(days=1):
logger.info('Using cached summary.')
with open(full_cachefile, 'r', encoding='utf-8') as fh:
return StringIO(fh.read())
logger.debug('Downloading summary for %r/%r uri: %r', section, domain, uri)
url = '{uri}/{section}/{domain}/assembly_summary.txt'.format(
section=section, domain=domain, uri=uri)
req = requests.get(url)