示例#1
0
func InitSession() (s *Session) {
	s = &Session{
		Type:    "std",
		Last:    "",
		Limit:   16,
		Session: geddit.NewSession(USER_AGENT),
	}
	return
}
示例#2
0
func (s *Session) Logout() {
	s.Type = "std"
	if s.LoginSession != nil {
		s.LoginSession.Clear()
		s.LoginSession = nil
	}
	s.Session = geddit.NewSession(USER_AGENT)
	s.Frontpage(s.Limit, "")
}
示例#3
0
文件: main.go 项目: bnadland/r
func showSubreddit(subredditName string) error {
	r := geddit.NewSession("r by /u/bnadland")

	submissions, err := r.SubredditSubmissions(subredditName, geddit.HotSubmissions, geddit.ListingOptions{})
	if err != nil {
		return err
	}

	isActive := true

	cursor := 3
	for isActive {

		entries := []string{}
		for i, submission := range submissions {
			entries = append(entries, fmt.Sprintf("%s %s", isActiveCursor(cursor, i), submission.Title))
		}

		ls := termui.NewList()
		ls.Items = entries
		ls.ItemFgColor = termui.ColorDefault
		ls.Border.Label = fmt.Sprintf("Subreddit: %s", subredditName)
		ls.Height = termui.TermHeight()
		ls.Width = termui.TermWidth()
		ls.Y = 0
		termui.Render(ls)
		event := <-termui.EventCh()
		if event.Type == termui.EventKey {
			switch event.Key {
			case termui.KeyArrowLeft:
				isActive = false
			case termui.KeyArrowDown:
				cursor = cursor + 1
				if cursor > len(submissions) {
					cursor = len(submissions)
				}
			case termui.KeyArrowUp:
				cursor = cursor - 1
				if cursor < 0 {
					cursor = 0
				}
			}
		}
	}
	return nil
}
示例#4
0
	"net/url"
	"os"
	"path/filepath"
	"regexp"
	"sync"
	"time"

	"github.com/ChimeraCoder/anaconda"
	"github.com/garyburd/redigo/redis"
	"github.com/jzelinskie/geddit"
)

const ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36"

var (
	session = geddit.NewSession(ua)
	pool    = newPool("/tmp/monks.sock")
)

func init() {
	ck := os.Getenv("CONSUMERKEY")
	cs := os.Getenv("CONSUMERSECRET")

	if ck == "" || cs == "" {
		panic("Cannot have empty API key/secret/token")
	}

	anaconda.SetConsumerKey(ck)
	anaconda.SetConsumerSecret(cs)
}