Narrrow down which entries to download.
491946
def filter_entries(entries, config):
    """"""
    def in_genus_list(species, genus_list):
        for genus in genus_list:
            if species.startswith(genus.capitalize()):
                return True
        return False

    new_entries = []
    for entry in entries:
        if config.type_material and config.type_material != ['any']:
            requested_types = map(lambda x: config._RELATION_TO_TYPE_MATERIAL[x], config.type_material)
            if not entry['relation_to_type_material'] or entry['relation_to_type_material'] not in requested_types:
                 logging.debug("Skipping assembly with no reference to type material or reference to type material does not match requested")
                 continue 
            else:
                print(entry['relation_to_type_material'])
        if config.genus and not in_genus_list(entry['organism_name'], config.genus):
            logging.debug('Organism name %r does not start with any in %r, skipping',
                          entry['organism_name'], config.genus)
            continue
        if config.species_taxid and entry['species_taxid'] not in config.species_taxid:
            logging.debug('Species TaxID %r does not match with any in %r, skipping',
                          entry['species_taxid'], config.species_taxid)
            continue
        if config.taxid and entry['taxid'] not in config.taxid:
            logging.debug('Organism TaxID %r does not match with any in %r, skipping',
                          entry['taxid'], config.taxid)
            continue
        if not config.is_compatible_assembly_accession(entry['assembly_accession']):
            logging.debug('Skipping entry with incompatible assembly accession %r', entry['assembly_accession'])
            continue
        if not config.is_compatible_assembly_level(entry['assembly_level']):
            logging.debug('Skipping entry with assembly level %r', entry['assembly_level'])
            continue
        if config.refseq_category != 'all' \
                and entry['refseq_category'] != config.get_refseq_category_string(config.refseq_category):
            logging.debug('Skipping entry with refseq_category %r, not %r', entry['refseq_category'],
                          config.refseq_category)
            continue
        new_entries.append(entry)

    return new_entries
419916
async def search_and_download(album, artist, format, size, out_filepath, *, size_tolerance_prct, amazon_tlds, no_lq_sources,
                              async_loop):
  
  # register sources
  source_args = (size, size_tolerance_prct)
  cover_sources = [sources.LastFmCoverSource(*source_args),
                   sources.AmazonCdCoverSource(*source_args),
                   sources.AmazonDigitalCoverSource(*source_args)]
  for tld in amazon_tlds:
    cover_sources.append(sources.AmazonCdCoverSource(*source_args, tld=tld))
  if not no_lq_sources:
    cover_sources.append(sources.GoogleImagesWebScrapeCoverSource(*source_args))

  # schedule search work
  search_futures = []
  for cover_source in cover_sources:
    coroutine = cover_source.search(album, artist)
    future = asyncio.ensure_future(coroutine, loop=async_loop)
    search_futures.append(future)

  # wait for it
  await asyncio.wait(search_futures, loop=async_loop)

  # get results
  results = []
  for future in search_futures:
    source_results = future.result()
    results.extend(source_results)

  # sort results
  results = await CoverSourceResult.preProcessForComparison(results, size, size_tolerance_prct)
  results.sort(reverse=True,
               key=functools.cmp_to_key(functools.partial(CoverSourceResult.compare,
                                                          target_size=size,
                                                          size_tolerance_prct=size_tolerance_prct)))
  if not results:
    logging.getLogger("Main").info("No results")

  # download
  for result in results:
    try:
      await result.get(format, size, size_tolerance_prct, out_filepath)
    except Exception as e:
      logging.getLogger("Main").warning("Download of %s failed: %s %s" % (result,
                                                                          e.__class__.__qualname__,
                                                                          e))
      continue
    else:
      return True

  return False
313208
def fetch(self):
        

        entries = []
        for activity in self.activities['entries']:
            entries.append(
                    [element for element in [activity['title'],
                        activity['content'][0]['value']]])

        return entries[0:self.max_entries]
169588
def downloadFiles(self, prompt=True, extract=False):
		""""""
		#First, get the download urls
		data = self.data
		downloadUrls = self.getDownloadUrls()
		
		#Then, confirm the user wants to do this
		if prompt:
			confirm = raw_input("Download files [Y/N]? ")
			if confirm.lower() != 'y':
				self.printd("Operation aborted by user input")
				return
				
		#Now, if they still do, do all this stuff:
		counter = -1
		for datum in data:
			counter += 1
			try:
				download = downloadUrls[counter]
			except:
				pass
				
			# Download the file; fix our user agent
			self.printd("Downloading " + datum[0] + " from " + download)
			headers = { 'User-Agent' : 'calcpkg/2.0' }
			request = urllib2.Request(download, None, headers)
			fileData = urllib2.urlopen(request).read()
			
			# Now, process the downloaded file
			dowName = datum[0]
			# Use a helper function to remove /pub, /files
			dowName = util.removeRootFromName(dowName)
			dowName = dowName[1:]
			dowName = dowName.replace('/', '-')
			dowName = self.downloadDir + dowName
			try:
				downloaded = open(dowName, 'wb')
			except:
				os.remove(dowName)
			downloaded.write(fileData)
			downloaded.close()
			self.printd("Download complete! Wrote file " + dowName + "\n")

			#Extract them if told to do so
			if extract:
				extractType = ""
				if '.zip' in dowName:
					extractType = "zip"
				elif '.tar' in dowName:
					extractType = "tar"
					specType = ""
					if '.bz2' in dowName:
						specType = ":bz2"
					elif ".gz" in dowName:
						specType = ":gz"
				elif ".tgz" in dowName:
					extractType = "tar"
					specType = ":gz"

				if extractType != "":
					self.printd("Extracting file " + dowName + ", creating directory for extracted files")
					dirName, a, ending = dowName.partition('.')
					dirName = dirName + '-' + ending
					try:
						os.mkdir(dirName)
					except:
						pass
					if extractType == "zip":
						archive = zipfile.ZipFile(dowName, 'r')
					elif extractType == "tar":
						archive = tarfile.open(dowName, "r" + specType)
					else:
						self.printd("An unknown error has occured!")
						return
					archive.extractall(dirName)
					self.printd("All files in archive extracted to " + dirName)
					os.remove(dowName)
					self.printd("The archive file " + dowName + " has been deleted!\n")
760595
def list_downloaded(**kwargs):
    '''
    
    '''
    CACHE_DIR = os.path.join('/var/cache/', _yum())

    ret = {}
    for root, dirnames, filenames in salt.utils.path.os_walk(CACHE_DIR):
        for filename in fnmatch.filter(filenames, '*.rpm'):
            package_path = os.path.join(root, filename)
            pkg_info = __salt__['lowpkg.bin_pkg_info'](package_path)
            pkg_timestamp = int(os.path.getctime(package_path))
            ret.setdefault(pkg_info['name'], {})[pkg_info['version']] = {
                'path': package_path,
                'size': os.path.getsize(package_path),
                'creation_date_time_t': pkg_timestamp,
                'creation_date_time': datetime.datetime.fromtimestamp(pkg_timestamp).isoformat(),
            }
    return ret
636428
def download(csvpath, asset_manager_id, data_id_type, data_id_list):
        """"""
        interface = interface_direct_csvpath(csvpath)
        logging.config.dictConfig(DEFAULT_LOGGING)
        logger = logging.getLogger(__name__)
        objs = []
        for data_id in data_id_list:
            Dict = dict()
            Dict[data_id_type] = data_id
            objs.append(interface.retrieve(asset_manager_id=asset_manager_id, **Dict))
        return objs
752208
def _download_query(self, as_of):
        
        c = self.institution.client()
        q = c.credit_card_account_query(number=self.number, date=as_of)
        return q
1347952
def check_downloaded(self, path, maybe_downloaded):
        
        downloaded = []
        for pkg in maybe_downloaded:
            if os.path.isfile(path + pkg):
                downloaded.append(pkg)
        return downloaded
1226005
def _load_entries(self):
        """"""

        rel_path = os.path.join('~','cltk_data',
                                'french',
                                'text','french_data_cltk'
                                ,'entries.py')
        path = os.path.expanduser(rel_path)
        #logger.info('Loading entries. This may take a minute.')
        loader = importlib.machinery.SourceFileLoader('entries', path)
        module = loader.load_module()
        entries = module.entries
        return entries
1272030
def click_download(self, event):
		
		args ['parallel'] = self.p.get()
		args ['file_type'] = self.optionmenu.get()
		args ['no_redirects'] = self.t.get()
		args ['query'] = self.entry_query.get()
		args ['min_file_size'] = int( self.entry_min.get())
		args ['max_file_size'] = int( self.entry_max.get())
		args ['limit'] = int( self.entry_limit.get())
		args ['website']= self.entry_website.get()
		args ['option']= self.engine.get()
		print(args)
		self.check_threat()
		download_content_gui( **args )
107717
def _load_entries(self, root):
        """"""
        mdict = {
            "comments": self._comment,
            "line": self._line,
            "group": self._group
        }
        for entry in root:
            mdict[entry.tag](entry)
1253990
def maybe_download_and_extract(self):
        """"""
        if not os.path.exists(self.cifar10_dir):

            if not os.path.exists(self.data_dir):
                os.makedirs(self.data_dir)

            def _progress(count, block_size, total_size):
                status_msg = '\r>> Downloading {} {:>3}%   '
                sys.stdout.write(status_msg.format(self.cifar10_tarball, float(count * block_size) / total_size * 100.0))
                sys.stdout.flush()

            file_path, _ = urlretrieve(CIFAR10_URL, self.cifar10_tarball, _progress)

            stat_info = os.stat(file_path)
            print('\nSuccessfully downloaded', file_path, stat_info.st_size, 'bytes.\n')

            tarfile.open(file_path, 'r:gz').extractall(self.data_dir)
628313
def _download_args(options):
    """"""
    return dict(
        version=options.version,
        download_base=options.download_base,
        downloader_factory=options.downloader_factory,
        to_dir=options.to_dir,
    )
686769
def do_download_datafiles(self, _):
        '''  '''
        contents = {"trialdata": lambda p: p.get_trial_data(), "eventdata": \
                    lambda p: p.get_event_data(), "questiondata": lambda p: \
                    p.get_question_data()}
        query = Participant.query.all()
        for k in contents:
            ret = "".join([contents[k](p) for p in query])
            temp_file = open(k + '.csv', 'w')
            temp_file.write(ret)
            temp_file.close()
1152822
def entries(self):
        """"""
        self.meta.seek(self.file_list_start)
        for i in range(0, self.num_files):
            yield self._get_node()
25123
def download(client, target_dir):
    """"""
    print('')
    print('download store listings')
    print('---------------------')
    listings = client.list('listings')
    for listing in listings:
        path = os.path.join(target_dir, 'listings', listing['language'])
        mkdir_p(path)
        with open(os.path.join(path, 'listing.json'), 'w') as outfile:
            print("save listing for {0}".format(listing['language']))
            json.dump(
                listing, outfile, sort_keys=True,
                indent=4, separators=(',', ': '))
957764
def which(program):
    """"""
    if (os.path.isabs(program) and os.path.isfile(program)
            and os.access(program, os.X_OK)):
        return [program]

    candidates = []
    locations = os.environ.get("PATH").split(os.pathsep)
    for location in locations:
        candidate = os.path.join(location, program)
        if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
            candidates.append(candidate)
    return candidates