def parse(self): """Download and parse the stored URLs.""" for ad_url in self.urls: soup = BeautifulSoup(self.download_html(ad_url)) self.found = True address = soup.find(attrs={'data-qa': "is24-expose-address"}) if address is None: error = soup.find('div', {'id': 'oss-error'}) if 'nicht gefunden' in str(error): self.found = False LOGGER.error('Not found: %s', ad_url) else: # Take the first non blank line found in the address div street = [line.strip() for line in address.find_all(text=True) if line.strip()][0] street = ' '.join(street.split()) if not self.found: continue neighborhood_content = [text_only.strip() for text_only in address.children if isinstance(text_only, str)] neighborhood = [zipcode.split(',')[0] for zipcode in neighborhood_content if zipcode][0] if 'Die vollständige Adresse' in neighborhood: self.full_address = ' '.join(street.split()) else: self.full_address = '{}, {}'.format(street, neighborhood) map_url = self.MAP_URL.format( origin=self.full_address.replace(' ', '+'), destination=self.DEFAULT_DESTINATION) self.browse(map_url, 'Google Maps') self.browse(ad_url, 'AD') return self
def window_monitor(save_logs=True): """Loop to monitor open windows of the selected applications. An app can have multiple windows, each one with its title. :param save_logs: True to save logs (default), False to only display what would be saved (dry run). :return: """ last = {} monitor_start_time = datetime.now() LOGGER.info('Starting the window monitor now (%s)...', monitor_start_time.strftime(TIME_FORMAT)) if not save_logs: LOGGER.error('Not saving logs to the database') try: while True: sleep(.2) for app, new_titles in list_windows().items(): assert isinstance(app, str) assert isinstance(new_titles, list) if app not in last.keys(): last[app] = defaultdict(tuple) for index, new_title in enumerate(new_titles): if last[app][index] and last[app][index][1] == new_title: continue last_info = last[app][index] # Time since last saved time, or since the beginning of the monitoring start_time = last_info[0] if last_info else monitor_start_time end_time = datetime.now() # Save time info for the next change of window title last[app][index] = (end_time, new_title) # Save logs only after the first change of title old_title = last_info[1] if last_info else '' if old_title: try: video = SESSION_INSTANCE.query(Video).filter(Video.path == old_title).one() video_id = video.video_id except NoResultFound: video_id = None window_log = WindowLog(start_dt=start_time, end_dt=end_time, app_name=app, title=old_title, video_id=video_id) LOGGER.info(window_log) if save_logs: SESSION_INSTANCE.add(window_log) SESSION_INSTANCE.commit() if new_title: LOGGER.warning("%s Open window in %s: %s", end_time.strftime(TIME_FORMAT), app, new_title) except KeyboardInterrupt: return
def add_to_playlist(videos): """Add one or more videos to VLC's playlist. :param videos: One or more video paths. :type videos: list|str :return: True if videos were added to the playlist. :rtype: bool """ if not is_vlc_running(): LOGGER.error('VLC is not running, please open it first.') return False videos = [videos] if isinstance(videos, str) else videos pipe = pipes.Template() pipe.append('xargs -0 vlc --quiet --no-fullscreen --no-auto-preparse --no-playlist-autostart', '--') with pipe.open_w(PIPEFILE) as handle: handle.write('\0'.join(videos)) LOGGER.info('%d videos added to the playlist.', len(videos)) return True