0
截至目前,我已經完成了大部分代碼,用於瀏覽subreddit,並在請求時下載頂部圖像。我能夠使用PRAW和urllib在獲取鏈接後下載圖像。我堅持的最後一部分是將圖像文件放在一個數組中,並將它們設置爲我的背景。這是我有什麼用下載的圖像改變windows背景的Reddit bot
import praw
import time
import os
import urllib as ul
import os
def backGroundChanger(sub):
USER_AGENT='wall paper changer for linux/windows by /u/**********' #specifies what my bot does and by who
REDDIT_ID= #reddit id
REDDIT_PASS= #reddit password
reddit=praw.Reddit(USER_AGENT) #creates bot
reddit.login(REDDIT_ID,REDDIT_PASS) #logsin
print reddit.is_logged_in()
images=reddit.get_subreddit(sub)
while True:
count=0
for sub in images.get_hot(limit=10):
imageLink=sub.url
print imageLink
n=str(count)
ul.urlretrieve(imageLink, "i" + n)
count+=1
file=[]
dir=os.getcwd()
for files in os.listdir("."):
if(files.endswith(".jpg|| .png"): # not sure if this will work
file.append(files)
changeBackGround(file,dir)
def changeBackGround(file, dir):
#Do back ground changing stuff here
def main():
subreddit=input("What subreddit would you like me to pull images from? ")
print "You chose " + subreddit
backGroundChanger(subreddit)
main()
謝謝,當我可以找到一些空閒時間,我會測試這一點,讓你知道。謝謝您的幫助! – user1943221