0

サブ reddit の新しい投稿を通知するスクリプトを作成しようとしています。コードのコアは次のとおりです。

sub = r.get_subreddit('indianwriters',fetch=True)
time.sleep(5)
posts = sub.get_new()                
while True:
        try:
            time.sleep(2.5)                
            post = next(posts)
            print post.id,post.title

ただし、これには最初の投稿がありません。しかし、次のように1行ずつ入力すると、次のようになります。

sub = r.get_subreddit('indianwriters',fetch=True)
time.sleep(5)
posts = sub.get_new()
post = next(posts)
print post.id,post.title

これは正しく動作します。では、なぜスクリプトで機能しないのでしょうか。

4

1 に答える 1