def confluence(): doc = requests.get( 'https://developer.atlassian.com/cloud/confluence/rest/') soup = BeautifulSoup(doc.content, features='html5lib') sections = soup.select("section") j = [] for i, sec in enumerate(sections): if i < 5: continue _id = sec.h3.get_text() try: name, path = sec.p.get_text().split() except ValueError: print(sec.p.get_text()) continue body = sec.div.get_text() j.append({ '_id': _id, 'name': name, 'path': path, 'body': body, }) with open(document_path('confluence_api.json'), 'w') as f: json.dump(j, f, indent=2)
def jira(): doc = requests.get( 'https://docs.atlassian.com/software/jira/docs/api/REST/latest/') soup = BeautifulSoup(doc.content, features='html5lib') resources = soup.select("#content > div > div > section > div.resource") j = [] for src in resources: d = {'resource': src.h3.get('id'), 'desc': src.p.get_text()} d.setdefault('method', []) for method in src.select('div.method'): name, path = method.h4.code.get_text().split('\xa0') d['method'].append({ '_id': method.h4.get('id'), 'name': name, 'path': path, 'body': method.select_one('.method-body').get_text(), }) j.append(d) with open(document_path('jira_api.json'), 'w') as f: json.dump(j, f, indent=2)
def touch_temp(category, template_string): suffix = config.get_section('CATEGORY', category, fallback=category) with NamedTemporaryFile(suffix=f'.{suffix}', dir=config.document_path(), delete=False) as tf: filepath = tf.name tf.write(template_string.encode()) tf.flush() call([editor, '+set backupcopy=yes', filepath]) tf.seek(0) edited = tf.read() return filepath, edited
def temp(category: str = 'md') -> tuple: template = config.get_section('TEMPLATE', category, fallback=None) if template: with open(config.document_path(template)) as f: template_string = f.read() else: template_string = '' filepath, edited = touch_temp(category, template_string) if len(edited) == len(template_string): print(f'Not edited! deleted temp file.') os.remove(filepath) return () return filepath, edited
def load(file='jira_api.json'): with open(document_path(file)) as f: data = json.load(f) return data
def load(file='confluence_api.json'): with open(document_path(file)) as f: data = json.load(f) return data
def edit(path): with open(config.document_path(path), 'a+b') as f: call([editor, '+set backupcopy=yes', path]) f.seek(0) buffer = f.read() return buffer