gdritter repos shitbird / master shitbird / fetch.py
master

Tree @master (Download .tar.gz)

fetch.py @masterraw · history · blame

#!/usr/bin/python2

import common
import sqlite3
import tweepy

def main():
    auth = tweepy.OAuthHandler(common.CONFIG['consumer_key'],
                               common.CONFIG['consumer_secret'])
    auth.set_access_token(common.CONFIG['access_token'],
                          common.CONFIG['access_token_secret'])
    api = tweepy.API(auth)

    with sqlite3.connect(common.DB_LOCATION) as conn:
        c = conn.cursor()
        add_tweets(api, c)
        conn.commit()

def add_tweets(api, c):
    for t in api.home_timeline():
        c.execute('INSERT INTO tweets VALUES (?, ?, ?, ?, ?)',
                  ( t.id,
                    t.text,
                    t.created_at.isoformat(),
                    t.author.name,
                    t.author.screen_name
                  ))

if __name__ == '__main__':
    main()