-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
120 lines (100 loc) · 3.35 KB
/
main.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
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
)
const githubSearchURL = "https://api.github.com/search/repositories"
type GitHubSearchResponse struct {
TotalCount int `json:"total_count"`
Items []GitHubRepo `json:"items"`
}
type GitHubRepo struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"html_url"`
}
func main() {
fileName := flag.String("f", "", "file name")
accessToken := flag.String("t", "", "GitHub access token")
flag.Parse()
if *fileName == "" {
fmt.Println("Please specify a file name using the -f flag.")
os.Exit(1)
}
if *accessToken == "" {
fmt.Println("Please specify a GitHub access token using the -t flag.")
os.Exit(1)
}
//start
welcome()
// Read the search term from the file
searchBytes, err := ioutil.ReadFile(*fileName)
if err != nil {
panic(err)
}
searchTerm := strings.TrimSpace(string(searchBytes))
searchURL := fmt.Sprintf("%s?q=%s", githubSearchURL, searchTerm)
req, err := http.NewRequest("GET", searchURL, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", fmt.Sprintf("token %s", *accessToken))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var searchResponse GitHubSearchResponse
err = json.Unmarshal(body, &searchResponse)
if err != nil {
panic(err)
}
// Print the search results
fmt.Printf("Total count: %d\n", searchResponse.TotalCount)
for _, item := range searchResponse.Items {
fmt.Printf("Name: %s\n", item.Name)
fmt.Printf("Description: %s\n", item.Description)
fmt.Printf("URL: %s\n", item.URL)
}
// Write the search results to a JSON file
file, err := json.MarshalIndent(searchResponse, "", " ")
if err != nil {
panic(err)
}
err = ioutil.WriteFile("search_results.json", file, 0644)
if err != nil {
panic(err)
}
fmt.Println("Search results written to search_results.json")
}
func welcome() {
//
been := `
██████ ██ ████████ ██ ██ ██ ██ ██████ ███████ ███████ █████ ██████ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ███ ██ ██ ███████ ██ ██ ██████ ███████ █████ ███████ ██████ ██ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██ ██ ██ ██ ██████ ██████ ███████ ███████ ██ ██ ██ ██ ██████ ██ ██
`
fmt.Printf("%v", been)
fmt.Printf("\t\t\t\t v 1.0 - 2023\n\n")
fmt.Println("Are You Ready ? :-) ")
time.Sleep(2 * time.Second)
fmt.Println("3")
time.Sleep(2 * time.Second)
fmt.Println("2")
time.Sleep(1 * time.Second)
fmt.Println("▄︻̷̿┻̿═━一")
}