def __init__(self, schedule_section): """Initialize a Schedule object.""" # schedule settings self.poll_frequency = to_int(schedule_section.poll_frequency) self.daily_at = self.format_daily_times(schedule_section.daily_at) self.hourly_at = to_int(to_list(schedule_section.hourly_at)) # skip conditions self.skip_hours_of_day = to_int(to_list(schedule_section.hours_of_day)) self.skip_days_of_week = to_list(schedule_section.days_of_week) self.skip_days_of_month = to_int(to_list(schedule_section.days_of_month)) self.skip_days_of_year = to_list(schedule_section.days_of_year) # lowercase skip days of week self.skip_days_of_week = [day.lower() for day in self.skip_days_of_week] # track state self.start_time = None self.last_time = None self.poll_count = 0 self.run_count = 0 # optional poll_message self.poll_message = ''
def record(datum): return { 'locale': datum[0], 'city': datum[0], 'official': datum[1], 'address': datum[2:5], 'phones': to_list(datum[5]), 'faxes': to_list(datum[6]), }
def clean_row(row): row['city'] = ' '.join( x.capitalize() for x in row['city'].split()) # title() doesn't work on Beans's row['official'] = row['official'].title() if row['official'] else None row['locale'] = row['city'] row['emails'] = to_list(row.pop('email')) row['phones'] = ['603-' + num for num in to_list(row.pop('phone'))] row['faxes'] = ['603-' + num for num in to_list(row.pop('fax'))] return row
def parse_county(county_name, county_text): locale = county_name.title() + ' County' match_dict = re_county.search(f'{county_text}\n\n').groupdict() return { 'locale': locale, 'county': locale, 'phones': to_list(match_dict['phone']), 'faxes': to_list(match_dict['fax']), 'address': match_dict['addr'].replace('\n', ', '), # emails are supplied in a separate list }
def parse_row(row): cols = [col.get_text('\n').strip() for col in row('td')] county = f"{cols[1]} County" phfaxemail = re_phfaxemail.match(cols[3]).groupdict() return { 'locale': county, 'county': county, 'official': cols[2], 'phones': to_list(phfaxemail.get('phone')), 'faxes': to_list(phfaxemail.get('fax')), 'emails': to_list(phfaxemail.get('email')), 'address': cols[4], }
def draw_overlay(self, vis): markers = to_list(int32(self.markers)) col = (0, 255, 255) for p in markers: cv.Circle(vis, p, 5, col, 2, cv.CV_AA) cv.Line(vis, markers[0], markers[1], col, 2, cv.CV_AA) cv.Line(vis, markers[0], markers[2], col, 2, cv.CV_AA)
def highlight(self, items): """ Sets the highlighting for specified tree items. Arguments: items [list (QTreeWidgetItem)]: List of highlited items """ itemset = {} if items is not None: for i in to_list(items): itemset[i] = True if self._view is not None: treeitems = self._view.findItems('*', Q.Qt.MatchWildcard | \ Q.Qt.MatchRecursive) root = self._view.invisibleRootItem() block = self.signalsBlocked() self.blockSignals(True) for item in treeitems: hlt = itemset.get(item, False) for c in xrange(self._view.columnCount()): item.setData(c, Role.HighlightRole, hlt) item.setBackground(c, Q.Qt.yellow \ if hlt else root.background(c)) self.blockSignals(block)
def parse_locale(datum): # some locales use an extra column for address if datum[5].strip() and re_phone_fax.search(datum[5]) is None: addr = datum[2:6] datum.pop(5) else: addr = datum[2:5] return { 'locale': datum[0], 'city': datum[0], 'official': datum[1], 'address': ', '.join(x.strip() for x in addr if x), 'phones': to_list(datum[5]), 'faxes': to_list(datum[6]), }
def add_unknown(self, names): """Add one or several unknowns. Arguments: typ (str): One of 'grel', 'grno', 'el' or 'no'. names (str or list[str]): One or more names of entity. """ self._unknown.extend(to_list(names))
def add_topo(self, typ, names): """Add one or several topological entities of type *typ*. Arguments: typ (str): One of 'grel', 'grno', 'el' or 'no'. names (str or list[str]): One or more names of entity. """ self._topo[typ] = self._topo.get(typ, []) + to_list(names)
def _typeInformation(self): """ Gets the information text about keyword type. """ inflist = [] kword = self.path().keyword() if kword is not None: kwtypelist = [] kwdef = kword.definition enum = kwdef.get('into') is not None if enum and sorted(kwdef.get('into')) == ["NON", "OUI"]: txt = "'%s'/'%s'" % (bold(translate("ParameterPanel", "Yes")), bold(translate("ParameterPanel", "No"))) inflist.append(txt) elif kwdef.get('typ') is not None: kwtypelist = to_list(kwdef.get('typ')) for kwtype in kwtypelist: if kwtype is None: continue if kwtype == 'I': txt = bold(translate("ParameterPanel", "integer")) lim = self._numberLimitsInfo(kwdef.get('val_min'), kwdef.get('val_max')) if len(lim): txt += " " + lim elif kwtype == 'R': txt = bold(translate("ParameterPanel", "float")) lim = self._numberLimitsInfo(kwdef.get('val_min'), kwdef.get('val_max')) if len(lim): txt += " " + lim elif kwtype == 'TXM': txt = bold(translate("ParameterPanel", "string")) elif is_subclass(kwtype, CATA.package('DataStructure').CO): txt = bold(translate("ParameterPanel", "macro name")) elif isinstance(kwtype, (types.TypeType, types.ClassType)): txt = translate("ParameterPanel", "object with type") txt += bold(" '%s'" % kwtype.__name__) else: txt = bold(str(kwtype)) if len(txt): if enum: txt += " (%s)" % italic(translate("ParameterPanel", "enumerated")) inflist.append(txt) info = "" if len(inflist): islist = self.path().isKeywordSequence() and \ not self.path().isInSequence() prefix = translate("ParameterPanel", "List with types") \ if islist else translate("ParameterPanel", "Value types") info = prefix + ": " + ", ".join(inflist) return info
def get_locality_datum(id_, attempt=0): if attempt > 5: return {} page = cache_request( BASE_URL, method='POST', data={'LocalityUid': id_}, wait=random.uniform(2, 3), ) soup = BeautifulSoup(page, 'lxml') results_wrappers = soup.select('.resultsWrapper') if results_wrappers: keys = results_wrappers[0].select('h5.display-lable') vals = results_wrappers[0].select('p.display-field') results = { key.text.strip(): val.text.strip() for key, val in zip(keys, vals) } locale = soup.select( 'select > option[selected="selected"]')[0].text.title() final = { 'locale': locale, 'county': locale if locale.endswith('County') else None, 'city': locale if not locale.endswith('County') else None, 'official': results['Registrar'], 'emails': to_list(results['Email']), 'faxes': to_list(results['Fax']), 'url': results.get('URL'), 'address': results.get('Mailing Address') or results.get('Address'), 'physicalAddress': results.get('Physical Address'), } return {k: v for k, v in final.items() if v} cached_files = glob.glob(os.path.join(work_dir, '*.*')) latest_file = max(cached_files, key=os.path.getctime) logging.warning( "error in Virginia file; deleting cached file %s; retry after wait", latest_file) os.remove(latest_file) sleep(30) return get_locality_datum(id_, attempt + 1)
def parse_county(county): county_name = county['Name'].title() + ' County' return { 'locale': county_name, 'county': county_name, 'official': county['DirectorName'].title(), 'emails': [county['Email']], 'faxes': to_list(county['FaxNum']), 'phones': [join_fields(county, ' x', ['OfficePhoneNum', 'OfficePhoneNumExt'])], 'address': join_fields(county, ', ', ['MailingAddr1', 'MailingAddr2', 'MailingAddrCSZ']), 'physicalAddress': join_fields(county, ', ', ['PhysicalAddr1', 'PhysicalAddr2', 'PhysicalAddrCSZ']), 'url': county['WebsiteAddr'], }
def setEditColumns(self, columns): """ Specify editable columns. Specify -1 as parameter to enable edition in all model columns. Arguments: columns (int, list[int]): Editable column(s). """ if columns == -1: self.columns = None else: columns = to_list(columns) self.columns = columns if columns else None
def showChildIems(self, items): """ Provide visibility of specified items by expanding their parent items. Arguments: items ([QTreeWidgetItem]): List with items to show. """ if items is None: return for i in to_list(items): pitem = i.parent() while pitem is not None: if not pitem.isExpanded(): self._view.expandItem(pitem) pitem = pitem.parent()
def format_daily_times(daily_times): """Format daily time values as HH:MM adding leading/trailing 0's and colon if missing.""" # make sure daily_times is a list daily_times = to_list(daily_times) output = [] for daily_time in daily_times: # if missing :MM, add :MM as suffix if ':' not in daily_time: daily_time = f'{daily_time}:00' # pad single H: as 0H: if daily_time[1] == ':': daily_time = f'0{daily_time}' output.append(daily_time) return output
def check_selection(selection, **kwargs): """ Check that selection suits specified conditions. Conditions are specified as the keyword arguments; supported criteria are currently the following: - size (int): Number of selected entities. - typeid (int, list[int]): Type(s) of selected item(s). - flags (int): Item flags (*Qt.ItemFlags*). Arguments: selection (list[Entity]): Selected entities. **kwargs: Keyword arguments specifying selection criteria. Returns: bool: *True* if selection suits given criteria; *False* otherwise. """ def _match(_types, _sel): _matched = False for _type in _types: if _type & _sel: _matched = True break return _matched result = True if "size" in kwargs: result = result and len(selection) == kwargs["size"] else: result = len(selection) > 0 if result and "typeid" in kwargs: typeid = to_list(kwargs["typeid"]) for item in selection: result = result and _match(typeid, item.type) if not result: break if result and "flags" in kwargs: for item in selection: result = result and (item.flags & kwargs["flags"]) if not result: break return result
def updateCurrent(self, items, tonext, wrap=True): """ Sets the current the item after current by first item from specified list. Arguments: items (QTreeWidgetItem|[QTreeWidgetItem]): List with items to show. tonext (bool): Next or prevoius item flags. """ if items is None or not len(items): return itemset = {} if items is not None: for i in to_list(items): itemset[i] = True cur = self._view.currentItem() step = 1 if tonext else -1 treeitems = self._view.findItems('*', Q.Qt.MatchWildcard | \ Q.Qt.MatchRecursive) index = treeitems.index(cur) if cur in treeitems else -1 index += step cur = None start = -1 while cur is None and index < len(treeitems) and \ index >= 0 and index != start: if itemset.get(treeitems[index], False): cur = treeitems[index] if start < 0: start = index index += step if wrap and index >= len(treeitems): index = 0 if wrap and index < 0: index = len(treeitems) - 1 if cur is not None: self._view.setCurrentItem(cur) self._view.scrollToItem(cur)
def _is_exist_keyword(self, command, storage, keyword, value=None): """ Checks existance the parameters in storage. Parameter should has keyword which starts with specified 'keyword' and has value which starts with specified 'value' if it's not None Arguments: storage (dict): Command storage. keyword (str): Search keyword pattern string value (str): Search value pattern string Returns: bool: Check state. 'True' if the storage contains parameter according given patterns """ res = False if isinstance(storage, dict): for key in storage.keys(): res = match_string(key, keyword) or \ match_string(translate_command(command, key), keyword) res = res and (value is None or len(value) == 0 or \ self._check_value(command, key, storage[key], value)) if not res: childstorage = storage[key] if isinstance(childstorage, dict): res = self._is_exist_keyword(command, childstorage, keyword, value) else: for param in to_list(childstorage): res = self._is_exist_keyword( command, param, keyword, value) if res: break if res: break return res
def _check_value(self, command, keyword, value, pattern): """ Checks existance of the pattern in value. Arguments: command (str): Command title. keyword (str): Parameter keyword. value (str|list): Parameter value. pattern (str): Value pattern string. Returns: bool: Check state. 'True' if the value contains given pattern. """ res = False if value is not None: values = to_list(value) for item in values: val = str(item) res = match_string(val, pattern) or \ match_string(translate_command(command, keyword, val), pattern) if res: break return res
def transform(self): cv.GetAffineTransform(to_list(self.markers0), to_list(self.markers), self.M) cv.WarpAffine(self.src, self.dst, self.M)
def test_to_list(): str_test = 'foo, None, baz, 1, , 3' str_list = to_list(str_test) print(str_list[4]) #print(str_list[5]) """
with open(dir_path(__file__) + '/cache/data.jl') as fh: for line in fh: data = json.loads(line) if data['type'] != 'local': continue value = filter_dict_by_key(data, {'clerk', 'email', 'phone', 'fax'}) value['county'] = data['CountyName'] value['city'] = data['jurisdictionName'] # rename Twp to Township if value['city'].endswith('Twp'): value['city'] = value['city'][:-3] + 'Township' county = value['county'].title().strip() output += [{ 'locale': value['city'] + ':' + county, 'city': value['city'], 'county': county, 'emails': to_list(value['email']), 'phones': to_list(value['phone']), 'faxes': to_list(value['fax']), 'official': value['clerk'], }] with open('public/michigan.json', 'w') as fh: json.dump(output, fh)
def add_messages(self, msglist): """Add messages to the list of messages of this execution.""" existing = [msg.checksum for msg in self._messages] for msg in to_list(msglist): if msg.checksum not in existing: self._messages.append(msg)