def extract_priority_label(body): """Parse url from body and query the priority labels.""" hostname = domain_name(extract_url(body)) if hostname: priorities = ['critical', 'important', 'normal'] # Find host_name in DB for site in site_db.query(Site).filter_by(url=hostname): return 'priority-{}'.format(priorities[site.priority - 1]) # No host_name in DB, find less-level domain (>2) # If host_name is lv4.lv3.example.com, find lv3.example.com/example.com subparts = hostname.split('.') domains = ['.'.join(subparts[i:]) for i, subpart in enumerate(subparts) if 0 < i < hostname.count('.')] for domain in domains: for site in site_db.query(Site).filter_by(url=domain): return 'priority-{}'.format(priorities[site.priority - 1]) return None
def dump_to_db(title, body, issue_number): url = extract_url(body) issue_db.add(WCIssue(issue_number, title, url, body)) issue_db.commit()