@ -0,0 +1 @@ |
|||||
|
twitterConfig.json |
@ -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" |
||||
|
} |
||||
|
|
||||
|
``` |
@ -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
|
||||
|
} |
@ -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)) |
||||
|
} |
@ -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) |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
#!/bin/bash |
||||
|
festcat_llegeix <<< $1 |
@ -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 |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
#!/bin/bash |
||||
|
festcat_llegeix <<< $1 |
@ -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) |
||||
|
} |
@ -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) |
||||
|
} |