예제 #1
0
def create_database_connection():
    """Creates a connection to a MySQLDatabase using the parmeters specified
    in the setting file"""
    try:
        db = MySQLDatabase(
            settings.DATABASE,
            user=settings.USERNAME,
            passwd=settings.PASSWORD,
            host=settings.HOST
        )
        db.connect()
    except Exception as e:
        print "Failed to connect to database", e
    return db
예제 #2
0
def doSQL(n, u, h, a, g):
    db = MySQLDatabase("asm_main", host=host, port=3306, user=user, passwd=passwd)
    db.connect()
    cur = db.get_cursor()
    
    nick = n
    user = u
    host = h
    account = a
    gecos = g
    
    escape = db.get_conn().escape_string
    
    sql = "SELECT * FROM actionlog WHERE "
    search = []
    if nick:
        search.append("nick LIKE '{nick}'".format(nick=escape(nick)))
    if user:
        search.append("user LIKE '{user}'".format(user=escape(user)))
    if host:
        search.append("host LIKE '{host}'".format(host=escape(host)))
    if account:
        search.append("account LIKE '{account}'".format(account=escape(account)))
    if gecos:
        search.append("gecos LIKE '{gecos}'".format(gecos=escape(gecos)))
    
    sql = sql+" OR ".join(search)
    l = cur.execute(sql)
    output = ""
    for row in cur.fetchall():
        output+= "<tr>"
        output+= "<td>#{}</td>".format(row[0]) # id
        output+= "<td>{}</td>".format(row[1])  # date
        output+= "<td>{}<span class=\"userhost\">!{}@{}</span></td>".format(row[5],row[6],row[7]) # nick!ident@host
        output+= "<td>received {}".format(row[2])  # event
        # (11, datetime.datetime(2016, 2, 21, 20, 25, 45), 'quiet', None, '##doge', 'doge', '~doge',
        # 'antispammeta/suchmeta/botters.doge', None, 'doge', 'doge', 'falco-devel', '~falco',
        # 'botters/doge/bot/falco', "nathan's bot", 'falco')
        if row[11]:
            output+= " from {}<span class=\"userhost\">{}{}</span></td>".format(
                row[11], "!"+row[12] if row[12] else "", "@"+row[13] if row[13] else "") # who it was from
        elif not row[11]:
            output+= "</td>"
        output+= "<td>{}</td>".format(row[4] if row[4] else "") # channel
        output+= "<td>{}</td>".format(row[3] if row[3] else "") # reason
        output+= "</tr>"
    return output
예제 #3
0
파일: learn.py 프로젝트: joetoth/dotfiles
                    help='Start in daemon mode which notifies to rekall')
parser.add_argument('--concept', type=str,
                    help='Concept to store for rekall')
parser.add_argument('--rekall', type=bool, default=False,
                    help='Print text and increment rekall')
parser.add_argument('--remove', type=bool, default=False,
                    help='Remove a concept')
parser.add_argument('--printall', type=bool, default=False,
                    help='Print everything in the database')

config = ConfigParser.ConfigParser()
config.read(os.path.expanduser('~/.rekall'))

args = parser.parse_args()
db = MySQLDatabase("rekall", host=config.get("mysql", "host"), user=config.get("mysql", "user"), passwd=config.get("mysql", "password"), charset="utf8", use_unicode=True)
db.connect()

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

class Concept(BaseModel):
  name = CharField()
  text = TextField(default="# Explanation / Analogy / Like I'm Five" )
  last_rekall = DateTimeField(default=datetime.datetime.now)
  rekalls = IntegerField(default=0)

  def next_rekall(self):
    return self.last_rekall + datetime.timedelta(seconds=(INTERVAL_SECONDS ^ self.rekalls))

Concept.create_table(fail_silently=True)
예제 #4
0
#!/usr/bin/env python
# encoding: utf-8

from peewee import (MySQLDatabase, Model, ForeignKeyField,
                    TextField, BigIntegerField, DateTimeField)

import settings


database = MySQLDatabase(settings.DATABASE,
                         user=settings.USER,
                         password=settings.PASSWORD)
database.connect()


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


class Category(BaseModel):
    name = TextField()


class Torrent(BaseModel):
    category = ForeignKeyField(Category)
    title = TextField()
    size = BigIntegerField()
    magnet = TextField()
    hash = TextField()
    nfo = TextField()
예제 #5
0
from peewee import CharField, Model, MySQLDatabase
from app import app

MYSQL_DB = 'users'
MYSQL_HOST = 'localhost'
MYSQL_PORT = 3306
MYSQL_USER = '******'
MYSQL_PASS = '******'

db = MySQLDatabase(MYSQL_DB,
                   host=MYSQL_HOST,
                   port=MYSQL_PORT,
                   user=MYSQL_USER,
                   passwd=MYSQL_PASS)
db.connect()


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


class tbl_users2(BaseModel):
    user_name = CharField(primary_key=True)
    user_password = CharField()
예제 #6
0
def last_test_pymysql():
    conn = MySQLDatabase.connect(host='localhost',
                                 port=3306,
                                 user='******',
                                 db='mysql')