def get_releases(url, **kwargs): resp = requests.get(url, **kwargs) resp_str = resp.content.decode('utf-8') reg = re.compile( '<div class="release-entry">[\s\S]*?<!-- /.release -->\s*</div>') releases = reg.findall(resp_str) reg_head = re.compile( '<div class="d-flex flex-items-start">[\s\S]*?<a href="(.*)">(.*)</a>') reg_date_time = re.compile( '<relative-time datetime="(.*?)">.*</relative-time>') reg_content = re.compile('<div class="markdown-body">([\s\S]*?)</div>') result = [] for r in releases: link, title = common.reg_find_one(reg_head, r) dt_text = common.reg_find_one(reg_date_time, r) item = { 'url': url_jump(resp.url, link), 'title': title, 'datetime': convert_datetime(dt_text), 'description': html_to_plain_text(common.reg_find_one(reg_content, r)), } result.append(item) return result
def dialog_select(title, description, buttons: list, default=None): title = ObjectConvertor.to_object(title) description = ObjectConvertor.to_object(description) if default is None: default = len(buttons) elif isinstance(default, int): default += 1 else: default = ObjectConvertor.to_object(default) check = [str(i) for i in buttons] buttons = ObjectConvertor.to_object(buttons) [stat, out, err] = AppleScript.exec( 'display dialog %s with title %s buttons %s default button %s' % (description, title, buttons, default)) index = None if out != '': reg = re.compile('button returned:(.*)') content = common.reg_find_one(reg, out, None) if content in check: index = check.index(content) return index
def get_hid_idle_time(): content = common.execute_get_out( ['/usr/sbin/ioreg', '-c', 'IOHIDSystem', '-d', '4']) reg = re.compile(r'"HIDIdleTime" = (\d+)') result = common.reg_find_one(reg, content, None) return int(result) / 1000000000
def check_display_sleep(): content = common.execute_get_out( ['/usr/sbin/ioreg', '-n', 'AppleBacklightDisplay', '-d', '9']) reg = re.compile(r'"dsyp"={"min"=(\d+),"max"=(\d+),"value"=(\d+)}') result = common.reg_find_one(reg, content, None) if result is not None: [min_, max_, value] = result return min_ == value else: return False
def check_lid(): content = common.execute_get_out( ['/usr/sbin/ioreg', '-c', 'IOPMrootDomain', '-d', '4']) reg = re.compile(r'"AppleClamshellState" = (\S+)') result = common.reg_find_one(reg, content, None) if result == 'Yes': return True elif result == 'No': return False else: return None