-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpulllist.go
131 lines (104 loc) · 2.74 KB
/
pulllist.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"flag"
"fmt"
"net/http"
"os"
"time"
//"reflect"
"encoding/json"
"io/ioutil"
"sort"
"strconv"
"strings"
"golang.org/x/crypto/ssh/terminal"
)
type allJSON struct {
Results map[string]book
}
type book struct {
ID string `json:"id"`
Fields bookFields
}
type bookFields struct {
Title string `json:"dc_solr_sortable_title"`
Type string `json:"type"`
}
func midnight(t time.Time) (midnight time.Time) {
yy := t.Year()
mm := t.Month()
dd := t.Day()
return time.Date(yy, mm, dd, 0, 0, 0, 0, time.UTC)
}
func main() {
advance := flag.Int("advance", 0, "How many weeks in advance to show")
jsonOnly := flag.Bool("json", false, "Show the JSON results only")
single := flag.Bool("1", false, "Single page mode")
flag.Parse()
date := time.Now()
date = date.Add(time.Duration(*advance*7*24) * time.Hour)
day := date.Weekday()
daysUntilWednesday := 0
if day < 3 {
daysUntilWednesday = 3 - int(day)
} else if day > 3 {
daysUntilWednesday = 10 - int(day)
}
nextWednesday := date.Add(time.Duration(24*daysUntilWednesday) * time.Hour)
nextThursday := date.Add(time.Duration(24*(daysUntilWednesday+1)) * time.Hour)
nextWednesdayStart := midnight(nextWednesday)
nextThursdayStart := midnight(nextThursday)
start := strconv.FormatInt(nextWednesdayStart.Unix(), 10)
end := strconv.FormatInt(nextThursdayStart.Unix(), 10)
booktype := "comic%7Cgraphic_novel"
url := "http://www.dccomics.com/proxy/search?type=" + booktype + "&startdate=" + start + "&enddate=" + end
//fmt.Println(url)
resp, err := http.Get(url)
if err != nil {
fmt.Println(err.Error())
}
body, _ := ioutil.ReadAll(resp.Body)
if *jsonOnly {
fmt.Println(string(body))
os.Exit(0)
}
var alljson allJSON
err = json.Unmarshal(body, &alljson)
if err != nil {
fmt.Println(err.Error())
}
var comics []string
var graphicNovels []string
for _, v := range alljson.Results {
if v.Fields.Type == "comic" {
comics = append(comics, strings.Title(strings.ToLower(v.Fields.Title)))
} else if v.Fields.Type == "graphic_novel" {
graphicNovels = append(graphicNovels, strings.Title(strings.ToLower(v.Fields.Title)))
}
}
sort.Strings(comics)
sort.Strings(graphicNovels)
_, height, err := terminal.GetSize(0)
maxlines := height - 1
var list []string
list = append(list, fmt.Sprintf("Comics:\n"))
for _, v := range comics {
list = append(list, fmt.Sprintf("%v\n", v))
}
list = append(list, fmt.Sprintf("\n"))
list = append(list, fmt.Sprintf("Graphic Novels:\n"))
for _, v := range graphicNovels {
list = append(list, fmt.Sprintf("%v\n", v))
}
for k, v := range list {
if k == 0 || k%maxlines != 0 {
fmt.Printf(v)
continue
}
if !*single {
var input string
fmt.Fprintf(os.Stderr, "MORE")
fmt.Scanln(&input)
}
}
}