-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ed61be3
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
settings.json |
Empty file.
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
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) | ||
} |
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
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 | ||
} |
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
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" | ||
} |