diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ac193c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +twitterConfig.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..4792912 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# twitterReader +twitter reader assistant written in Go lang + +uses festival for the text to speech features + + +to execute +``` +./twitterReader +``` + +install festival +``` +sudo apt-get install festival festvox-kallpc16k +``` +install spanish +``` +sudo apt-get install festvox-ellpc11k +``` +install catalan voice +``` +sudo add-apt-repository ppa:zeehio/festcat +sudo apt-get update +sudo apt-get install festival-ca festvox-ca-ona-hts festcat-utils +``` + +needs the twitter account tokens in the file twitterConfig.json +```json +{ + "username": "account_name", + "consumer_key": "xxxxxxxxxxxxxx", + "consumer_secret": "xxxxxxxxxxx", + "access_token_key": "xxxxxxxxxx", + "access_token_secret": "xxxxxxx" +} + +``` diff --git a/color.go b/color.go new file mode 100644 index 0000000..e945ac5 --- /dev/null +++ b/color.go @@ -0,0 +1,57 @@ +package main + +import "fmt" + +//Color struct, defines the color +type Color struct{} + +var c Color + +//DarkGray color +func (c Color) DarkGray(t string) { + fmt.Print("\x1b[30;1m") //dark gray + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Red color +func (c Color) Red(t string) { + fmt.Print("\x1b[31;1m") //red + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Green color +func (c Color) Green(t string) { + fmt.Print("\x1b[32;1m") //green + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Yellow color +func (c Color) Yellow(t string) { + fmt.Print("\x1b[33;1m") //yellow + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Blue color +func (c Color) Blue(t string) { + fmt.Print("\x1b[34;1m") //blue + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Purple color +func (c Color) Purple(t string) { + fmt.Print("\x1b[35;1m") //purple + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} + +//Cyan color +func (c Color) Cyan(t string) { + fmt.Print("\x1b[36;1m") //cyan + fmt.Println(t) + fmt.Print("\x1b[0m") //defaultColor +} diff --git a/festival.go b/festival.go new file mode 100644 index 0000000..7fb0535 --- /dev/null +++ b/festival.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "os/exec" + "strings" +) + +func festivalEn(text string) { + path, err := exec.LookPath("festival") + if err != nil { + return + } + festival := exec.Command(path, "--tts") + reader := strings.NewReader(text) + festival.Stdin = reader + err = festival.Run() +} + +func festivalCa(text string) { + out, err := exec.Command("bash", "readCa.sh", text).Output() + if err != nil { + fmt.Println("error") + } + fmt.Println(string(out)) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..f397ecb --- /dev/null +++ b/main.go @@ -0,0 +1,16 @@ +package main + +func main() { + c.Cyan("hi") + client := readConfigTokensAndConnect() + tweets := getTimeline(client) + for i := 0; i < len(tweets); i++ { + c.Cyan(tweets[i].User.ScreenName + ": " + tweets[i].Text) + c.Green(tweets[i].Lang) + if tweets[i].Lang == "en" { + festivalEn(tweets[i].User.ScreenName + ": " + tweets[i].Text) + } else { + festivalCa(tweets[i].User.ScreenName + ": " + tweets[i].Text) + } + } +} diff --git a/readCa.sh b/readCa.sh new file mode 100644 index 0000000..fbaaf8f --- /dev/null +++ b/readCa.sh @@ -0,0 +1,2 @@ +#!/bin/bash +festcat_llegeix <<< $1 diff --git a/readConfigTokensAndConnect.go b/readConfigTokensAndConnect.go new file mode 100644 index 0000000..faf531d --- /dev/null +++ b/readConfigTokensAndConnect.go @@ -0,0 +1,40 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + + "github.com/dghubble/go-twitter/twitter" + "github.com/dghubble/oauth1" +) + +//Config stores the data from json twitterConfig.json file +type Config struct { + ConsumerKey string `json:"consumer_key"` + ConsumerSecret string `json:"consumer_secret"` + AccessTokenKey string `json:"access_token_key"` + AccessTokenSecret string `json:"access_token_secret"` +} + +func readConfigTokensAndConnect() (client *twitter.Client) { + var config Config + file, e := ioutil.ReadFile("twitterConfig.json") + if e != nil { + fmt.Println("error:", e) + } + content := string(file) + json.Unmarshal([]byte(content), &config) + fmt.Println("twitterConfig.json read comlete") + + fmt.Print("connecting to twitter api --> ") + configu := oauth1.NewConfig(config.ConsumerKey, config.ConsumerSecret) + token := oauth1.NewToken(config.AccessTokenKey, config.AccessTokenSecret) + httpClient := configu.Client(oauth1.NoContext, token) + // twitter client + client = twitter.NewClient(httpClient) + + fmt.Println("connection successfull") + + return client +} diff --git a/readEs.sh b/readEs.sh new file mode 100644 index 0000000..fbaaf8f --- /dev/null +++ b/readEs.sh @@ -0,0 +1,2 @@ +#!/bin/bash +festcat_llegeix <<< $1 diff --git a/timeline.go b/timeline.go new file mode 100644 index 0000000..7724dd6 --- /dev/null +++ b/timeline.go @@ -0,0 +1,13 @@ +package main + +import ( + "github.com/dghubble/go-twitter/twitter" +) + +func getTimeline(client *twitter.Client) []twitter.Tweet { + homeTimelineParams := &twitter.HomeTimelineParams{ + Count: 4, + } + tweets, _, _ := client.Timelines.HomeTimeline(homeTimelineParams) + return (tweets) +} diff --git a/twitterReader b/twitterReader new file mode 100755 index 0000000..72100aa Binary files /dev/null and b/twitterReader differ diff --git a/waitTime.go b/waitTime.go new file mode 100644 index 0000000..b7ea70c --- /dev/null +++ b/waitTime.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "strconv" + "time" +) + +func waitMinutes(minutes int) { + //wait to avoid the twitter api limitation + timeToSleep := time.Duration(minutes) * time.Minute + fmt.Println("waiting " + strconv.Itoa(minutes) + " min") + fmt.Println(time.Now().Local()) + time.Sleep(timeToSleep) +} +func waitSeconds(seconds int) { + //wait to avoid the twitter api limitation + timeToSleep := time.Duration(seconds) * time.Second + fmt.Println("waiting " + strconv.Itoa(seconds) + " seconds") + fmt.Println(time.Now().Local()) + time.Sleep(timeToSleep) +}