コード例 #1
0
def list_active_legislators_first():
    query = 'select bioguide_id from bioguide_legislatorrole group by bioguide_id order by max(end_date) desc, bioguide_id'
    from MySQLdb import Connection
    cursor = Connection('localhost', 'capwords', 'capwords',
                        'capwords').cursor()
    cursor.execute(query)
    results = [x[0] for x in cursor.fetchall()]
    return results
コード例 #2
0
ファイル: DB.py プロジェクト: laohaier67/secure-storage
 def __init__(self, config):
     '''
     Constructor
     '''
     self.config=config
     conn=Connection(**config)
     if not conn:
         #print("connection failed")
         pass
     self.cursor=conn.cursor()
     self.conn=conn
コード例 #3
0
ファイル: api.py プロジェクト: serenahjl/autumn
 def connect(self):
     try:
         self.__connect = Connection(host=self.__host,
                                     user=self.__user,
                                     passwd=self.__password,
                                     db=self.__db,
                                     port=self.__port,
                                     connect_timeout=self.__timeout)
         self.__cursor = self.__connect.cursor(DictCursor)
         self.__connected = True
     except Exception as e:
         raise MySQLAPIException(e)
コード例 #4
0
 def GenerateConn(dbname,
                  host="localhost",
                  port=3306,
                  user="******",
                  passwd="123456",
                  charset='utf8'):
     conn = Connection(host=host,
                       port=port,
                       user=user,
                       passwd=passwd,
                       db=dbname,
                       charset=charset)
     return conn
コード例 #5
0
ファイル: spide_to_db.py プロジェクト: ppaydd/problem_count
def db_connect():
    while True:
        try:
            mysqldb = Connection(host=database['host'],
                                 user=database['user'],
                                 passwd=database['password'],
                                 db=database['db'],
                                 charset=database['charset'])
        except Exception:
            print('error')
            continue
        else:
            return mysqldb
コード例 #6
0
def create_connection(*args, **kwargs):
    print(kwargs)

    if not kwargs:
        raise ValueError("Must send connection details")

    if not kwargs.get("host", None) or not kwargs.get(
            "user", None) or not kwargs.get("passwd", None):
        raise ValueError("Arguments 'host', 'user' and 'passwd' are required")

    connection = None

    try:
        connection = Connection(host=kwargs.get("host", None),
                                user=kwargs.get("user", None),
                                passwd=kwargs.get("passwd", None),
                                database=kwargs.get("database", "mysql"))
        print("Connection to MySQL DB successful")

    except Error as e:
        traceback.print_exc()
        raise

    return connection
コード例 #7
0
# -*- coding:utf-8 -*-

__author__ = 'wanggen'

import os
from MySQLdb import Connection

conn = Connection(host='wg-linux',
                  user='******',
                  passwd='wanggen',
                  db='groupon',
                  charset='utf8')

cursor = conn.cursor()

cursor.execute('select * from ecp_orders limit 10')

cursor.close()

a = """
 ls -l ../
"""
files = os.popen(a).read()

with open('test', mode='wr') as f:
    f.write(files)