Ejemplo n.º 1
0
from utils import execute
import peewee as pw

db = 'perkedu'

database = pw.MySQLDatabase(db, **{'user': '******'})


class UnknownField(object):
    pass


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


class Questions(BaseModel):
    anonymous = pw.IntegerField(null=True)
    answers = pw.IntegerField()
    category = pw.IntegerField(null=True)
    modified = pw.DateTimeField()
    name = pw.CharField(max_length=255)
    posted = pw.DateTimeField()
    question = pw.CharField(max_length=255)
    studentid = pw.CharField(db_column='student_id', max_length=254)

    class Meta:
        db_table = 'questions'

Ejemplo n.º 2
0
from bs4 import BeautifulSoup
import peewee

BASE_URL = 'http://210.75.213.188/shh/portal/bjjs2016/'
PAGE = 2940

username = '******'
password = ''
dbname = 'ershoufang'
host = '127.0.0.1'

database = peewee.MySQLDatabase(
    dbname,
    host=host,
    port=3306,
    user=username,
    passwd=password,
    charset='utf8',
    use_unicode=True,
)


class BaseModel(peewee.Model):
    def __init__(self):
        pass

    class Meta:
        def __init__(self):
            super().__init__()
            pass
Ejemplo n.º 3
0
            gateway_name=self.gateway_name,
        )

        self.gateway.on_contract(contract)


#建立链接
# connect = peewee.SqliteDatabase("/home/jiangyx/fruitday/db.sqlite3") #运行该程序后就能在当前目录下创建“test.db”数据库

settings = {
    'host': '47.244.240.38',
    'password': '******',
    'port': 3306,
    'user': '******'
}
connect = peewee.MySQLDatabase("fruitday", **settings)


class Money(peewee.Model):
    money_user_id = peewee.CharField(
        max_length=255)  # This field type is a guess.
    money_balance = peewee.FloatField()
    money_available = peewee.FloatField()
    money_frozen = peewee.FloatField()
    money_accountid = peewee.CharField(
        primary_key=True, max_length=255)  # This field type is a guess.

    class Meta:
        database = connect

Ejemplo n.º 4
0
import peewee as pw
import os

import sys
from os import path

sys.path.append(path.join(path.dirname(__file__), '..'))
import load_env

db = pw.MySQLDatabase(
    os.getenv("DB_NAME"),
    user=os.getenv("DB_USER"),
    password=os.getenv("DB_PW"),
    host=os.getenv("DB_HOST"),
    port=int(os.getenv("DB_PORT")),
)
Ejemplo n.º 5
0
import peewee
from peewee import *
import pandas as pd

db = peewee.MySQLDatabase('securities_master',
                          user='******',
                          passwd='password')


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


class Exchange(BaseModel):
    #exchange_id = IntegerField(primary_key = True,unique = True,null=False)
    abbrev = CharField(null=False, max_length=32, unique=True)
    name = CharField(null=False, max_length=255)
    city = CharField(null=True, max_length=255)
    country = CharField(null=True, max_length=255)
    currency = CharField(null=True, max_length=64)
    timezone_offset = TimeField()
    created_date = DateTimeField(null=False)
    last_updated_date = DateTimeField(null=False)


class Data_Vendor(BaseModel):
    #data_vendor_id =IntegerField(primary_key = True,unique = True,null=False)
    name = CharField(null=False, max_length=64, unique=True)
    website_url = CharField(null=True, max_length=255)
    support_email = CharField(null=True, max_length=255)
Ejemplo n.º 6
0
from datetime import datetime, date
from math import log
import peewee

# open DataBase
db = peewee.MySQLDatabase('my-trac', user='******', passwd='')


class Limits_user(peewee.Model):
    name = peewee.TextField()
    weight = peewee.FloatField()
    maximum = peewee.IntegerField()

    class Meta:
        database = db


class Weight:
    registration = Limits_user.get(Limits_user.name == 'registration').weight
    valuations = Limits_user.get(Limits_user.name == 'valuations').weight
    uses_app = Limits_user.get(Limits_user.name == 'uses_app').weight
    tickets_purchased = Limits_user.get(
        Limits_user.name == 'tickets_purchased').weight
    groups = Limits_user.get(Limits_user.name == 'groups').weight


class Maximum:
    registration = Limits_user.get(Limits_user.name == 'registration').maximum
    valuations = Limits_user.get(Limits_user.name == 'valuations').maximum
    uses_app = Limits_user.get(Limits_user.name == 'uses_app').maximum
    tickets_purchased = Limits_user.get(
Ejemplo n.º 7
0
import peewee as pw
import os
from dateutil import parser

myDB = (pw.MySQLDatabase(os.environ['CTC_CANDLES_DB'],
                         host=os.environ['CTC_CANDLES_HOST'],
                         port=int(os.environ['CTC_CANDLES_PORT']),
                         user=os.environ['CTC_CANDLES_USER'],
                         passwd=os.environ['CTC_CANDLES_PASSWORD']))


class MySQLModel(pw.Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = myDB


class Candle(MySQLModel):
    firstTrade = None
    lastTrade = None
    close = pw.DecimalField(null=True)
    high = pw.DecimalField(null=True)
    low = pw.DecimalField(null=True)
    open = pw.DecimalField(null=True)
    trades = pw.IntegerField(null=True)
    volume = pw.DecimalField(null=True, max_digits=20, decimal_places=8)
    idfrom = pw.IntegerField(null=True)
    idto = pw.IntegerField(null=True)
    candle_date_time = pw.CharField(null=True)

Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
################################### PART0 DESCRIPTION #################################
# Filename: db.py
# Description:
#

# E-mail: [email protected]
# Create: 2016-08-28 23:09:25
# Last:
__author__ = 'yuens'

################################### PART1 IMPORT ######################################

import peewee

databaseName = "DouBan"
hostName = "localhost"
password = "******"
userName = '******'
portCode = 3306

#database = peewee.MySQLDatabase('web_db', **{'host': 'localhost', 'password': '******', 'port': 3306, 'user': '******'})
database = peewee.MySQLDatabase(database=databaseName,
                                **{
                                    'host': hostName,
                                    'password': password,
                                    'port': portCode,
                                    'user': userName
                                })
Ejemplo n.º 9
0
 def setUp(self):
     os.system('echo "create database peeweedbevolve_test;" | mysql')
     self.db = pw.MySQLDatabase('peeweedbevolve_test')
     self.db.connect()
     peeweedbevolve.clear()
Ejemplo n.º 10
0
import os
import peewee

DATABASE = os.environ.get('DATEBASE')

if DATABASE == 'MYSQL':
    database = peewee.MySQLDatabase(database="USERDB",
                                    host=os.environ.get('MYSQL_HOST'),
                                    user="******",
                                    password="******",
                                    charset="utf8mb4")
else:
    database = peewee.SqliteDatabase(
        os.path.join(os.path.dirname(__file__), 'example.db'))


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


# Example below
# class User(BaseModel):
#     id = peewee.AutoField()
#     username = peewee.CharField(unique=True)
#     email = peewee.CharField()
#     join_date = peewee.DateTimeField(formats="%y/%m/%d %H:%M:%S")


def create_tables():
    # with database:
Ejemplo n.º 11
0
        os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
import toycabinet
import peewee
from toycabinet.core.dborm.models import User
from toycabinet.core.preset import Preset

if not len(Preset.tool.email):
    raise KeyError(
        'ToyCabinet register need client email address, please fill in [presets.json]'
    )

if Preset.tool.db_type == 'postgres':
    DB = peewee.PostgresqlDatabase(**Preset.tool.db_info)
elif Preset.tool.db_type == 'mysql':
    DB = peewee.MySQLDatabase(**Preset.tool.db_info)
elif Preset.tool.db_type == 'sqlite':
    DB = peewee.SqliteDatabase(**Preset.tool.db_info)
else:
    raise KeyError(
        'ToyCabinet support database types: 1.postgres  2.mysql  3.sqlite ')

database = DB
database.connect()

user = User.get(id=1)
user.name = 'admin'
user.admin = True
user.password = '******'
user.save()
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-

import peewee, pickle, pdb

from datetime import datetime as dt
from random import choice
from datetime import datetime as dt
from utils import return_slug

from project import bcrypt

_database = peewee.MySQLDatabase('wing_cms',
                                 user='******',
                                 passwd='wing_cms')


class BaseModel(peewee.Model):
    class Meta:
        database = _database


class ArticleRevision(BaseModel):
    pickle_obj = peewee.TextField()
    creation_date = peewee.DateField(default=dt.today().date())

    def __unicode__(self):
        return 'rev. from %s. v%s' % (self.creation_date.strftime('%Y-%m-%d'),
                                      self.id)


class CategoryRevision(BaseModel):
Ejemplo n.º 13
0
from flask import Flask, render_template, request, send_from_directory
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import SelectField, SubmitField, RadioField, StringField
from wtforms.validators import DataRequired
import peewee as pw
import json
import os

#####################数据库相关##################################################
# 数据库名称定义为全局变量
global MYSQLDB
MYSQLDB = pw.MySQLDatabase('trftarget',
                           user='******',
                           password='******',
                           host='127.0.0.1',
                           port=3306,
                           autoconnect=False)


class MYSQLBaseModel(pw.Model):
    # 所用数据库为MYSQLDB
    class Meta:
        database = MYSQLDB  # MYSQLDB为所定义的数据库变量


# 定义MySQL data types
class UnTinyIntField(pw.IntegerField):
    # Range 0-255
    field_type = 'TINYINT UNSIGNED'
Ejemplo n.º 14
0
#creation d'une DataBase
import peewee as pw

# connection a la base de donnees
myDB = pw.MySQLDatabase("marattm_webproject_quizz",
    host="mysql2.paris1.alwaysdata.com",
    port=3306,
    user="******",
    passwd="Azer0123")
myDB.connect()

# Definition de la table 'HighScore'
class Quizz(pw.Model):
    class Meta:
        database = myDB
    # Definition de 3 colonnes
    name = pw.CharField()           #nom image
    img = pw.CharField()            #adresse une image
    label_name = pw.CharField()     #type de l'image
    label_nb = pw.BigIntegerField() #ordre
    # le champ id est automatiquement cree


if __name__ == "__main__":
    # si ce fichier est execute a la main, alors creation de la table
    myDB.create_tables([Quizz])
Ejemplo n.º 15
0
import peewee as pw
import config

myDB = pw.MySQLDatabase(\
            config.db['name'], \
            host = config.db['host'], \
            user = config.db['user'],\
            passwd = config.db['passwd'])


class BaseModel(pw.Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = myDB


class major(BaseModel):
    id = pw.PrimaryKeyField()
    major_code = pw.CharField(max_length=255)
    major_name = pw.CharField(max_length=255)


class course(BaseModel):
    id = pw.PrimaryKeyField()
    major = pw.ForeignKeyField(major, related_name='courses')
    course_code = pw.CharField(max_length=255)
    course_name = pw.CharField(max_length=255)


def createTables():
    myDB.connect()
Ejemplo n.º 16
0
import peewee
import datetime

database = peewee.MySQLDatabase('test',
                                host='localhost',
                                port=3306,
                                user='******',
                                passwd='')


class User(peewee.Model):
    username = peewee.CharField(unique=True, max_length=50, index=True)
    password = peewee.CharField(max_length=50, null=True)
    email = peewee.CharField(max_length=50)
    active = peewee.BooleanField(default=True)
    created_date = peewee.DateTimeField(default=datetime.datetime.now)

    class Meta:
        database = database
        db_table = 'users'

    def __str__(self):
        return self.username


class Store(peewee.Model):
    admin = peewee.ForeignKeyField(
        User, related_name='store')  #primary_key=True Relacion uno a uno
    name = peewee.CharField(max_length=50, unique=50, index=True)
    address = peewee.TextField()
    active = peewee.BooleanField(default=True)
Ejemplo n.º 17
0
#!/usr/bin/env python

import re
from collections import Counter
from collections import defaultdict
from collections import OrderedDict
from operator import itemgetter
import time
import datetime
import random

#########################################################
import peewee as pw

myDB = pw.MySQLDatabase("mail_db", host="localhost", port=3306, user="******", passwd="mysql")

class MySQLModel(pw.Model):
    """A base model that will use our MySQL database"""
    class Meta:
        database = myDB

class mailing(MySQLModel):
    addr = pw.CharField(max_length=255, unique=True,primary_key=True)

def connect():
    try:
        myDB.connect()
        print("... DB connected")
    except Error as e:
        print(e)
        print("... DB not connected")
Ejemplo n.º 18
0
import os
import configparser
import peewee

# config.ini から設定値を読み込む
ini_file = configparser.ConfigParser()
ini_file.read_file(open("config.ini"))

# # local保存の場合
# HOST = ini_file.get('db_local', 'HOST')
# DATABASE = ini_file.get('db_local', 'DATABASE')
# USER = ini_file.get('db_local', 'USER')
# PASSWD = ini_file.get('db_local', 'PASSWD')

# docker-compose 保存の場合
HOST = ini_file.get('db_docker', 'HOST')
DATABASE = ini_file.get('db_docker', 'DATABASE')
USER = ini_file.get('db_docker', 'USER')
PASSWD = ini_file.get('db_docker', 'PASSWD')

# データベース接続
db = peewee.MySQLDatabase(host=HOST,
                          database=DATABASE,
                          user=USER,
                          password=PASSWD)
Ejemplo n.º 19
0
import peewee
import json

# Open configuration file
try:
    with open('config.json', encoding='utf8') as config_file:
        Config = json.load(config_file)
except:
    print('Unable to open config.json!')
    print(
        'If you haven\'t created a configuration file, please use the example configuration file as a guide.'
    )
    print('Otherwise, make sure the file permissions are set correctly.')
    exit(1)

db = peewee.MySQLDatabase(Config['mail']['db_db'],
                          host=Config['mail']['db_host'],
                          port=Config['mail']['db_port'],
                          user=Config['mail']['db_user'],
                          passwd=Config['mail']['db_password'],
                          charset=Config['mail']['db_charset'])


class BaseModel(peewee.Model):
    class Meta:
        database = db
Ejemplo n.º 20
0
from contextvars import ContextVar
from api import config
import peewee

db_state_default = {"closed": None, "conn": None, "ctx": None, "transactions": None}
db_state = ContextVar("db_state", default=db_state_default.copy())

class PeeweeConnectionState(peewee._ConnectionState):
    def __init__(self, **kwargs):
        super().__setattr__("_state", db_state)
        super().__init__(**kwargs)

    def __setattr__(self, name, value):
        self._state.get()[name] = value

    def __getattr__(self, name):
        return self._state.get()[name]

db = None

if config.DATABASE_TYPE == "mysql":
    db = peewee.MySQLDatabase(config.MYSQL_DB, host=config.MYSQL_HOST,
        port=config.MYSQL_PORT, user=config.MYSQL_USER, password=config.MYSQL_PASS)
else:
    db = peewee.SqliteDatabase(config.SQLITE_NAME, check_same_thread=False)

db._state = PeeweeConnectionState()