示例#1
0
import os
from peewee import PostgresqlDatabase, Model, CharField, BooleanField, ForeignKeyField
from flask_security import UserMixin, RoleMixin
from playhouse.db_url import connect

DATABASE = "hurtigen"
db = PostgresqlDatabase(DATABASE)

DATABASE_URL = os.environ.get("DATABASE_URL")
if DATABASE_URL:
    db = connect(DATABASE_URL)
else:
    DATABASE = "hurtigen"
    db = PostgresqlDatabase(DATABASE)


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


class Contact(BaseModel):
    email = CharField()
    message = CharField()


class Password(BaseModel):
    password = CharField()


class User(BaseModel, UserMixin):
示例#2
0
from chalicelib import settings
from peewee import PostgresqlDatabase

db = PostgresqlDatabase(settings.DATABASE['NAME'],
                        user=settings.DATABASE['USER'],
                        password=settings.DATABASE['PASSWORD'],
                        host=settings.DATABASE['HOST'],
                        port=settings.DATABASE['PORT'])
示例#3
0
from peewee import Model, CharField, IntegerField, DateTimeField, PostgresqlDatabase, TextField
from playhouse.postgres_ext import JSONField

from datetime import datetime

from config import get_cfg

db_cfg = get_cfg('db')
db_conn = {
    'host': db_cfg['host'],
    'user': db_cfg['user'],
    'password': db_cfg['password'],
    'database': db_cfg['database'],
    'autorollback': db_cfg['autorollback']
}
db = PostgresqlDatabase(**db_conn)

msg_ids = {"b_info": 0, "b_main": 0}


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


class User(BaseModel):
    tg_id = IntegerField()
    username = CharField()
    registered = DateTimeField(default=datetime.now)

示例#4
0
from dynaconf import settings
from enum import Enum
from peewee import Model, PostgresqlDatabase, CharField, IntegerField,BigIntegerField,FloatField,ForeignKeyField, DateTimeField
from peewee_extra_fields import EnumField
db = PostgresqlDatabase(settings.DATABASE_NAME, user=settings.DATABASE_USERNAME, password=settings.DATABASE_PASSWORD, host= settings.DATABASE_HOST)

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

    def __str__(self):
        sb = []
        for key in self.__dict__:
            sb.append("{key}='{value}'".format(key=key, value=self.__dict__[key]))
    
        return ', '.join(sb)
    
    def __repr__(self):
        return self.__str__() 


class TransactionType(Enum):
    BUY = 1
    SELL = 2

class Client(BaseModel) :
    name = CharField()
    wallet = FloatField()

示例#5
0
from .OrangeDB import Orange
from peewee import PostgresqlDatabase
from redis import Redis

config = Orange(file_path='config.json', auto_dump=False, load=True)
db = PostgresqlDatabase(
    config['database']['name'],
    user=config['database']['user'],
    host=config['database']['host'],
    port=config['database']['port'],
    password=config['database'].get('password')
)

redis = Redis(
    host=config['redis']['host'],
    port=config['redis']['port'],
    db=config['redis']['db'],
    password=config['redis'].get('password')
)


示例#6
0
import os
import pw_database_url
from peewee import PostgresqlDatabase, Model

config = pw_database_url.config()
database = PostgresqlDatabase(config['name'],
                              host=config['host'],
                              port=config['port'],
                              user=config['user'],
                              password=config['password'])
database.connect()


class BaseModel(Model):
    class Meta:
        database = database
示例#7
0
def init_postgresql(settings: dict):
    keys = {"database", "user", "password", "host", "port"}
    settings = {k: v for k, v in settings.items() if k in keys}
    db = PostgresqlDatabase(**settings)
    return db
示例#8
0
from peewee import PostgresqlDatabase, UUIDField, Model, CharField, TextField, ForeignKeyField, CompositeKey, \
    IntegerField, DoubleField

PEWEE_DB = PostgresqlDatabase(None)


class Student(Model):
    id = UUIDField(primary_key=True)
    name = CharField(max_length=64)
    surname = CharField(max_length=64)
    group_name = CharField(max_length=16)

    class Meta:
        database = PEWEE_DB
        db_table = 'students'


class Article(Model):
    id = UUIDField(primary_key=True)
    url = CharField(unique=True)
    title = CharField()
    text = TextField()
    keywords = CharField()
    author = CharField(null=True)

    student = ForeignKeyField(Student, to_field='id', db_column='student_id')

    class Meta:
        database = PEWEE_DB
        db_table = 'articles'
示例#9
0
from peewee import PostgresqlDatabase, Model, CharField, TextField

connection = {
    'user': '******',
    'password': '******',
    'host': '46.30.164.249',
    'port': 5432
}

db = PostgresqlDatabase('library', **connection)


class MyTexts(Model):
    key = CharField()
    slug = CharField()
    text = TextField()

    class Meta:
        database = db
        table_name = 'dor_texts'


# sql = "INSERT INTO dor_texts VALUES (556, 'value2', 'value3', 'Hello World');"
# db.execute_sql(sql)

# cursor = db.execute_sql('select * from dor_texts where slug = "asterisk";')
# for raw in cursor:
#     print(raw)

# text = MyTexts.create(
#     key='blabla',
示例#10
0
    IntegerField,
    Model,
    PostgresqlDatabase)

import settings as config


POSTGRES_HOST = config.DATABASE['HOST']
POSTGRES_PORT = int(config.DATABASE['PORT'])
POSTGRES_DATABASE = config.DATABASE['DATABASE']
POSTGRES_USER = config.DATABASE['USER']
POSTGRES_PASSWORD = config.DATABASE['PASSWORD']

db_handle = PostgresqlDatabase(database=POSTGRES_DATABASE,
                               host=POSTGRES_HOST,
                               port=POSTGRES_PORT,
                               user=POSTGRES_USER,
                               password=POSTGRES_PASSWORD)


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


class Transactions(BaseModel):
    id_transaction = IntegerField(primary_key=True)
    id_account = IntegerField()
    transaction_type = CharField(max_length=255)
    transaction_date = DateField()
    transaction_amount = FloatField()
示例#11
0
from decimal import Decimal

from decouple import config
from peewee import PostgresqlDatabase
from twitter import Api

INTERVAL = config('INTERVAL', cast=lambda x: int(x) * 60)
TIMEZONE = config('TIMEZONE')

REDIS_URL = config('REDIS_URL')
DATABASE = PostgresqlDatabase(database=config('POSTGRES_DB'),
                              user=config('POSTGRES_USER'),
                              password=config('POSTGRES_PASSWORD'),
                              host=config('POSTGRES_HOST'),
                              port=config('POSTGRES_PORT'))

CELERY_CONFIG = {'broker': REDIS_URL, 'timezone': TIMEZONE}

CREDENTIALS = {
    'consumer_key': config('TWITTER_CONSUMER_KEY', default=None),
    'consumer_secret': config('TWITTER_CONSUMER_SECRET', default=None),
    'access_token_key': config('TWITTER_ACCESS_TOKEN', default=None),
    'access_token_secret': config('TWITTER_ACCESS_TOKEN_SECRET', default=None)
}
TWITTER = Api(**CREDENTIALS) if all(CREDENTIALS.values()) else None
TWEET = config('TWEET')
CONTRACT_SPEED = config('CONTRACT_SPEED', cast=lambda x: int(x) * 10**6)
MINIMUM_SPEED = config('THRESHOLD', cast=lambda x: Decimal(x) * CONTRACT_SPEED)
示例#12
0
'''configuration values for api'''
from argon2 import PasswordHasher
from peewee import PostgresqlDatabase, SqliteDatabase
import os

DEBUG = True
HOST = '0.0.0.0'
PORT = 8000
SECRET_KEY = 'SD:FLKDWUdsfk;aifaw:WEFJuqhw*GF%DR$*&%$eFgYrtUjhuu9IuyR5p^TGIYv'
DEFAULT_RATE = '100/hour'
HASHER = PasswordHasher()
try:
    DATABASE = PostgresqlDatabase(os.environ['database'],
                                  host=os.environ['host'],
                                  port=os.environ['port'],
                                  user=os.environ['user'],
                                  password=os.environ['password'],
                                  sslmode=os.environ['sslmode'],
                                  sslrootcert=os.environ['sslrootcert'])
except KeyError:
    DATABASE = SqliteDatabase('courses.sqlite')
示例#13
0
import os
from dotenv import load_dotenv
from peewee import PostgresqlDatabase
from models.Oglas import Zupanija, Grad, Naselje, Oglas

load_dotenv()
env = os.environ

db = PostgresqlDatabase(
    "nadimistan",
    user=env.get("DB_USER"),
    password=env.get("DB_USER_PWD"),
    host=env.get("DB_HOST"),
)
db.create_tables([Zupanija, Grad, Naselje, Oglas])
示例#14
0
文件: models.py 项目: navikt/standbot
# I Ruby/Rails så brukes det flertall i navn på databasemodeller. Siden peewee
# ikke bruker dette mønsteret, så bruker vi `Meta.table_name` for å overskrive
# klassenavnet.

import os

from datetime import datetime
from peewee import PostgresqlDatabase, CharField, ForeignKeyField, Model, DateTimeField, TextField

USER = os.getenv('POSTGRES_USER', 'postgres')
PASSWORD = os.getenv('POSTGRES_PASSWORD', 'postgres')
HOST = os.getenv('POSTGRES_SOCKET_PATH', 'localhost')

DB = PostgresqlDatabase('standbot',
                        user=USER,
                        password=PASSWORD,
                        host=HOST,
                        port='5432')


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


class Team(BaseModel):
    class Meta:
        table_name = 'teams'

    name = CharField()
示例#15
0
# from app.server import server

# api = server.get_api()
config_name = os.getenv('FLASK_CONFIG')

if config_name == "development":
    db = SqliteDatabase("id.db")
else:
    database = {
        'user': '******',
        'password': '******',
        'host': '127.0.0.1',
        'port': 5432
    }

    db = PostgresqlDatabase("PAMS", **database)


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


class UserRole(BaseModel):

    role = TextField()


class User(BaseModel):

    username = TextField()
示例#16
0
from peewee import (
    Model,
    CharField,
    AutoField,
    PostgresqlDatabase,
    DateField,
    IntegerField,
    TextField,
)

db = PostgresqlDatabase("reviews", host="localhost", user="******")


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


class Album(BaseModel):
    id = AutoField()
    title = CharField()
    title_en = CharField()
    magazine_name = CharField()
    date = DateField()


class Reader(BaseModel):
    id = AutoField()
    first_name = CharField()
    last_name = CharField()
    age = IntegerField()
示例#17
0
import os
import datetime
from peewee import Model, PostgresqlDatabase, CharField, DateTimeField,\
    IntegerField, TextField, BigIntegerField
from playhouse.db_url import connect
import settings

if os.environ.get('DATABASE_URL'):
    database = connect(os.environ.get('DATABASE_URL'))
else:
    database = PostgresqlDatabase(
        settings.DB_NAME,
        user=settings.DB_USER,
        password=settings.DB_PASS,
        host=settings.DB_HOST,
    )


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


class Users(BaseModel):
    name = CharField()
    mobile = BigIntegerField()
    email = CharField()
    idcard = TextField()
    rtype = CharField()
    tickets = IntegerField()
    rdate = DateTimeField(default=datetime.datetime.now)
示例#18
0
import os

from dotenv import load_dotenv
from peewee import PostgresqlDatabase

load_dotenv()

DATABASE = os.getenv("DB_DATABASE")
USER = os.getenv("DB_USER")
PASSWORD = os.getenv("DB_PASSWORD")
HOST = os.getenv("DB_HOST")

db = PostgresqlDatabase(database=DATABASE, user=USER, password=PASSWORD, host=HOST)
示例#19
0
import numpy as np

########################################
# Begin database stuff

if 'DATABASE_URL' in os.environ:
    db_url = os.environ['DATABASE_URL']
    dbname = db_url.split('@')[1].split('/')[1]
    user = db_url.split('@')[0].split(':')[1].lstrip('//')
    password = db_url.split('@')[0].split(':')[2]
    host = db_url.split('@')[1].split('/')[0].split(':')[0]
    port = db_url.split('@')[1].split('/')[0].split(':')[1]
    DB = PostgresqlDatabase(
        dbname,
        user=user,
        password=password,
        host=host,
        port=port,
    )
else:
    DB = SqliteDatabase('predictions.db')


class Prediction(Model):
    observation_id = IntegerField(unique=True)
    observation = TextField()
    proba = FloatField()
    true_class = IntegerField(null=True)

    class Meta:
        database = DB
示例#20
0
import os

from peewee import PostgresqlDatabase

DB = PostgresqlDatabase(os.environ.get('ECONAPP_DATABASE'),
                        user=os.environ.get('ECONAPP_DATABASE_USER'),
                        password=os.environ.get('ECONAPP_DATABASE_PASSWORD'),
                        host=os.environ.get('ECONAPP_DATABASE_HOST',
                                            'localhost'))
示例#21
0
from peewee import PostgresqlDatabase
import os

SECRET = os.environ.get('SECRET')
POSTGRES_PASSWORD = os.environ.get('POSTGRES_PASSWORD')
POSTGRES_USER = os.environ.get('POSTGRES_USER')
POSTGRES_DB = os.environ.get('POSTGRES_DB')
TOKEN = os.environ.get('TOKEN')
GOD_ID = os.environ.get('GOD_ID')
GOD_NAME = os.environ.get('GOD_NAME')
MAX_SUM = os.environ.get('MAX_SUM')

db = PostgresqlDatabase(
    POSTGRES_DB,
    user=POSTGRES_USER,
    password=POSTGRES_PASSWORD,
    host='db')

# # for debug
# from peewee import SqliteDatabase
# import base64
#
# db = SqliteDatabase('bot.db')
# SECRET = base64.b64encode(open('secret', 'rb').read())
# TOKEN = '565567133:AAFrjt4yMptoRC1FUt8kB4RqTi1IoIEdnYY'
示例#22
0

app = Flask(__name__)
app.config.from_pyfile('flask.cfg')
if app.config['ENV'] == 'development':
    app.config['CHROME_DRIVER'] = 'chromedriver78'
    app.config['DATABASE_NAME'] = 'scraping'
    app.config['DATABASE_HOST'] = '35.227.74.45'
    app.config['DATABASE_USER'] = '******'
    app.config['DATABASE_PASSWORD'] = '******'
    app.config['PROXY_LIST'] = ['127.0.0.1:80']

db = PostgresqlDatabase(
    app.config['DATABASE_NAME'],
    host=app.config['DATABASE_HOST'],
    port=app.config['DATABASE_PORT'],
    user=app.config['DATABASE_USER'],
    password=app.config['DATABASE_PASSWORD']
)
Bootstrap(app)


# This hook ensures that a connection is opened to handle any queries
# generated by the request.
@app.before_request
def _db_connect():
    db.connect()


# This hook ensures that the connection is closed when we've finished
# processing the request.
示例#23
0
import os

from peewee import PostgresqlDatabase

db = PostgresqlDatabase(
    'scheduleDB',
    user='******',
    password='******',
    host='schedule-db.clhrtwy2vi9q.us-east-2.rds.amazonaws.com',
    port=5432)


def get_secret_key():
    return os.urandom(24)
import os, logging

import azure.functions as func
from azure.storage.blob import BlobServiceClient
from peewee import PostgresqlDatabase, Model, CharField, DateTimeField, TextField

db = PostgresqlDatabase(os.environ["PGDATABASE"])


class LogEntry(Model):
    name = CharField()
    created = DateTimeField()
    text = TextField()

    class Meta:
        indexes = ((('name', 'created'), True), )
        database = db


def init_database():
    db.connect()
    db.create_tables([LogEntry])


def main(myblob: func.InputStream):
    container, blobname = myblob.name.split("/", 1)
    blobclient = BlobServiceClient.from_connection_string(
        os.environ["FLEETCARE_CONNSTRING"])
    blob = blobclient.get_container_client(container).get_blob_client(blobname)
    blobprops = blob.get_blob_properties()
    blobtext = blob.download_blob().content_as_text()
示例#25
0
from peewee import PostgresqlDatabase, SqliteDatabase
from peewee import Model, CharField, TextField, IntegerField, BooleanField, DateTimeField, ForeignKeyField, CompositeKey

import bcrypt
import config

if config.production:
    db = PostgresqlDatabase(config.database.database, user=config.database.user, password=config.database.password)
else:
    db = SqliteDatabase("dev.db")


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


class Team(BaseModel):
    name = CharField(unique=True)
    affiliation = CharField(null=True)
    restricts = TextField(default="")
    key = CharField(unique=True, index=True)
    eligibility = BooleanField(null=True)

    def solved(self, challenge):
        return ChallengeSolve.select().where(ChallengeSolve.team == self, ChallengeSolve.challenge == challenge).count()

    def eligible(self):
        if self.eligibility is not None:
            return self.eligibility
        return all([member.eligible() for member in self.members]) and self.members.count() <= 3
示例#26
0
from datetime import datetime as dt
import peeweedbevolve
from peewee import (CharField, DateTimeField, Model, AutoField, IntegerField,
                    PostgresqlDatabase, TextField, FloatField, ForeignKeyField,
                    BooleanField, DecimalField)
from config import PG_CONN

db = PostgresqlDatabase(**PG_CONN)


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


class Users(BaseModel):
    id = AutoField()
    telegram_id = IntegerField(unique=1)
    username = CharField(null=True, unique=1)
    first_name = CharField(null=True)
    last_name = CharField(null=True)
    created_dt = DateTimeField(default=dt.utcnow)
    last_seen_dt = DateTimeField(default=dt.utcnow)


class Channels(BaseModel):
    id = AutoField()
    uuid = CharField()
    name = CharField(null=True)
    members_count = IntegerField(default=0)
    tid = CharField(unique=True)
示例#27
0
import os

import click
from flask import g
from flask.cli import with_appcontext
from peewee import PostgresqlDatabase

database = PostgresqlDatabase(os.environ['POSTGRES_DB'],
                              user=os.environ['POSTGRES_USER'],
                              password=os.environ['POSTGRES_PASSWORD'],
                              host=os.environ['POSTGRES_HOST'],
                              port=os.environ['POSTGRES_PORT'])


def get_db():
    if 'db' not in g:
        g.db = database
    return g.db


def close_db(e=None):
    db = g.pop('db', None)

    if db is not None:
        db.close()


def init_db():
    db = get_db()
    from flaskr.models import User, Post, AuthToken
    db.create_tables([User, Post, AuthToken])
示例#28
0
from peewee import PostgresqlDatabase, Model, CharField
from playhouse.shortcuts import model_to_dict, dict_to_model
from functools import partial

db = PostgresqlDatabase('bookmarks',
                        user='******',
                        password='',
                        host='localhost',
                        port=5432)
db.connect()


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


class Bookmark(BaseModel):
    name = CharField()
    category = CharField()
    url = CharField()


# db.drop_tables([Bookmark])
db.create_tables([Bookmark])


def bookmarker():
    current_bookmarks()

    print("What would you like to do?")
示例#29
0
from decimal import Decimal

from decouple import config
from peewee import PostgresqlDatabase
from twitter import Api

INTERVAL = config("INTERVAL", cast=lambda x: int(x) * 60)
TIMEZONE = config("TIMEZONE")

REDIS_URL = config("REDIS_URL")
DATABASE = PostgresqlDatabase(
    database=config("POSTGRES_DB"),
    user=config("POSTGRES_USER"),
    password=config("POSTGRES_PASSWORD"),
    host=config("POSTGRES_HOST"),
    port=config("POSTGRES_PORT"),
)

CELERY_CONFIG = {"broker": REDIS_URL, "timezone": TIMEZONE}

CREDENTIALS = {
    "consumer_key": config("TWITTER_CONSUMER_KEY", default=None),
    "consumer_secret": config("TWITTER_CONSUMER_SECRET", default=None),
    "access_token_key": config("TWITTER_ACCESS_TOKEN", default=None),
    "access_token_secret": config("TWITTER_ACCESS_TOKEN_SECRET", default=None),
}
TWITTER = Api(**CREDENTIALS) if all(CREDENTIALS.values()) else None
TWEET = config("TWEET")
CONTRACT_SPEED = config("CONTRACT_SPEED", cast=lambda x: int(x) * 10**6)
MINIMUM_SPEED = config("THRESHOLD", cast=lambda x: Decimal(x) * CONTRACT_SPEED)
示例#30
0
from os import environ

from flask_login import UserMixin
from dsnparse import parse_environ
from peewee import (SqliteDatabase, PostgresqlDatabase, Model, CharField,
                    TextField, DateTimeField, ForeignKeyField, DecimalField,
                    IntegerField,)

if(environ.get('DATABASE_URL')):
    url = parse_environ('DATABASE_URL')
    db = PostgresqlDatabase(url.paths[0],
                            user=url.username,
                            password=url.password,
                            host=url.host,
                            port=url.port)
else:
    db = SqliteDatabase('groovin.db')


class Promoter(Model, UserMixin):
    name = CharField()
    email = CharField(unique=True)
    bio = TextField()
    password = CharField()

    def to_map(self):
        data = self.__dict__['__data__']
        data.pop('password')
        return data

    class Meta: