/
read_github
executable file
·89 lines (63 loc) · 2.08 KB
/
read_github
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
import os
import sys
import argparse
import json
from groundstation.station import Station
from groundstation.node import Node
from groundstation import logger
log = logger.getLogger(__name__)
from groundstation.protocols import github as github_protocol
def _write_header(output):
for tag in ("<html>",
"<head>",
"<title>Test Issue</title>",
"</head>",
"<body>",
):
output.write(tag)
output.write("\n")
def _write_root(root, output):
output.write("<h1>%s :: %s</h1>\n" % (root.channel, root.id))
def _write_title(obj, output):
output.write("<h3>%s</h3>\n" % (obj["body"]))
def _write_body(obj, output):
output.write("<p><pre>%s</pre></p>" % (obj["body"]))
def _write_comment(obj, output):
output.write("<p><pre>%s</pre></p>" % (obj["body"]))
def _create_option_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--repo", dest='repo', action='store')
parser.add_argument("--issue", dest='issue', action='store', type=int)
parser.add_argument("--output", dest='output', action='store')
return parser
def _create_station():
station_path = os.path.expanduser("~/.groundstation")
myself = Node()
station = Station(station_path, myself)
return station
def main(argv):
parser = _create_option_parser()
station = _create_station()
args = parser.parse_args(argv[1:])
adaptor = github_protocol.GithubReadAdaptor(station, args.repo)
if args.output:
output = open(args.output, 'w')
else:
output = sys.stdout
issue = adaptor.get_issue(args.issue)
root = issue.pop()
_write_header(output)
_write_root(root, output)
while issue:
obj = issue.pop()
data = json.loads(obj.data)
if data["type"] == "title":
_write_title(data, output)
elif data["type"] == "body":
_write_body(data, output)
elif data["type"] == "comment":
_write_comment(data, output)
if __name__ == "__main__":
main(sys.argv)
# def __init__(self, id, channel, protocol):