gpt4 book ai didi

python - 使用下载的图像更改 Windows 背景的 Reddit 机器人

转载 作者:太空宇宙 更新时间:2023-11-04 09:44:25 25 4
gpt4 key购买 nike

截至目前,我已经完成了大部分用于浏览 subreddit 和在请求时下载热门图片的代码。一旦获得链接,我就能够使用 PRAW 和 urllib 下载图像。我坚持的最后一部分是将图像文件放在一个数组中,并将它们实际设置为我的背景。这是我拥有的

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()

最佳答案

这可能有效,也可能无效;它未经测试。

阅读 os.system function 是一种使用系统程序设置背景的方法,如 linux 中的 xsetbg。看这里设置windows背景(它只涉及破解注册表)。

import os
import glob
import random
import sys
import time
import urllib

import praw

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)
urllib.urlretrieve(imageLink, "i" + n )

count += 1

files = glob.glob("*.jpg") + glob.glob("*.png")

changeBackGround(files)


def changeBackGround(ifiles):
#Do back ground changing stuff here
the_file = ifiles[random.randint(0, len(ifiles) - 1)]
if(sys.platform.startswith("win")): # Windows
# Do this yourself
pass
elif(sys.platform.startswith("linux")): # Linux
os.system("xsetbg -center %s" % the_file)

def main():
subreddit = input("What subreddit would you like me to pull images from? ")
print "You chose " + subreddit
backGroundChanger(subreddit)

main()

关于python - 使用下载的图像更改 Windows 背景的 Reddit 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17976419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com