Ejemplo n.º 1
0
// Renders feed in Atom format
func (c *Context) Atom(feed *feeds.Feed) *Result {
	atom, err := feed.ToAtom()
	if err != nil {
		return c.Error(err)
	}
	return c.Result(http.StatusOK, []byte(atom), "application/atom+xml", nil)
}
Ejemplo n.º 2
0
func getRss() string {
	twitterConfig := oauth1.NewConfig(conf.ConsumerKey, conf.ConsumerSecret)
	token := oauth1.NewToken(conf.AccessToken, conf.AccessSecret)
	// OAuth1 http.Client will automatically authorize Requests
	httpClient := twitterConfig.Client(oauth1.NoContext, token)

	// Twitter Client
	client := twitter.NewClient(httpClient)

	// debugging & testing
	/*if conf.Debug {
		var tweetId int64 = 7654321
		tweet, _, err := client.Statuses.Show(tweetId, &twitter.StatusShowParams{})
		if err != nil {
			processAPIError("Couldn't load client.Statuses.Show: ", err)
			return ""
		}
		fmt.Println(parser.GetTweetUrl(*tweet))
		spew.Dump(tweet)
		fmt.Println(parser.ParseTweetText(*tweet))
		return ""
	}*/

	// Get timeline
	homeTimelineParams := &twitter.HomeTimelineParams{Count: conf.MaxTweets}
	tweets, _, err := client.Timelines.HomeTimeline(homeTimelineParams)
	if err != nil {
		processAPIError("Couldn't load HomeTimeline: ", err)
		return ""
	}

	// get either single tweets or combine multiple tweets of the same author together
	var rssFeed *feeds.Feed
	if conf.CombinedFeed == false {
		rssFeed = feed.CreateIndividualFeed(conf, tweets)
	} else {
		rssFeed = feed.CreateCombinedUserFeed(conf, tweets)
	}

	// Create feed
	atom, err := rssFeed.ToAtom()
	if err != nil {
		log.Fatal(err)
	}

	return atom
}
Ejemplo n.º 3
0
func main() {
	pflag.Parse()

	now := time.Now()
	feed := feeds.Feed{
		Title: *feedTitle,
		Link: &feeds.Link{
			Href: *feedPublishUrl,
		},
		Description: *feedDescription,
		Author: &feeds.Author{
			*feedAuthorName, *feedAuthorEmail,
		},
		Created: now,
	}

	filepath.Walk(*inputDir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if info.IsDir() {
			return nil
		}

		relPath, err := filepath.Rel(*inputDir, path)
		if err != nil {
			return err
		}

		feed.Items = append(feed.Items, &feeds.Item{
			Id:    "file:" + url.QueryEscape(path),
			Title: info.Name(),
			Link: &feeds.Link{
				Href: *feedFilesBaseUrl + relPath,
			},
			Description: path,
			Author:      &feeds.Author{*feedAuthorName, *feedAuthorEmail},
			Created:     info.ModTime(),
		})

		return nil
	})

	var content string
	var err error
	switch *outputFormat {
	case "rss":
		content, err = feed.ToRss()
	case "atom":
		content, err = feed.ToAtom()
	default:
		log.Fatalf("Unknown format: %s", *outputFormat)
	}

	if err != nil {
		log.Fatalf("Failed to generate feed: %#v", err)
	}

	err = ioutil.WriteFile(*outputFile, []byte(content), 0777)
	if err != nil {
		log.Fatalf("Failed to store feed: %#v", err)
	}
}