Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
haarts committed Dec 3, 2013
0 parents commit ed61be3
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
settings.json
Empty file added README.md
Empty file.
48 changes: 48 additions & 0 deletions golang_news.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"github.com/ChimeraCoder/anaconda"
rss "github.com/jteeuwen/go-pkg-rss"
"net/url"
"os"
"time"
)

const timeout = 50

func main() {
go PollFeed("http://blog.golang.org/feed.atom", timeout)
go PollFeed("https://news.ycombinator.com/rss", timeout)
PollFeed("http://www.reddit.com/r/golang.rss", timeout)
}

func PollFeed(uri string, timeout int) {
feed := rss.New(timeout, true, chanHandler, itemHandler)

for {
if err := feed.Fetch(uri, nil); err != nil {
fmt.Fprintf(os.Stderr, "[e] %s: %s", uri, err)
return
}

<-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))
}
}

func chanHandler(feed *rss.Feed, newchannels []*rss.Channel) {
fmt.Printf("%d new channel(s) in %s\n", len(newchannels), feed.Url)
}

func itemHandler(feed *rss.Feed, ch *rss.Channel, newItems []*rss.Item) {
fmt.Printf("%d new item(s) in %s\n", len(newItems), feed.Url)
}

func PostTweet(tweet string) {
anaconda.SetConsumerKey("9AuRCuPxHAuvPdLIt9Sg")
anaconda.SetConsumerSecret("14pYoR2B3IAeRsQiOZrSrjweseNj8YW97XbHjwkp4")
api := anaconda.NewTwitterApi("404687248-c3I6DzhE3KpZvX7lX1J3DFw1AFrtzj8xiwldvBJG", "P7pFC7ZEpKp5WvqtK6xnY0GPyH8Fqt9eOjDrjqi0jlIbO")

v := url.Values{}
api.PostTweet(tweet, v)
}
39 changes: 39 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
)

type settings struct {
ConsumerKey string
ConsumerSecret string
AccessToken string
AccessTokenSecret string
}

func ReadConsumerKey() string {
return readSettings().ConsumerKey
}

func ReadConsumerSecret() string {
return readSettings().ConsumerSecret
}

func ReadAccessToken() string {
return readSettings().AccessToken
}

func readSettings() settings {
file, err := ioutil.ReadFile("./settings.json")
if err != nil {
fmt.Errorf("File error: %v\n", err)
}
var s settings
err = json.Unmarshal(file, &s)
if err != nil {
fmt.Errorf("File failed to decode: %v\n", err)
}
return s
}
6 changes: 6 additions & 0 deletions settings.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ConsumerKey": "your-consumer-key",
"ConsumerSecret": "your-consumer-secret",
"AccessToken": "your-access-token",
"AccessTokenSecret": "your-access-token-secret"
}

0 comments on commit ed61be3

Please sign in to comment.