def create(): """Creates db from model and executes sql script to fill tables""" Rss.create_table() Data.create_table() Tokenized.create_table() with open(SQL_SCRIPT) as f: for line in f: SQL_DB.execute_sql(line.strip())
def insert_update_data(data, cache_time_delta=None): """Inserts new prased feed or updates existing parsed feed""" dt = get_datetime(time_delta=cache_time_delta) if Data.select().where( (Data.last_modified > dt) & (Data.identifier == data['identifier'])).exists(): row = Data.get( (Data.last_modified > dt) & (Data.identifier == data['identifier'])) result = update_data(row, data) elif Data.select().where( (Data.last_modified > dt) & (Data.rss_id == data['rss_id']) & (Data.description_hash == data['description_hash'])).exists(): row = Data.get( (Data.last_modified > dt) & (Data.rss_id == data['rss_id']) & (Data.description_hash == data['description_hash'])) result = update_data(row, data) else: result = insert_data(data) return result
def insert_data(data): new_row = Data() new_row.rss_id = data['rss_id'] new_row.identifier = data['identifier'] new_row.published = data['published'] new_row.last_modified = datetime.datetime.now() new_row.description = data['description'] new_row.description_hash = data['description_hash'] new_row.title = data['title'] new_row.link = data['link'] new_row.save() return new_row.data_id