Skip to content
Permalink
Browse files

save post sent

  • Loading branch information
Mte90 committed Jan 7, 2020
1 parent 220f5cb commit a01bd1071e3f002881b85d4c750acb4b495894c0
Showing with 10 additions and 8 deletions.
  1. +10 −8 bot.py
18 bot.py
@@ -10,6 +10,11 @@
if os.path.exists('./praw.ini'):
praw_config = configparser.RawConfigParser()
praw_config.read_file(open('./praw.ini'))

def save_tweets(posts):
with open('posts.json', 'w') as outfile:
print("\nPost saved")
json.dump(posts, outfile, indent=4)

reddit = praw.Reddit(str(praw_config.get('user', 'nickname')))

@@ -37,14 +42,14 @@
print("File posts found")
with open('./posts.json') as json_file:
posts = json.load(json_file)
print("Posts item: " + str(len(posts)))

excludes = str(praw_config.get('user', 'exclude'))
excludes = excludes.split(',')

for post in user.upvoted(limit=100):
if post.id not in posts:
tweet_it = True
posts[post.id] = {'title': post.title, 'subreddit': str(post.subreddit).lower(), 'permalink': post.permalink}
print("Missing " + post.id + " post")

for exclude in excludes:
@@ -53,13 +58,10 @@
break

if tweet_it:
# Wait 10 minutes before tweet it
time.sleep(600)
posts[post.id] = {'title': post.title, 'subreddit': str(post.subreddit).lower(), 'permalink': post.permalink}
# Create a tweet
print('Posting new tweet')
save_tweets(posts)
api.update_status(post.title + ' via /r/' + str(post.subreddit) + "\nhttps://www.reddit.com" + post.permalink)

print()
with open('posts.json', 'w') as outfile:
print("Posts saved")
json.dump(posts, outfile, indent=4)
# Wait 10 minutes before tweet it
time.sleep(600)

0 comments on commit a01bd10

Please sign in to comment.
You can’t perform that action at this time.