Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alpkeskin
GitHub Repository: alpkeskin/mosint
Path: blob/master/v3/pkg/social/twitter/twitter.go
689 views
1
/*
2
Copyright © 2023 github.com/alpkeskin
3
*/
4
package twitter
5
6
import (
7
"encoding/json"
8
"fmt"
9
"io"
10
"net/http"
11
"net/url"
12
13
"github.com/alpkeskin/mosint/v3/internal/spinner"
14
"github.com/fatih/color"
15
)
16
17
type Twitter struct {
18
Exists bool
19
}
20
21
type response struct {
22
Valid bool `json:"valid"`
23
Msg string `json:"msg"`
24
Taken bool `json:"taken"`
25
}
26
27
func New() *Twitter {
28
return &Twitter{}
29
}
30
31
func (t *Twitter) Check(email string) {
32
spinner := spinner.New("Twitter Account Checking")
33
spinner.Start()
34
35
twitterUrl := "https://api.twitter.com/i/users/email_available.json"
36
data := url.Values{}
37
data.Set("email", email)
38
r, err := http.Get(twitterUrl + "?" + data.Encode())
39
40
if err != nil {
41
spinner.StopFail()
42
spinner.SetMessage(err.Error())
43
return
44
}
45
46
r.Header.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
47
48
if err != nil {
49
spinner.StopFail()
50
spinner.SetMessage(err.Error())
51
return
52
}
53
54
if r.StatusCode != http.StatusOK {
55
msg := fmt.Sprintf("Status code error: %d %s", r.StatusCode, r.Status)
56
spinner.StopFail()
57
spinner.SetMessage(msg)
58
return
59
}
60
61
body, err := io.ReadAll(r.Body)
62
63
if err != nil {
64
spinner.StopFail()
65
spinner.SetMessage(err.Error())
66
return
67
}
68
69
var response response
70
err = json.Unmarshal(body, &response)
71
72
if err != nil {
73
spinner.StopFail()
74
spinner.SetMessage(err.Error())
75
return
76
}
77
78
if !response.Taken {
79
t.Exists = false
80
spinner.Stop()
81
return
82
}
83
84
t.Exists = true
85
spinner.Stop()
86
}
87
88
func (i *Twitter) Print() {
89
if i.Exists {
90
fmt.Println(color.GreenString("[+]"), "Twitter Account Exists", color.GreenString("\u2714"))
91
return
92
}
93
fmt.Println(color.RedString("[!]"), "Twitter Account Not Exists", color.RedString("\u2718"))
94
}
95
96