Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. #
  2. # Author: Beta Folf
  3. # Project: Scripts/RedditYiffGrabber
  4. # File: index.py
  5. #
  6.  
  7. # Imports
  8. import urllib.request
  9. import praw
  10. import pandas as pd
  11. import datetime as dt
  12. import os
  13. from bs4 import BeautifulSoup
  14.  
  15. # Globals
  16. REDDIT_ID = "Create a reddit developer app"
  17. REDDIT_SECRET = "Create a reddit developer app"
  18.  
  19. # Run
  20. reddit = praw.Reddit(client_id=REDDIT_ID,
  21. client_secret=REDDIT_SECRET,
  22. user_agent='RedditYiffGrabber',
  23. username='Your reddit name',
  24. password='Your reddit password')
  25.  
  26. TOTAL_IMAGE_COUNT = 0
  27.  
  28. # r/yiff
  29. try:
  30. yiffSubreddit = reddit.subreddit("yiff")
  31.  
  32. yiffTopPosts = yiffSubreddit.top(limit=100)
  33.  
  34. straightURL = []
  35. gayURL = []
  36. soloFemaleURL = []
  37.  
  38. print("Getting posts from r/yiff...")
  39.  
  40. posts = []
  41. postsTitle = []
  42.  
  43. for post in yiffTopPosts:
  44. title = list(post.title)
  45. for t in title:
  46. try:
  47. if "[" in title and "]" in title:
  48. openBracket = title.index("[")
  49. closeBracket = title.index("]")
  50. postsTitle = [(title[openBracket+1:closeBracket])]
  51. else:
  52. postsTitle = title
  53. except Exception as e:
  54. print("Could not get posts! " + e)
  55. for postT in postsTitle:
  56. if len(postT) == 1:
  57. if postT[0].upper() == "M":
  58. gayURL.append(post.url)
  59. elif postT[0].upper() == "F":
  60. straightURL.append(post.url)
  61. else:
  62. break
  63. else:
  64. 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:
  65. straightURL.append(post.url)
  66. else:
  67. gayURL.append(post.url)
  68.  
  69. # r/yiffgif
  70. yiffGifSubreddit = reddit.subreddit("yiffgif")
  71.  
  72. yiffGifTopPosts = yiffGifSubreddit.top(limit=100)
  73.  
  74. posts = []
  75. postsTitle = []
  76.  
  77. print("Getting posts from r/yiffgif...")
  78.  
  79. for post in yiffGifTopPosts:
  80. title = list(post.title)
  81. for t in title:
  82. try:
  83. if "[" in title and "]" in title:
  84. openBracket = title.index("[")
  85. closeBracket = title.index("]")
  86. postsTitle = [(title[openBracket+1:closeBracket])]
  87. else:
  88. postsTitle = title
  89. except Exception as e:
  90. print("Could not get posts! " + e)
  91. for postT in postsTitle:
  92. if len(postT) == 1:
  93. if postT[0].upper() == "M":
  94. gayURL.append(post.url)
  95. elif postT[0].upper() == "F":
  96. straightURL.append(post.url)
  97. else:
  98. break
  99. else:
  100. 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:
  101. straightURL.append(post.url)
  102. else:
  103. gayURL.append(post.url)
  104.  
  105. print("Getting straight image sizes...")
  106.  
  107. for image in straightURL:
  108. print("Trying information from " + image + " ...")
  109. try:
  110. with urllib.request.urlopen(image) as url:
  111. size = url.info()["Content-Length"]
  112. if int(size) >= 8e6:
  113. straightURL.remove(image)
  114. except Exception as e:
  115. print("Could not get straight image size!")
  116.  
  117. print("Getting gay image sizes...")
  118.  
  119. for image in gayURL:
  120. print("Trying information from " + image + " ...")
  121. try:
  122. with urllib.request.urlopen(image) as url:
  123. size = url.info()["Content-Length"]
  124. if int(size) >= 8e6:
  125. gayURL.remove(image)
  126. except Exception as e:
  127. print("Could not get gay image size!")
  128.  
  129. count = 0
  130.  
  131. print("Downloading straight images...")
  132.  
  133. for image in straightURL:
  134. print("Trying download for " + image + " ...")
  135. count = count + 1
  136. t = image.split(".")
  137. if "https://gfycat" in t and t[-1] != "gif" and t[-1] != "gifv":
  138. page = urllib.request.urlopen(image).read()
  139. e6Link = ""
  140. soup = BeautifulSoup(page).findAll(
  141. "a", {"class": "value"}, href=True)
  142. for item in soup:
  143. if item.text:
  144. e6Link = item["href"]
  145. try:
  146. urllib.request.urlretrieve(
  147. str(e6Link), "./straight/gifs/" + str(count) + ".gif")
  148. TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
  149. except Exception as e:
  150. print("Could not get image!" + e)
  151. elif "https://gfycat" in t and t[-1] != "gif" and t[-1] != "gifv" or t[-1] == "gif" or t[-1] == "gifv":
  152. if not os.path.exists("./straight/gifs"):
  153. os.makedirs("./straight/gifs")
  154. try:
  155. urllib.request.urlretrieve(
  156. str(image), "./straight/gifs/" + str(count) + ".gif")
  157. TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
  158. except Exception as e:
  159. print("Could not get image!" + e)
  160. elif t[-1] == "png" or t[-1] == "jpg" or t[-1] == "jpeg":
  161. if not os.path.exists("./straight/images"):
  162. os.makedirs("./straight/images")
  163. try:
  164. urllib.request.urlretrieve(
  165. str(image), "./straight/images/" + str(count) + "." + t[-1])
  166. TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
  167. except:
  168. print("Could not get image!")
  169.  
  170. count = 0
  171.  
  172. print("Downloading gay images...")
  173.  
  174. for image in gayURL:
  175. print("Trying download for " + image + " ...")
  176. count = count + 1
  177. t = image.split(".")
  178. if t[-1] == "png" or t[-1] == "jpg" or t[-1] == "jpeg":
  179. if not os.path.exists("./gay/images"):
  180. os.makedirs("./gay/images")
  181. try:
  182. urllib.request.urlretrieve(
  183. str(image), "./gay/images/" + str(count) + "." + t[-1])
  184. TOTAL_IMAGE_COUNT = TOTAL_IMAGE_COUNT + 1
  185. except:
  186. print("Could not get image!")
  187.  
  188. print("Got " + str(TOTAL_IMAGE_COUNT) + " images! Have fun!")
  189. except Exception as e:
  190. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement