使用Reddit和Tumblr API接收Reddit网址并将其发布为tumblr图像时出错

时间:2018-11-01 15:30:23

标签: python tumblr reddit praw pytumblr

我正在编写一个脚本,该脚本从指定的subreddit获取一些帖子,然后使用该URL在api和python站点的tumblr上创建图像帖子。我的问题是,当我尝试从reddit检索URL并将其发布到tumblr时,我的程序改为打印随机subreddit的URL(始终为URL https://www.reddit.com/r/accidentallyliberian/),我想知道代码中的错误是什么,为什么出错了正在打印该网址,而不是我在if语句中指定的有关该网址中包含'.img'或'.png'的字符串的网址。

import praw
import json
import pytumblr

reddit = praw.Reddit(client_id='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                     client_secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                     password='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                     user_agent='url grabber by /u/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                     username='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

oauth_token = 'http://www.tumblr.com/oauth/request_token'
AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize'
ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token'
consumer_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

client = pytumblr.TumblrRestClient(
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)

#print(reddit.user.me())
def get_post_url(subreddit, amount):
    for submission in reddit.subreddit(subreddit).hot(limit = amount):
        if '.img' or '.png' in submission.url:
            client.create_photo('username', state="published", tags=["testing", "ok"],
                                source = submission.url)
            #urllib.request.urlretrieve(submission.url, filename)

            print(submission.url)
        else:
            print('')


if __name__ == '__main__':
    get_post_url('funny', 1)

0 个答案:

没有答案