当前位置: 首页>>代码示例>>Python>>正文


Python Connector.connect方法代码示例

本文整理汇总了Python中connector.Connector.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Connector.connect方法的具体用法?Python Connector.connect怎么用?Python Connector.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connector.Connector的用法示例。


在下文中一共展示了Connector.connect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fill_gen_add_payment

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_add_payment():
    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()

    cursor.execute("select ReservationID, ToPay, ReservationDate from Reservations")
    row = cursor.fetchone()

    ratio = [i / 10 for i in range(1, 11)]

    c = Connector()
    cn = c.connect(secretpassword)

    while row:
        reservationid = row[0]
        topay = row[1]
        date = row[2]
        money_deposited = math.floor(int(topay) * random.choice(ratio))

        (y, m, d) = date.split("-")
        begin = dt.date(int(y), int(m), int(d)).toordinal()
        book_ord = dt.datetime.fromordinal(begin + random.randint(1, 7))
        date_of_payment = "/".join((str(book_ord.year), str(book_ord.month), str(book_ord.day)))

        result = (reservationid, money_deposited, date_of_payment)
        print("Add Payment " + str(result))
        c.apply_proc('GeneratorAddPayment', result)

        row = cursor.fetchone()

    conn.close()
    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:34,代码来源:generator.py

示例2: fill_gen_book_places_for_workshop

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_book_places_for_workshop():
    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()

    cursor.execute("select Reservations.ReservationID, WorkshopID, MaxSpots "
                   "from DaysOfConf "
                   "inner join Workshops on Workshops.DayID = DaysOfConf.DayID "
                   "inner join Reservations on Reservations.DayID = DaysOfConf.DayID")
    row = cursor.fetchone()

    c = Connector()
    cn = c.connect(secretpassword)

    while row:
        reservationid = row[0]
        workshopid = row[1]
        maxspots = math.floor(row[2] / 3)

        result = (reservationid, workshopid, maxspots)
        print("Add Workshop Reservation " + str(result))
        c.apply_proc('BookPlacesForWorkshop', result)

        row = cursor.fetchone()

    conn.close()
    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:29,代码来源:generator.py

示例3: fill_gen_add_attendees

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_add_attendees():
    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()

    cursor.execute("select company.clientid, spotsreserved from company "
                   "inner join clients on clients.clientid = company.clientid "
                   "inner join reservations on reservations.clientid = clients.clientid")
    row = cursor.fetchone()

    c = Connector()
    cn = c.connect(secretpassword)

    while row:
        clientid = row[0]
        spots_reserved = row[1]

        for reservation in range(spots_reserved):

            name, surname = getNameSurname()
            result = (clientid, name, surname)
            print("Add Attendee " + str(result))
            c.apply_proc('AddAttendee', result)

        row = cursor.fetchone()

    conn.close()
    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:30,代码来源:generator.py

示例4: fill_gen_assign_workshop_attendee

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_assign_workshop_attendee():

    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()

    workshop_attendees = []

    cursor.execute("select distinct Attendees.AttendeeID, WorkshopReservations.WReservationID "
                   "from Attendees "
                   "inner join Participation on Participation.AttendeeID = Attendees.AttendeeID "
                   "inner join Reservations on Reservations.ReservationID = Participation.ReservationID "
                   "inner join WorkshopReservations on WorkshopReservations.ReservationID = Reservations.ReservationID")

    row = cursor.fetchone()

    while row:
        workshop_attendees.append((row[0], row[1]))
        row = cursor.fetchone()

    filler = Connector()

    workshop_attendees_size = len(workshop_attendees)
    filler.apply_proc_multi('AssignParticipantToWorkshop', workshop_attendees, workshop_attendees_size)



    conn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:30,代码来源:generator.py

示例5: fill_gen_book_places_for_day

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_book_places_for_day():
    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()
    clients = []
    clients_getter = conn.cursor()
    clients_getter.execute("select clientid from clients")
    clients_ids = clients_getter.fetchone()
    while clients_ids:
        clients.append(clients_ids[0])
        clients_ids = clients_getter.fetchone()

    cursor.execute("select DayId, conferences.DateFrom, Spots "
                   "from DaysOfConf "
                   "inner join Conferences on conferences.ConferenceId = daysofconf.ConferenceId")
    row = cursor.fetchone()

    c = Connector()
    cn = c.connect(secretpassword)


    while row:
        dayid = row[0]
        date = row[1]
        spots_avail = row[2]

        (y, m, d) = date.split("-")
        begin = dt.date(int(y), int(m), int(d)).toordinal()

        for reservation in range(3):
            client = random.choice(clients)
            spots = random.randint(1, int(spots_avail/4))
            book_ord = dt.datetime.fromordinal(begin - random.randint(15, 80))
            date_of_book = "/".join((str(book_ord.year), str(book_ord.month), str(book_ord.day)))
            result = (dayid, client, spots, date_of_book)
            print("Book spots for the day " + str(result))
            c.apply_proc('GeneratorBookPlacesForDay', result)

        row = cursor.fetchone()

    conn.close()
    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:44,代码来源:generator.py

示例6: fill_gen_add_thresholds

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_add_thresholds():
    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()
    cursor.execute("select * from conferences")
    row = cursor.fetchone()

    c = Connector()
    cn = c.connect(secretpassword)

    while row:
        idconf = row[0]
        dayofconf = row[2]
        for threshold in range(3):
            res = gen_add_thresholds(idconf, threshold, dayofconf)
            c.apply_proc('AddPrice', res)
            print(res)
        row = cursor.fetchone()
    conn.close()

    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:23,代码来源:generator.py

示例7: fill_gen_add_workshop

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_add_workshop():

    connector = Connector()
    conn = connector.connect(secretpassword)

    workshop_types_id = []
    workshop_getter = conn.cursor()
    workshop_getter.execute("select WorkshopTypeID from WorkshopType")
    types_row = workshop_getter.fetchone()
    while types_row:
        workshop_types_id.append(types_row[0])
        types_row = workshop_getter.fetchone()

    days_id = []
    days_getter = conn.cursor()
    days_getter.execute("select DayID from DaysOfConf")
    days_row = days_getter.fetchone()
    while days_row:
        days_id.append(days_row[0])
        days_row = days_getter.fetchone()

    conn.close()

    print(workshop_types_id)
    print(days_id)

    c = Connector()
    cn = c.connect(secretpassword)

    for day in days_id:
        workshop = random.choice(workshop_types_id)
        start = random.choice(["14:00:00", "15:00:00", "16:00:00"])
        end = random.choice(["18:00:00", "19:00:00", "20:00:00"])
        spots = random.choice([5, 10, 15, 20])
        price = random.randint(2, 15) * 10
        result = (workshop, day, start, end, spots, price)
        print("Add Workshop " + str(result))
        c.apply_proc('AddWorkshop', result)

    cn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:42,代码来源:generator.py

示例8: fill_gen_assign_attendee

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
def fill_gen_assign_attendee():

    connector = Connector()
    conn = connector.connect(secretpassword)
    cursor = conn.cursor()

    individual_participation = []

    cursor.execute("select distinct Attendees.AttendeeID, Reservations.ReservationID "
                   "from Attendees "
                   "inner join Clients on Attendees.ClientID = Clients.ClientID "
                   "inner join Reservations on Reservations.ClientID = Clients.ClientID "
                   "inner join Individual on Individual.ClientID = Clients.ClientID")

    row = cursor.fetchone()

    while row:
        individual_participation.append((row[0], row[1]))
        row = cursor.fetchone()

    company_participation = []

    cursor.execute("select distinct Attendees.AttendeeID, Reservations.ReservationID "
                   "from Attendees "
                   "inner join Clients on Attendees.ClientID = Clients.ClientID "
                   "inner join Reservations on Reservations.ClientID = Clients.ClientID "
                   "inner join Company on Company.ClientID = Clients.ClientID")

    row = cursor.fetchone()

    while row:
        company_participation.append((row[0], row[1]))
        row = cursor.fetchone()

    # Two list of (AttendeeID, ReservationID) to apply

    # The following lines may cause declination of IDE control xD
    # print(individual_participation)
    # print(len(individual_participation))
    # print(company_participation)
    # print(len(company_participation))

    # Those insertions causes error -> try block
    filler = Connector()

    individual_size = len(individual_participation)
    filler.apply_proc_multi('AssignAttendee', individual_participation, individual_size)

    company_size = len(company_participation)
    filler.apply_proc_multi('AssignAttendee', company_participation, company_size)

    conn.close()
开发者ID:onegrx,项目名称:db-gen,代码行数:54,代码来源:generator.py

示例9: Modem

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
class Modem(object):
    """Class modem to control the node via TCP"""

    class Status:
        """Internal class where the status sens_ts are defined"""
        IDLE, BUSY2REQ, BUSY2DATA, BUSY2RECV, BUSY2REQ2DATA, KILL = range(6)

    class ErrorDict:
        """Internal class to map the error sens_ts to their error message"""
        NONE, SYNT_ERR, WRONG_SETTING, NOT_RESPONDING, FILE_NOT_FOUND, \
        TX_WHILE_RX, RX_WHILE_TX = range(7)
        error_dict = {
            NONE : 'none',
            SYNT_ERR : 'command syntax error',
            WRONG_SETTING : 'wrong setting, value not allowed',
            NOT_RESPONDING : 'device not responding, check the status',
            FILE_NOT_FOUND : 'file not found error',
            TX_WHILE_RX : 'you attempt to transmit while receiving, if \
                you really want, set the force flag to 1',
            RX_WHILE_TX : 'you attempt to receive while transmitting if \
                you really want set the force flag to 1'
         }

    def __init__(self, ip, port, automatic = True, control_buf_size = 32, data_buf_size = 128, \
        m_to = 0.01, socket_to = 0.005):
        """
        Constructor, initialize the modem and the connector. Connect the
        modem to the submerged node
        @param self pointer to the class object
        @param ip string cointaining the IP address of the TCP server
        @param port string with the port of the TCP server socket
        @param control_buf_size: int with the control buffer size, in bytes
        @param data_buf_size: int with the data buffer size, in bytes
        @param m_to: float value time out of the cycle, in [s]
        @param socket_to: time out of the socket checking operation, [s]
        """
        self.conn = Connector(ip, port, control_buf_size, data_buf_size, socket_to)
        self.conn.connect()
        self.m_to = m_to
        self.status = Modem.Status.IDLE
        self.node_status = 0
        self.automatic = automatic
        self.interpreter = Interpreter()
        self.mainPID = os.getpid()
        self.error_status = Modem.ErrorDict.NONE
        self.commands_queue = "".split(Interpreter.END_COMMAND)
        if automatic:
            thread.start_new_thread(self.run,())

    def run(self):
        """
        Run cycle, checks if data available
        @param self pointer to the class object
        """
        threadPID = os.getpid()
        index = 0
        while True:
            index += 1
            if ((index * self.m_to) > 1):
                #self.check4kill(threadPID)
                index = 1
            if(self.status == Modem.Status.IDLE or self.status == Modem.Status.BUSY2REQ):
                r, e = self.conn.dataAvailable()
                if(e):
                    break
                if(r):
                    rx = self.recvCommand()
                    if (len(rx) == 0):
                        break
            elif(self.status == Modem.Status.KILL):
                break
            sleep(self.m_to)
        self.close()
        print >>sys.stderr, 'Closing'

    def check4kill(self,threadPID = -1):
        """
        Check if the process has to be killed
        @param self pointer to the class object
        """
        #TODO: check in the kill log if my main or my thred PID are there.
        #      In case True, kill all. /var/log/check_status/check_kills.log
        # kill $TOPPID
        # /var/log/check_status/check_off.log
        off_log = "/var/log/check_status/check_off.log"
        kill_log = "/var/log/check_status/check_kills.log"
        try:
            f = open (off_log, "r")
            l = f.read(self.conn.data_buf_size)
            while (l or self.status != Modem.Status.KILL):
                if l == "poweroff":
                    self.status = Modem.Status.KILL
                l = f.read(self.conn.data_buf_size)
            f.close()
        except IOError:
            print off_log + " not found"
        try:
            f = open (kill_log, "r")
            l = f.read(self.conn.data_buf_size)
            while (l or self.status != Modem.Status.KILL):
#.........这里部分代码省略.........
开发者ID:marinetech,项目名称:Udoo,代码行数:103,代码来源:modem.py

示例10:

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import connect [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#   Copyright 2011 Peter Morton & Matthew Yeung
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#	   http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

from PyQt4 import QtGui
import numpy as np
import pygame
import typewriter
from setupeventfilters import setupEventFilters
from onfocusmanager import onFocusManager
from glviewer import Viewer
from connector import Connector
# Play with these constants to change the system response
SAMPLE_STRIDE = 2		  # Divide depth map resolution by this amount

KB_WIDTH_FAC = 1		 # Width of keyboard = Length * KB_WIDTH_FAC
KB_HEIGHT_FAC = 1	   # Height of keyboard = Length * KB_HEIGHT_FAC
开发者ID:morio,项目名称:KinectACI,代码行数:32,代码来源:kinectaci.py


注:本文中的connector.Connector.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。