def get_archive_mp3s(self, archive_entries, filepath):
        start = _timer()

        for file in archive_entries:
            feed_id = file['feed_id']
            archive_uri = file['uri']
            file_date = self.__format_entry_date(file['end_time'])

            print(f'Downloading {archive_entries.index(file) + 1} of '
                  f'{len(archive_entries)}')

            # Build the path for saving the downloaded .mp3
            out_file_name = filepath + '-'.join([feed_id, file_date]) + '.mp3'

            # Get the URL of the mp3 file
            mp3_soup = self.get_download_soup(archive_uri)
            file_url = self.__parse_mp3_path(mp3_soup)

            if self.verbose:
                print(f'\tfrom {file_url}')
                print(f'\tto {out_file_name}')

            self.__fetch_mp3([out_file_name, file_url])

        duration = _timer() - start

        if len(archive_entries) > 0: print('\nDownloads complete.')
        if self.verbose:
            print(f'\nRetrieved {len(archive_entries)} files in '
                  f'{round(duration,4)} seconds.')
Example #2
0
    def get_archive_mp3s(self, archive_entries, filepath):
        start = _timer()

        for file in archive_entries:
            feed_id = file.feed_id
            archive_uri = file.file_uri
            file_date = self.__format_entry_date(file.file_end_datetime)
            file_url = file.mp3_url

            # Build the path for saving the downloaded .mp3
            out_file_name = filepath + '-'.join([feed_id, file_date]) + '.mp3'

            print(f'Downloading {archive_entries.index(file) + 1} of '
                  f'{len(archive_entries)}')
            if self.verbose:
                print(f'\tfrom {file_url}')
                print(f'\tto {out_file_name}')

            #self.throttle.throttle('file')
            self.__fetch_mp3([out_file_name, file_url])

        duration = _timer() - start

        if len(archive_entries) > 0: print('\nDownloads complete.')
        if self.verbose:
            print(f'\nRetrieved {len(archive_entries)} files in '
                  f'{round(duration,4)} seconds.')
Example #3
0
def _blockUntilConditionMet(getValue,
                            giveUpAfterSeconds,
                            shouldStopEvaluator=lambda value: bool(value),
                            intervalBetweenSeconds=0.1,
                            errorMessage=None):
    """Repeatedly tries to get a value up until a time limit expires. Tries are separated by
	a time interval. The call will block until shouldStopEvaluator returns True when given the value,
	the default evaluator just returns the value converted to a boolean.
	@return A tuple, (True, value) if evaluator condition is met, otherwise (False, None)
	@raises RuntimeError if the time limit expires and an errorMessage is given.
	"""
    assert callable(getValue)
    assert callable(shouldStopEvaluator)
    assert intervalBetweenSeconds > 0.001
    SLEEP_TIME = intervalBetweenSeconds * 0.5
    startTime = _timer()
    lastRunTime = startTime
    firstRun = True  # ensure we start immediately
    while (_timer() - startTime) < giveUpAfterSeconds:
        if firstRun or (_timer() - lastRunTime) > intervalBetweenSeconds:
            firstRun = False
            lastRunTime = _timer()
            val = getValue()
            if shouldStopEvaluator(val):
                return True, val
            _sleep(SLEEP_TIME)

    else:
        if errorMessage:
            raise AssertionError(errorMessage)
        return False, None
Example #4
0
def _blockUntilConditionMet(
		getValue,
		giveUpAfterSeconds,
		shouldStopEvaluator=lambda value: bool(value),
		intervalBetweenSeconds=0.1,
		errorMessage=None):
	"""Repeatedly tries to get a value up until a time limit expires. Tries are separated by
	a time interval. The call will block until shouldStopEvaluator returns True when given the value,
	the default evaluator just returns the value converted to a boolean.
	@return A tuple, (True, value) if evaluator condition is met, otherwise (False, None)
	@raises RuntimeError if the time limit expires and an errorMessage is given.
	"""
	assert callable(getValue)
	assert callable(shouldStopEvaluator)
	assert intervalBetweenSeconds > 0.001
	SLEEP_TIME = intervalBetweenSeconds * 0.5
	startTime = _timer()
	lastRunTime = startTime
	firstRun = True  # ensure we start immediately
	while (_timer() - startTime) < giveUpAfterSeconds:
		if firstRun or (_timer() - lastRunTime) > intervalBetweenSeconds:
			firstRun = False
			lastRunTime = _timer()
			val = getValue()
			if shouldStopEvaluator(val):
				return True, val
			_sleep(SLEEP_TIME)

	else:
		if errorMessage:
			raise AssertionError(errorMessage)
		return False, None
def test_pipe_speed():
    c, d = multiprocessing.Pipe()
    cond = multiprocessing.Condition()
    elapsed = 0
    iterations = 1

    while elapsed < delta:
        iterations *= 2

        p = multiprocessing.Process(target=pipe_func,
                                    args=(d, cond, iterations))
        cond.acquire()
        p.start()
        cond.wait()
        cond.release()

        result = None
        t = _timer()

        while result != 'STOP':
            result = c.recv()

        elapsed = _timer() - t
        p.join()

    print(iterations, 'objects passed through connection in', elapsed,
          'seconds')
    print('average number/sec:', iterations / elapsed)
 def throttle(self, type='page'):
     if type == 'page':
         while not _timer() - self.last_page_req >= _PAGE_REQUEST_WAIT:
             pass
         self.last_page_req = _timer()
     else:
         while not _timer() - self.last_file_req >= _FILE_REQUEST_WAIT:
             pass
         self.last_file_req = _timer()
Example #7
0
	def _onNvdaSpeech(self, speechSequence=None):
		if not speechSequence:
			return
		with threading.Lock():
			self._speechOccurred_requiresLock = True
			self._lastSpeechTime_requiresLock = _timer()
			self._nvdaSpeech_requiresLock.append(speechSequence)
 def _hasSpeechFinished(self, speechStartedIndex: Optional[int] = None):
     with self._speechLock:
         started = speechStartedIndex is None or speechStartedIndex < self.get_next_speech_index(
         )
         finished = self.SPEECH_HAS_FINISHED_SECONDS < _timer(
         ) - self._lastSpeechTime_requiresLock
         return started and finished
    def get_archive_mp3s(self, archive_entries, filepath):
        start = _timer()
        earliest_download = min([
            entry['start_time'] for entry in archive_entries
        ]).strftime('%m-%d-%y %H:%M')
        latest_download = max([
            entry['start_time'] for entry in archive_entries
        ]).strftime('%m-%d-%y %H:%M')

        t = _tqdm(archive_entries,
                  desc='Overall progress',
                  leave=True,
                  dynamic_ncols=True)

        t.write(f'Downloading {earliest_download} to {latest_download}')
        t.write(f'Storing at {filepath}.')

        for file in t:
            feed_id = self._parent.feed_id
            archive_uri = file['uri']
            file_date = self._format_entry_date(file['end_time'])

            # Build the path for saving the downloaded .mp3
            out_file_name = filepath + '-'.join([feed_id, file_date]) + '.mp3'

            # Get the URL of the mp3 file
            mp3_soup = self.get_download_soup(archive_uri)
            file_url = self._parse_mp3_path(mp3_soup)

            self._fetch_mp3([out_file_name, file_url], t)
Example #10
0
	def __init__(self):
		self._nvdaSpeech = [
			[""],  # initialise with an empty string, this allows for access via [-1]. This is equiv to no speech.
		]
		self._allSpeechStartIndex = 0
		self._speechOccurred = False
		self.isNvdaStartupComplete = False
		self.lastSpeechTime = _timer()
		self._registerWithExtensionPoints()
Example #11
0
	def __init__(self):
		# speech cache is ordered temporally, oldest at low indexes, most recent at highest index.
		self._nvdaSpeech_requiresLock = [  # requires thread locking before read/write
			[""],  # initialise with an empty string, this allows for access via [-1]. This is equiv to no speech.
		]
		self._speechOccurred_requiresLock = False  # requires thread locking before read/write
		self._lastSpeechTime_requiresLock = _timer()
		self._isNvdaStartupComplete = False
		self._allSpeechStartIndex = self.get_last_speech_index()
		self._maxKeywordDuration = 30
		self._registerWithExtensionPoints()
Example #12
0
	def __init__(self):
		# speech cache is ordered temporally, oldest at low indexes, most recent at highest index.
		self._nvdaSpeech_requiresLock = [  # requires thread locking before read/write
			[""],  # initialise with an empty string, this allows for access via [-1]. This is equiv to no speech.
		]
		self._lastSpeechTime_requiresLock = _timer()
		#: Lock to protect members that are written to in _onNvdaSpeech.
		self._speechLock = threading.RLock()

		# braille raw text (not dots) cache is ordered temporally,
		# oldest at low indexes, most recent at highest index.
		self._nvdaBraille_requiresLock = [  # requires thread locking before read/write
			"",  # initialise with an empty string, this allows for access via [-1]. This is equiv to no braille.
		]
		#: Lock to protect members that are written to in _onNvdaBraille.
		self._brailleLock = threading.RLock()

		self._isNvdaStartupComplete = False
		self._allSpeechStartIndex = self.get_last_speech_index()
		self._allBrailleStartIndex = self.get_last_braille_index()
		self._maxKeywordDuration = 30
		self._registerWithExtensionPoints()
Example #13
0
	def hasSpeechFinished(self):
		return self.SPEECH_HAS_FINISHED_SECONDS < _timer() - self.lastSpeechTime
 def _onNvdaSpeech(self, speechSequence=None):
     if not speechSequence:
         return
     with self._speechLock:
         self._lastSpeechTime_requiresLock = _timer()
         self._nvdaSpeech_requiresLock.append(speechSequence)
Example #15
0
def _pop_time(message=None, log=print):
    elapsed_time = _timer() - _tld.time_stack.pop()
    if message is None:
        return
    depth = len(_tld.time_stack)
    log('│ ' * depth + f'{message}: {elapsed_time:.3f} seconds')
Example #16
0
def _push_time():
    if not hasattr(_tld, 'time_stack'):
        _tld.time_stack = []
    _tld.time_stack.append(_timer())
Example #17
0
	def _hasSpeechFinished(self):
		with threading.Lock():
			return self.SPEECH_HAS_FINISHED_SECONDS < _timer() - self._lastSpeechTime_requiresLock
Example #18
0
	def _onNvdaSpeech(self, speechSequence=None):
		if not speechSequence: return
		with threading.Lock():
			self._speechOccurred = True
			self.lastSpeechTime = _timer()
			self._nvdaSpeech.append(speechSequence)
 def __init__(self):
     self.last_file_req = _timer()
     self.last_page_req = _timer()
Example #20
0
 def hasSpeechFinished(self):
     return self.SPEECH_HAS_FINISHED_SECONDS < _timer(
     ) - self.lastSpeechTime
 def _wait(self, duration):
     while not _timer() - self.last_file_req >= duration:
         pass
     self.last_file_req = _timer()