Created
January 8, 2017 18:22
-
-
Save bdittmer/6edde66d094ea4521d4010d7d163a84b to your computer and use it in GitHub Desktop.
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" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
"regexp" | |
"strconv" | |
) | |
func main() { | |
// enter url here | |
getComments("") | |
} | |
var re = regexp.MustCompile("[0-9]+") | |
func getComments(url string) { | |
resp, err := http.Get(url) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
var r FbCommentResp | |
if err = json.Unmarshal(body, &r); err != nil { | |
panic(err) | |
} | |
for _, comment := range r.Data { | |
numbers := re.FindAllString(comment.Message, 1) | |
if len(numbers) == 1 { | |
guess, err := strconv.Atoi(numbers[0]) | |
if err != nil { | |
continue | |
} | |
if guess >= 325 && guess <= 333 { | |
fmt.Printf("%s guessed %d\n", comment.From.Name, guess) | |
} | |
if guess == 329 { | |
fmt.Printf("%s nailed it @ %s: %s, quitting\n", comment.From.Name, comment.CreatedTime, comment.Message) | |
os.Exit(0) | |
} | |
} | |
} | |
getComments(r.Paging.Next) | |
} | |
type FbCommentResp struct { | |
Data []struct { | |
CreatedTime string `json:"created_time"` | |
From struct { | |
Name string `json:"name"` | |
ID string `json:"id"` | |
} `json:"from"` | |
Message string `json:"message"` | |
ID string `json:"id"` | |
} `json:"data"` | |
Paging struct { | |
Cursors struct { | |
Before string `json:"before"` | |
After string `json:"after"` | |
} `json:"cursors"` | |
Next string `json:"next"` | |
} `json:"paging"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment