Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
File: api.py Progetto: jongwony/jw
def load(file='jira_api.json'):
    with open(document_path(file)) as f:
        data = json.load(f)
    return data
Esempio n. 6
0
def load(file='confluence_api.json'):
    with open(document_path(file)) as f:
        data = json.load(f)
    return data
Esempio n. 7
0
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