gdritter repos shitbird / master shitbird / common.py
master

Tree @master (Download .tar.gz)

common.py @masterraw · history · blame

import os
import re
import sqlite3
import yaml

DEFAULT_SBDIR = os.path.join(os.environ['HOME'], '.shitbird')
SBDIR = os.environ.get('SBDIR', DEFAULT_SBDIR)
DB_LOCATION = os.path.join(SBDIR, 'tweets.db')
CFG_LOCATION = os.path.join(SBDIR, 'config.yaml')

try:
    with open(CFG_LOCATION) as f:
        CONFIG = yaml.load(f)
except:
    CONFIG = {}

def row_to_dict(row):
    return { 'id': row[0],
             'tweet': row[1],
             'date': row[2],
             'name': row[3],
             'handle': row[4] }

def get_tweets():
    with sqlite3.connect(DB_LOCATION) as conn:
        c = conn.cursor()
        for row in c.execute('SELECT * FROM tweets;'):
            yield row_to_dict(row)
        conn.commit()