-
Notifications
You must be signed in to change notification settings - Fork 29
/
parse.go
70 lines (65 loc) · 1.9 KB
/
parse.go
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
package main
import (
"encoding/csv"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strconv"
"time"
)
func main() {
tsvFile, _ := os.Create("data.tsv")
defer tsvFile.Close()
writer := csv.NewWriter(tsvFile)
writer.Comma = '\t'
defer writer.Flush()
files, _ := filepath.Glob("*.json")
var repos []Repo
for _, element := range files {
file, e := ioutil.ReadFile(element)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
var repo Repo
json.Unmarshal(file, &repo)
fmt.Println(repo.Url, repo.Stars)
repos = append(repos, repo)
}
sort.Sort(ByStars(repos))
header := []string{"stars", "language", "updated", "issues", "size", "forks", "watchers", "repo", "created", "description"}
writer.Write(header)
for _, repo := range repos {
url := repo.Url
stars := strconv.Itoa(repo.Stars)
lang := repo.Lang
openIssues := strconv.Itoa(repo.OpenIssues)
size := strconv.Itoa(repo.Size)
forks := strconv.Itoa(repo.Forks)
watchers := strconv.Itoa(repo.Watchers)
pushedAt := repo.PushedAt.Format("2006-01-02")
createdAt := repo.CreatedAt.Format("2006-01-02")
desc := repo.Desc
values := []string{stars, lang, pushedAt, openIssues, size, forks, watchers, url, createdAt, desc}
writer.Write(values)
}
}
type Repo struct {
Url string `json:"html_url"`
Stars int `json:"stargazers_count"`
Lang string `json:"language"`
OpenIssues int `json:"open_issues_count"`
Size int `json:"size"`
Forks int `json:"forks_count"`
Watchers int `json:"watchers_count"`
PushedAt time.Time `json:"pushed_at"`
CreatedAt time.Time `json:"created_at"`
Desc string `json:"description"`
}
type ByStars []Repo
func (a ByStars) Len() int { return len(a) }
func (a ByStars) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByStars) Less(j, i int) bool { return a[i].Stars < a[j].Stars }