Exemplo n.º 1
0
func main() {
	r, err := geddit.NewLoginSession("", "", "FuckTheCowboysBot/v0.2 /u/bananaboydean /u/harkins")
	if err != nil {
		fmt.Println(err)
	}
	_, err = r.AboutSubreddit("tossboxtest")
	if err != nil {
		fmt.Println(err)
	}
	cpt, err := r.NewCaptchaIden()
	if err != nil {
		fmt.Println(err)
	}
	capt := &geddit.Captcha{cpt, cpt}
	file, err := os.Open("test.png")
	if err != nil {
		fmt.Println(err)
	}
	defer file.Close()
	fInfo, _ := file.Stat()
	var size int64 = fInfo.Size()
	buf := make([]byte, size)
	fReader := bufio.NewReader(file)
	fReader.Read(buf)
	fileBase64Str := base64.StdEncoding.EncodeToString(buf)
	fmt.Println(fInfo.Name())
	fmt.Println(len(fileBase64Str))
	r.Submit(geddit.NewTextSubmission("tossboxtest", fInfo.Name(), fileBase64Str[0:35000], false, capt))
}
Exemplo n.º 2
0
// Please don't handle errors this way.
func main() {
	// Login to reddit
	session, _ := geddit.NewLoginSession(
		"novelty_account",
		"password",
		"gedditAgent v1",
	)

	// Set listing options
	subOpts := geddit.ListingOptions{
		Limit: 10,
	}

	// Get reddit's default frontpage
	submissions, _ := session.DefaultFrontpage(geddit.DefaultPopularity, subOpts)

	// Get our own personal frontpage
	submissions, _ = session.Frontpage(geddit.DefaultPopularity, subOpts)

	// Get specific subreddit submissions, sorted by new
	submissions, _ = session.SubredditSubmissions("hockey", geddit.NewSubmissions, subOpts)

	// Print title and author of each submission
	for _, s := range submissions {
		fmt.Printf("Title: %s\nAuthor: %s\n\n", s.Title, s.Author)
	}

	// Upvote the first post
	session.Vote(submissions[0], geddit.UpVote)
}
Exemplo n.º 3
0
func (s *Session) Login() {
	username := ui.GetString("username: "******"password: "******"login"
	s.LoginSession = sesh
	s.Last = ""
	s.Session = nil
	s.Frontpage(s.Limit, "")
}
Exemplo n.º 4
0
func main() {
	checked = make(map[string]struct{})
	var subreddits = [...]string{"askreddit", "4chan"} // subreddits to check

	// login to reddit
	r, err := geddit.NewLoginSession(USERNAME, PASSWORD, "CarelessBot v1")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to log in\n")
		return
	}

	// set listing options
	subOpts := geddit.ListingOptions{
		Limit: 100,
	}

	for {
		for _, sub := range subreddits {
			submissions, err := r.SubredditSubmissions(sub, geddit.NewSubmissions, subOpts)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to get new submissions for %s\n", sub)
			} else {
				for _, s := range submissions {
					fmt.Println("Checking comments in ", s.Permalink)
					// get submission comments
					comments, err := r.Comments(s)
					if err != nil {
						fmt.Fprintf(os.Stderr, "Failed to get submission comments: %s\n", err.Error())
					} else {
						go checkComments(comments)
					}
				}
			}
		}
		// sleep for a while
		fmt.Println("Sleeping for", SLEEP_TIME)
		time.Sleep(SLEEP_TIME)
	}
}
Exemplo n.º 5
0
func pullFromReddit(ses *discordgo.Session) bool {
	pgDb := dbConn()

	defer func() bool {
		if err := recover(); err != nil {
			//			fmt.Println("recovered from wrong pull")
			pgDb.Close()
			return false
		}
		return true
	}()

	session, _ := geddit.NewLoginSession(
		"",
		"",
		"gedditAgent v1",
	)

	rows, err := pgDb.Query(
		`SELECT last_url FROM reddit 
        ORDER BY time_stamp DESC LIMIT 100`)
	checkErr(err)

	var url string
	urlArr := make(map[string]int)
	for rows.Next() {
		rows.Scan(&url)
		urlArr[url] = 1
	}
	rows.Close()

	subOpts := geddit.ListingOptions{
		Limit: 100,
	}

	submissions, _ := session.Frontpage(geddit.HotSubmissions, subOpts)

	for _, s := range submissions {
		_, ok := urlArr[s.URL]
		if ok {
			break
		}
		tx, err := pgDb.Begin()
		checkErr(err)

		_, err = tx.Exec("INSERT INTO reddit (last_url) VALUES ($1)", s.URL)
		checkErr(err)

		tx.Commit()

		if strings.Contains(s.URL, "imgur") &&
			!strings.Contains(s.URL, "/a/") &&
			!strings.Contains(s.URL, "/gallery/") {
			//			fmt.Println(s.URL)
			rx := regexp.MustCompile(`^(https?://.*?)/(.*?)(\..*)?$`)
			m := rx.FindStringSubmatch(s.URL)
			//			fmt.Println(m)

			base := m[1]
			pref := m[2]
			ext := m[3]
			//			fmt.Println("after m split")
			if len(ext) == 0 {
				ext = ".jpg"
			}
			animated := imgurFilext(pref)

			url := base + "/" + pref + ext
			if animated {
				url = base + "/" + pref + ".gif"
			}

			response, err := http.Get(url)
			checkErr(err)

			//			fmt.Println(response.ContentLength)

			if response.ContentLength <= 8388608 {
				ses.ChannelMessageSend(CHANID,
					fmt.Sprintf("\n```%s```\n%s\n", s.Title, url))
			} else {
				ses.ChannelMessageSend(CHANID,
					fmt.Sprintf(
						"\n```**CANNOT EMBED FILE IS TOO LARGE**\n%s```\n%s",
						s.Title, s.URL))
			}

		} else {
			ses.ChannelMessageSend(CHANID,
				fmt.Sprintf("\n```%s```\n%s\n", s.Title, s.URL))
		}
		time.Sleep(time.Second * 2)
	}
	pgDb.Close()
	return true
}
Exemplo n.º 6
0
func main() {
	//Read reddit username and password
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Enter Username: "******"Enter Password: "******"gedditAgent v1",
	)

	// Set listing options
	subOpts := geddit.ListingOptions{
		Limit: 50,
	}

	// Get specific subreddit submissions, sorted by new
	submissions, _ := session.SubredditSubmissions("Dota2", geddit.TopSubmissions, subOpts)
	fmt.Printf("Len: %d\n\n", len(submissions))
	subOpts = geddit.ListingOptions{
		Limit: 35,
	}
	submissionshot, _ := session.SubredditSubmissions("Dota2", geddit.HotSubmissions, subOpts)
	submissions = append(submissions, submissionshot...)

	fmt.Printf("Len: %d Len: %d\n\n", len(submissionshot), len(submissions))
	var comments = make(chan *geddit.Comment, 1000)
	var wg sync.WaitGroup
	for _, s := range submissions {
		wg.Add(1)
		comment, err := session.Comments(s)
		if err != nil {
			continue
		}
		go func() {
			// fmt.Printf("CommentDetect. Title: %s\n\n", s.Title)
			// fmt.Printf("CommentDetected. ID: %d\n\n", wg)
			CommentDetect("Dota", comment, comments, wg)
			defer wg.Done()
		}()
	}
	wg.Wait()
	close(comments)
	fmt.Printf("Len commets: %d\n\n", len(comments))
	// fmt.Print("Enter Meme: ")
	// urlquery, _ := reader.ReadString('\n')
	// urlquery = url.QueryEscape(strings.TrimSpace(urlquery))
	// fmt.Printf("5/7 %s\n\n",urlquery)

	// knowyourmemes, _ := getMemes(urlquery)
	// for _, s := range knowyourmemes {
	//     fmt.Printf("Meme: %d %s\n\n", len(knowyourmemes), s.Body)
	// }
	//http://rkgk.api.searchify.com/v1/indexes/kym_production/instantlinks?query=jotain&fetch=*

	// Print title and author of each submission
	for elem := range comments {
		wg.Add(1)
		go func() {
			MemeCheck(elem, wg)
		}()
	}
	wg.Wait()
	// for _, s := range submissions {
	// 	fmt.Printf("Title: %s\nAuthor: %s Comments: %s\n\n", s.Title, s.Author,comments)
	// }

	// Upvote the first post
	//session.Vote(submissions[0], geddit.UpVote)
}
Exemplo n.º 7
0
func main() {
	// Load the config
	configFile := path.Join(os.Getenv("HOME"), ".config", "redditDownloader.conf")
	if _, err := os.Stat(configFile); os.IsNotExist(err) {
		fmt.Println("Create a config file at ~/.config/redditDownloader.conf. A json message with user and password strings as well as a an entry count of reddit to search and the minimum duration of videos to download.")
		os.Exit(1)
	}
	file, err := os.Open(configFile)
	if err != nil {
		fmt.Println("Unable to open the config file")
		os.Exit(1)
	}
	decoder := json.NewDecoder(file)
	config := Configuration{}
	err = decoder.Decode(&config)
	if err != nil {
		fmt.Println("Unable to read config file:", err)
		os.Exit(1)
	}

	// Connect to reddit
	session, err := geddit.NewLoginSession(
		config.User,
		config.Password,
		"gedditAgent v1",
	)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Set listing options
	subOpts := geddit.ListingOptions{
		Limit: config.Entries,
	}

	// Get reddit's default frontpage
	// submissions, _ := session.DefaultFrontpage(geddit.DefaultPopularity, subOpts)

	// Get our own personal frontpage
	// submissions, _ = session.Frontpage(geddit.DefaultPopularity, subOpts)

	// Get specific subreddit submissions, sorted by new
	submissions, err := session.SubredditSubmissions("rugbyunion", geddit.NewSubmissions, subOpts)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	var wg sync.WaitGroup
	for _, s := range submissions {
		// fmt.Printf("Title: %s\nAuthor: %s\nUrl: %s\n", s.Title, s.Author, s.URL)
		fmt.Println(s.Title)
		if strings.Contains(s.URL, "youtube") {
			wg.Add(1)
			download(s.URL, wg, config.MinDuration)
		}
		// Check the comments as well
		comments, err := session.Comments(s)
		if err != nil {
			fmt.Println(err)
		}
		for _, c := range comments {
			urls := xurls.Strict.FindAllString(c.Body, -1)
			for _, u := range urls {
				if strings.Contains(u, "youtube") {
					wg.Add(1)
					download(u, wg, config.MinDuration)
				}
			}
		}
	}
}