Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import praw
- reddit = praw.Reddit(
- client_id='client_id',
- client_secret='client_secret',
- password='password',
- user_agent='user_agent',
- username='username'
- )
- conn = sqlite3.connect('civworldpowers.db')
- c = conn.cursor()
- def outdated_ids():
- """Get all id's from the database that have not yet been updated"""
- c.execute('''SELECT id FROM posts WHERE updated IS NOT "True"''')
- for _id in c.fetchall():
- yield _id[0]
- def flair_score(_id):
- """Get the current flair and score for a particular submission"""
- sub = reddit.submission(_id)
- return sub.link_flair_css_class, sub.score, 'True', _id
- def update_id(data):
- """Update the flair and score for a submission"""
- while True:
- try:
- c.execute('''UPDATE posts SET flair = (?), score = (?),
- updated = (?) WHERE id=(?)''', data)
- except sqlite3.OperationalError:
- continue
- else:
- conn.commit()
- break
- def main():
- """Get all submissions that have not yet been updated, get their current score and
- flair and update the database with that information"""
- for _id in outdated_ids():
- update_id(flair_score(_id))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement