Python 3.x 检查Reddit帖子是否为视频
我正在制作一个机器人,从我选择的subreddit下载帖子,但我只想下载照片。我的代码已经确保帖子不是文本,但我无法检查视频是否是文本。如果帖子是视频,程序应该跳过它 以下是我目前的代码:Python 3.x 检查Reddit帖子是否为视频,python-3.x,reddit,praw,Python 3.x,Reddit,Praw,我正在制作一个机器人,从我选择的subreddit下载帖子,但我只想下载照片。我的代码已经确保帖子不是文本,但我无法检查视频是否是文本。如果帖子是视频,程序应该跳过它 以下是我目前的代码: from InstagramAPI import InstagramAPI import praw import requests import urllib.request import time import keyboard from PIL import Image import math #mak
from InstagramAPI import InstagramAPI
import praw
import requests
import urllib.request
import time
import keyboard
from PIL import Image
import math
#make a reddit acount and look up how to find this stuff. its called PRAW
reddit = praw.Reddit(client_id='***',
client_secret='***',
username='',
password='',
user_agent='chrome')
def DLimage(url, filePath, fileName):
fullPath = filePath + fileName + '.jpg'
urllib.request.urlretrieve(url, fullPath)
#folder path to store downloaded images
filePath = "/Users/***/AppBot/WTF/"
subreddit = reddit.subreddit('videos') #subreddit to take images from
waitTime = 2 #to prevent reddit badgateway error. DONt change
numRounds = 100 #how many posts
postFrequency = 600 # how often to post in seconds.
numPics = 100 #how many pics per post
for x in range(numRounds):
new_memes = subreddit.top('all') #.hot/.rising/.new reddit sorting algorithm
authors = []
photoAlbum = []
print("Round/post number:", x)
for subbmission in new_memes:
if subbmission.preview == True: #checking if post is only text.
#print("Post was text, skipping to next post.")
pass
else:
continue
url = subbmission.url
time.sleep(waitTime)
fileName = str(subbmission)
fullPath = filePath + fileName + '.jpg'
#print(fullPath)
time.sleep(waitTime)
#print(url)
try:
DLimage(url, filePath, fileName)
except:
print("scratch that, next post.")
continue
time.sleep(waitTime)
img = Image.open(fullPath)
width, height = img.size
#img = img.resize((1000, 1020), Image.NEAREST) #image resize. width/height
img = img.convert("RGB")
img.save(fullPath)
time.sleep(postFrequency)
可能有助于确定任何给定提交链接指向的媒体类型。可能有助于确定任何给定提交链接指向的媒体类型。