Ejemplo n.º 1
0
func InitSession() (s *Session) {
	s = &Session{
		Type:    "std",
		Last:    "",
		Limit:   16,
		Session: geddit.NewSession(USER_AGENT),
	}
	return
}
Ejemplo n.º 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, "")
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: 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
}
Ejemplo n.º 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)
}