aboutsummaryrefslogtreecommitdiff
path: root/src/export.py
blob: b453bc48430754d1eecd139de164783a6abc0ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from github import Github
from github import Auth
import os

token = None
with open(os.path.expanduser('~') + "/.config/github/token", "r") as f:
    token = str(f.readline().strip())

auth = Auth.Token(token)

g = Github(auth=auth)

root = "."
datefmt = '%a, %d %b %Y %H:%M:%S %z'

repo = g.get_repo("dillo-browser/dillo")
open_issues = repo.get_issues(state="all")
for issue in open_issues:
    print(issue)
    n = issue.number
    title = issue.title
    body = issue.body
    os.makedirs("%s/%d" % (root, n), exist_ok=True)
    issue_file = "%s/%d/index.md" % (root, n)
    if body is None:
        body = ''

    body = body.replace('\r\n', '\n')

    with open(issue_file, "w") as f:
        f.write("Title: " + issue.title + '\n')
        f.write("Author: " + issue.user.login + '\n')
        f.write("Created: " + issue.created_at.strftime(datefmt) + '\n')
        f.write("State: " + issue.state + '\n')
        f.write('\n')
        f.write(body)
        for comment in issue.get_comments():
            f.write('\n\n--%--\n')
            f.write('From: ' + comment.user.login + '\n')
            f.write('Date: ' + comment.created_at.strftime(datefmt) + '\n')
            f.write('\n')
            f.write(comment.body.replace('\r\n', '\n'))

g.close()