Last active
August 18, 2017 19:38
-
-
Save kisPocok/a9f9169750a3142fb7fa067bef10d3d3 to your computer and use it in GitHub Desktop.
List recently fired colleges (kudos for slack!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"fmt" | |
"net/http" | |
"time" | |
) | |
type SlackUsers struct { | |
ID string `json:"id"` | |
Name string `json:"name"` | |
RealName string `json:"real_name"` | |
Deleted bool `json:"deleted"` | |
Profile SlackProfile `json:"profile"` | |
Updated int64 `json:"updated"` | |
} | |
type SlackProfile struct { | |
FirstName string `json:"first_name"` | |
LastName string `json:"last_name"` | |
RealName string `json:"real_name"` | |
ImageURL string `json:"image_192"` | |
} | |
type SlackResponse struct { | |
OK bool `json:"ok"` | |
Members []SlackUsers `json:"members"` | |
CacheTimestamp int `json:"cache_ts"` | |
} | |
var myClient = &http.Client{Timeout: 10 * time.Second} | |
func main() { | |
token := flag.String("token", "", "Slack token goes here, grab yours from https://api.slack.com/methods/users.list/test") | |
flag.Parse() | |
var response SlackResponse | |
url := fmt.Sprintf("https://slack.com/api/users.list?token=%s&pretty=1", *token) | |
getJson(url, &response) | |
fmt.Println("Deleted slack users:") | |
for _, User := range response.Members { | |
if User.Deleted { | |
if User.Profile.RealName != "" { | |
fmt.Print(User.Profile.RealName) | |
} else if User.RealName != "" { | |
fmt.Print(User.RealName) | |
} else if User.Profile.FirstName != "" || User.Profile.LastName != "" { | |
fmt.Print(User.Profile.FirstName, User.Profile.LastName) | |
} else { | |
fmt.Print("Unnamed") | |
} | |
fmt.Print(" ", time.Unix(User.Updated, 0)) | |
fmt.Print(" ", User.Profile.ImageURL) | |
fmt.Print("\n") | |
} | |
} | |
} | |
func getJson(url string, target interface{}) error { | |
r, err := myClient.Get(url) | |
if err != nil { | |
return err | |
} | |
defer r.Body.Close() | |
return json.NewDecoder(r.Body).Decode(target) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment