worst_captcha/scraper.go

51 lines
1.0 KiB
Go

package main
import (
"WorstCaptcha"
"fmt"
"github.com/kurrik/twittergo"
"gopkg.in/gcfg.v1"
"os"
"strings"
)
func main() {
var config WorstCaptcha.Config
var twitter *twittergo.Client
// Parse config file
if err := gcfg.ReadFileInto(&config, "worstcaptcha.gcfg"); err != nil {
fmt.Printf("Config error: %s\n", err)
os.Exit(1)
}
// Get Twitter Client
twitter = WorstCaptcha.NewTwitter(config)
// Do twitter search and loop
for _, tweet := range WorstCaptcha.DoSearch(twitter) {
fmt.Printf("\n=================\n")
// Type assert entities to be a map
entities := tweet["entities"].(map[string]interface{})
// Type assert media to be a list
mediaList := entities["media"].([]interface{})
// Type assert the media to be a map
media := mediaList[0].(map[string]interface{})
// Get the link
imageUrl := media["media_url_https"]
// Parts of word
parts := strings.Split(tweet.Text(), " ")
// Build word without link
word := strings.Join(parts[0:len(parts)-1], " ")
fmt.Println(imageUrl)
fmt.Println(word)
}
}