python 将打开标记的问题和时间估计/时间框导出为CSV

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 将打开标记的问题和时间估计/时间框导出为CSV相关的知识,希望对你有一定的参考价值。


"""
Exports open Issues with a specific label and extract time box from a specified repository to a CSV file
Uses basic authentication (Github username + password) to retrieve Issues
from a repository that username has access to. Supports Github API v3.
Base on this original gists: https://gist.github.com/unbracketed/3380407
usage: run [gh username] [gh password] [repo (i.e. gizra/danel)] [label to include (i.e. '1st priority')]
"""
import csv
import requests
import sys
import re


GITHUB_USER = sys.argv[1]
GITHUB_PASSWORD = sys.argv[2]
REPO = sys.argv[3]  # format is username/repo
ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/%s/issues' % REPO
AUTH = (GITHUB_USER, GITHUB_PASSWORD)

def extract_time_box(title):
    # search for a [digit+h] to extract time estimation as integer/ "No estimation"
    extract = re.search(r'\[([\d\.]+)h\]', title)
    if extract != None:
        timebox = str(extract.group(1))
    else:
        return "No Estimation"
    return timebox

def write_issues(r):
    """output a list of issues to csv"""
    if not r.status_code == 200:
        raise Exception(r.status_code)
    for issue in r.json():
        labels = issue['labels']
        for label in labels:                              # filter by label, not a case sensitive
            if label['name'].lower() == sys.argv[4].lower() and issue['state'] == 'open':
                title = issue['title']
                csvout.writerow([issue['number'], title, extract_time_box(title)])
                print(title)


def get_headers(r):
    """extract pages from headers"""
    pages = dict(
        [(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in
            [link.split(';') for link in
                r.headers['link'].split(',')]])
    return pages


csvfile = '%s-issues-%s.csv' % (REPO.replace('/', '-'), sys.argv[4])
with open(csvfile, 'w', encoding='utf8', newline='') as csvfile:
    csvout =  csv.writer(csvfile, delimiter=',')
    header = (('id', 'Title', 'Time Estimation'))
    csvout.writerow(header)

    r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH) # first call
    print("getting 1")
    pages = get_headers(r) # get next/last info
    write_issues(r)
    counter = 2
    #more pages? examine the 'link' header returned
    if 'link' in r.headers:
        pages = get_headers(r) # get next/last info
        while 'next' in pages:
            print ("getting ",counter)
            counter +=1
            print(pages['next'])
            r = requests.get(pages['next'], auth=AUTH)
            pages = get_headers(r) # get next/last info
            write_issues(r)
            pages = get_headers(r)

以上是关于python 将打开标记的问题和时间估计/时间框导出为CSV的主要内容,如果未能解决你的问题,请参考以下文章

基准标记或相机姿态估计

python照相机模型与增强现实

使用单相机进行标记姿态估计的误差

使用正则表达式关闭打开的 XML 标记

如何为 sklearn 的 CountVectorizer 编写自定义标记器以将所有 XML 标记以及打开和关闭标记之间的所有文本视为标记

贝叶斯公式与最大后验估计(MAP)