Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Author: Beta Folf
- # Project: Scripts/RedditYiffGrabber
- # File: index.py
- #
- # Imports
- import urllib.request
- import praw
- import pandas as pd
- import datetime as dt
- import os
- from bs4 import BeautifulSoup
- # Globals
- REDDIT_ID = "Create a reddit developer app"
- REDDIT_SECRET = "Create a reddit developer app"
- # Run
- reddit = praw.Reddit(client_id=REDDIT_ID,
- client_secret=REDDIT_SECRET,
- user_agent='RedditYiffGrabber',
- username='Your reddit name',
- password='Your reddit password')
- TOTAL_IMAGE_COUNT = 0
- # r/yiff
- try:
- yiffSubreddit = reddit.subreddit("yiff")
- yiffTopPosts = yiffSubreddit.top(limit=100)
- straightURL = []
- gayURL = []
- soloFemaleURL = []
- print("Getting posts from r/yiff...")
- posts = []
- postsTitle = []
- for post in yiffTopPosts:
- title = list(post.title)
- for t in title:
- try:
- if "[" in title and "]" in title:
- openBracket = title.index("[")
- closeBracket = title.index("]")
- postsTitle = [(title[openBracket+1:closeBracket])]
- else:
- postsTitle = title
- except Exception as e:
- print("Could not get posts! " + e)
- for postT in postsTitle:
- if len(postT) == 1:
- if postT[0].upper() == "M":
- gayURL.append(post.url)
- elif postT[0].upper() == "F":
- straightURL.append(post.url)
- else:
- break
- else:
- if "M" in postT and "F" in postT or "F" in postT and "T" in postT or "F" in postT and "M" not in postT:
- straightURL.append(post.url)
- else:
- gayURL.append(post.url)
- # r/yiffgif
- yiffGifSubreddit = reddit.subreddit("yiffgif")
- yiffGifTopPosts = yiffGifSubreddit.top(limit=100)
- posts = []
- postsTitle = []
- print("Getting posts from r/yiffgif...")
- for post in yiffGifTopPosts:
- title = list(post.title)
- for t in title:
- try:
- if "[" in title and "]" in title:
- openBracket = title.index("[")
- closeBracket = title.index("]")
- postsTitle = [(title[openBracket+1:closeBracket])]
- else:
- postsTitle = title
- except Exception as e:
- print("Could not get posts! " + e)
- for postT in postsTitle:
- if len(postT) == 1:
- if postT[0].upper() == "M":
- gayURL.append(post.url)
- elif postT[0].upper() == "F":
- straightURL.append(post.url)
- else:
- break
- else:
- if "M" in postT and "F" in postT or "F" in postT and "T" in postT or "F" in postT and "M" not in postT:
- straightURL.append(post.url)
- else:
- gayURL.append(post.url)
- print("Getting straight image sizes...")
- for image in straightURL:
- print("Trying information from " + image + " ...")
- try:
- with urllib.request.urlopen(image) as url:
- size = url.info()["Content-Length"]
- if int(size) >= 8e6:
- straightURL.remove(image)
- except Exception as e:
- print("Could not get straight image size!")
- print("Getting gay image sizes...")
- for image in gayURL:
- print("Trying information from " + image + " ...")
- try:
- with urllib.request.urlopen(image) as url:
- size = url.info()["Content-Length"]
- if int(size) >= 8e6:
- gayURL.remove(image)
- except Exception as e:
- print("Could not get gay image size!")
- count = 0
- print("Downloading straight images...")
- for image in straightURL:
- print("Trying download for " + image + " ...")
- count = count + 1
- t = image.split(".")
- if "https://gfycat" in t and t[-1] != "gif" and t[-1] != "gifv":
- page = urllib.request.urlopen(image).read()
- e6Link = ""
- soup = BeautifulSoup(page).findAll(
- "a", {"class": "value"}, href=True)
- for item in soup:
- if item.text:
- e6Link = item["href"]
- try:
- urllib.request.urlretrieve(
- str(e6Link), "./straight/gifs/" + str(count) + ".gif")
- TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
- except Exception as e:
- print("Could not get image!" + e)
- elif "https://gfycat" in t and t[-1] != "gif" and t[-1] != "gifv" or t[-1] == "gif" or t[-1] == "gifv":
- if not os.path.exists("./straight/gifs"):
- os.makedirs("./straight/gifs")
- try:
- urllib.request.urlretrieve(
- str(image), "./straight/gifs/" + str(count) + ".gif")
- TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
- except Exception as e:
- print("Could not get image!" + e)
- elif t[-1] == "png" or t[-1] == "jpg" or t[-1] == "jpeg":
- if not os.path.exists("./straight/images"):
- os.makedirs("./straight/images")
- try:
- urllib.request.urlretrieve(
- str(image), "./straight/images/" + str(count) + "." + t[-1])
- TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
- except:
- print("Could not get image!")
- count = 0
- print("Downloading gay images...")
- for image in gayURL:
- print("Trying download for " + image + " ...")
- count = count + 1
- t = image.split(".")
- if t[-1] == "png" or t[-1] == "jpg" or t[-1] == "jpeg":
- if not os.path.exists("./gay/images"):
- os.makedirs("./gay/images")
- try:
- urllib.request.urlretrieve(
- str(image), "./gay/images/" + str(count) + "." + t[-1])
- TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
- except:
- print("Could not get image!")
- print("Got " + str(TOTAL_IMAGE_COUNT) + " images! Have fun!")
- except Exception as e:
- print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement