Exemple #1
0
def start_database(dbname, sqlite=False, tbl_name=None, **kwargs):
    """Connect to a SQLite or MySQL database.

    Args:
        dbname (str): Database path (SQLite) or name (MySQL).

    Kwargs:
        sqlite (bool): Use SQLite instead of MySQL.
        tbl_name (str): Alternative name for locations table.
        host (str): MySQL host.
        user (str): Username for MySQL.
        passwd (str): Password for MySQL.
        ssl (dict): Dictionary of paths to SSL certificates.
    """
    if sqlite:
        db = SqliteExtDatabase(dbname)
    else:
        db = MySQLDatabase(dbname, **kwargs)

    if tbl_name is not None:
        Location._meta.db_table = tbl_name.strip()

    dbproxy.initialize(db)
    db.create_table(Location, safe=True)

    return db
Exemple #2
0
def main():
    '''setup db, get connection to bittorrent, download movies'''
    movie_database = SqliteExtDatabase('movies.db')

    class Movie(Model):
        '''movie object for database'''
        title = TextField()
        name = TextField()
        label = TextField()
        magnet_link = TextField()
        downloaded = BooleanField()

        class Meta:
            '''set database for the model'''
            database = movie_database

    movie_database.connect()
    movie_database.create_table(Movie, safe=True)

    bittorrent = setup_bittorrent()

    while True:
        download_movies(bittorrent, Movie)
        time.sleep(60)
Exemple #3
0
from peewee import *
from playhouse.sqlite_ext import AutoIncrementField, SqliteExtDatabase

database_file = "data.sqlite"
db = SqliteExtDatabase(database_file, pragmas=(('foreign_keys', 'on'), ))


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    id = AutoIncrementField()
    name = TextField()
    login = TextField()
    password = TextField()


class WishList(BaseModel):
    # user = ForeignKeyField(User, related_name='wishlist')
    name = TextField()
    description = TextField(null=True)
    cost = TextField(null=True)
    links = TextField(null=True)
    picture = TextField(null=True)


db.create_table(User, safe=True)
db.create_table(WishList, safe=True)