示例#1
0
 def initialize(cls, **kwargs):
     Database.__connection_pool = pool.SimpleConnectionPool(1, 3, **kwargs)
示例#2
0
 def initialise(**kwargs):
     Database.__connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)
 def initialize(**kwargs):
     Database.__connection_pool = pool.SimpleConnectionPool(
         constants.MIN_INIT_CONN, constants.MAX_CONN_POOL, **kwargs)
 def initialise(cls, **kwargs):      # "**kwargs" => any named parameters
     Database.__connection_pool = pool.SimpleConnectionPool(1, 1, **kwargs)
示例#5
0
文件: nmpa.py 项目: levashovn/scroxy
import ipaddress
import concurrent.futures
import nmap
import requests
from psycopg2 import sql, IntegrityError, pool
from contextlib import contextmanager
import local_congfig
db = pool.SimpleConnectionPool(1,
                               10,
                               user=local_congfig.DB_USER,
                               password=local_congfig.DB_PASS,
                               database=local_congfig.DB_NAME,
                               host=local_congfig.DB_HOST)
print('Successfully connected to db...')


@contextmanager
def get_connection():
    con = db.getconn()
    try:
        yield con
    finally:
        db.putconn(con)


def create_table():
    with get_connection() as conn:

        cursor = conn.cursor()
        query = sql.SQL(
            "CREATE TABLE IF NOT EXISTS {} (curl VARCHAR (50) PRIMARY KEY, ip VARCHAR (50) NOT NULL, protocol VARCHAR (10) NOT NULL,port INT NOT NULL )"
示例#6
0
 def init(cls, **kwargs):
     cls.connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)
示例#7
0
 def initialise(**kwargs):
     Database.__connection_pool = pool.SimpleConnectionPool(1,
                                                            10,
                                                            **kwargs) # accept any number of named params
示例#8
0
    # check required environment variables are set
    #
    dbname, dbuser, tablename, google_api_key = os.environ.get(
        'DBNAME', None), os.environ.get('DBUSER', None), os.environ.get(
            'TABLE', None), os.environ.get('GOOGLE_API_KEY', None)
    if not all([dbname, dbuser, tablename, google_api_key]):
        logger.error(
            "one of the following required environment variables is not set: DBNAME={} DBUSER={} TABLE={} GOOGLE_API_KEY={}"
            .format(dbname, dbuser, tablename, google_api_key))
        sys.exit(1)
    logger.debug("DBNAME={} DBUSER={} TABLENAME={} GOOGLE_API_KEY={}".format(
        dbname, dbuser, tablename, google_api_key))

    # create pool with min number of connections of 1, max of 15
    dbpool = psycopg2_pool.SimpleConnectionPool(1,
                                                30,
                                                dbname=os.environ["DBNAME"],
                                                user=os.environ['DBUSER'])

    with get_connection() as conn:
        thread_pool = multiproc_pool.ThreadPool(processes=15)

        #
        # geocode tablename with an `address_of_record`
        #
        crs = conn.cursor()
        crs.execute(
            "SELECT pid, address_of_record, city, state, postal_code, ward FROM "
            + tablename +
            " WHERE address_of_record IS NOT NULL AND reported_address IS NULL AND needs_geocoding = 1 and is_geocoded = 0"
        )
        props1 = crs.fetchall()
示例#9
0
 def initialize(cls, minconn, maxconn, **kwargs):
     cls.__connection_pool = pool.SimpleConnectionPool(minconn, maxconn, **kwargs)
示例#10
0
 def initialise(**kwargs):  # **kwargs = any named parameters
     Database.__connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)
示例#11
0
import boto3
import os
import operator
from contextlib import contextmanager

from flask import Flask, request, json, jsonify
from psycopg2 import pool

from api.settings import HOST, PORT, DEBUG
from helpers.resizer import resize_and_upload

app = Flask(__name__)
db = pool.SimpleConnectionPool(
    1,
    10,
    host='',
    database='', user='',
    password='',
    port=5432)
s3 = boto3.client(
    's3',
    aws_access_key_id=os.getenv('AWS_ACCESS_KEY'),
    aws_secret_access_key=os.getenv('AWS_SECRET'),
    region_name='eu-west-1')
BUCKET = 'rekognition-adihack'
PREFIX = 'https://s3-eu-west-1.amazonaws.com/rekognition-adihack/'


def make_response(data):
    response = app.response_class(
            response=json.dumps(data),
示例#12
0
 def initialise(self, **kwargs):
     cp = pool.SimpleConnectionPool(1, 1, **kwargs)
示例#13
0
# coding: UTF-8
from bottle import route, run, template, request, redirect, static_file
from contextlib import contextmanager
from psycopg2 import pool, extras
import os

# 接続プール
conn_pool = pool.SimpleConnectionPool(minconn=1,
                                      maxconn=10,
                                      dsn=os.environ.get("DATABASE_URL"))

# BBS-ID
bbs_id = "1"


@route("/")
def index():
    with get_cursor() as cur:
        bbs = get_bbs(cur, bbs_id)
        thread_list = get_thread_list(cur, bbs_id)
    return template("index", title=bbs["title"], thread_list=thread_list)


@route("/add", method="POST")
def add():
    with get_cursor() as cur:
        add_thread(cur, bbs_id, request.forms.getunicode("txt_title"),
                   request.forms.getunicode("txt_author"))
    return redirect("/")

示例#14
0
 def make_pool(self, minconn=2, maxconn=5):
     """ create a connection pool """
     return pool.SimpleConnectionPool(minconn, maxconn, **self.db_config)
示例#15
0
文件: app.py 项目: maxthwell/locate
# -*- coding: utf-8 -*-

from flask import Flask, abort, request, jsonify,make_response
from flask_cors import *
from functools import wraps
import json
import redis
from psycopg2 import pool as pgpool
from importlib import import_module as dimport
app = Flask(__name__)
CORS(app, supports_credentials=True)

#添加redis与postgresql连接池
redis_pool=redis.ConnectionPool(host='127.0.0.1', port=6379,db=2)
pg_conn_pool = pgpool.SimpleConnectionPool(5,200,
		host = '127.0.0.1',port='15432',user='******',
		password='******',dbname='locate')

def resp(body):
	r = jsonify(body)
	r.headers['Access-Control-Allow-Origin'] = '*'
	return r 

@app.route('/<apiname>', methods=['POST'])
def post_opration(apiname):
	params=request.json
	print('params=>',params)
	red=redis.Redis(connection_pool=redis_pool)
	db=pg_conn_pool.getconn()
	cursor=db.cursor()
	func=getattr(dimport('api.%s'%apiname),'main')
示例#16
0
 def initialise(**kwargs):
     #database=dbname, host=lclHost, user=logged_in_user, port=postgres_port, password=pwd
     for key, value in kwargs.items():
         print("%s == %s" % (key, value))
     Database.__connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)
示例#17
0
 def set_connection(cls, **kwargs):
     cls.__connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)
示例#18
0
from psycopg2 import pool

connection_pool = pool.SimpleConnectionPool(1,
                                            1,
                                            database='learning',
                                            user='******',
                                            password='******',
                                            host='localhost')


class CursorFromConnectionFromPool:
    def __init__(self):
        self.connection = None
        self.cursor = None

    def __enter__(self):
        self.connection = connection_pool.getconn()
        self.cursor = self.connection.cursor()
        return self.cursor

    def __exit__(self, exception_type, exception_value, exception_traceback):
        if exception_value is not None:
            self.connection.rollback()
        else:
            self.cursor.close()
            self.connection.commit()
        connection_pool.putconn(self.connection)


示例#19
0
 def initialise(cls):
     cls.__connection_pool = pool.SimpleConnectionPool(
         dsn=os.environ["DATABASE_URL"], minconn=2, maxconn=10)
示例#20
0
 def create_PSQL_connection(self):
     import psycopg2.pool as pgpool
     if not getattr(self, '_DbConnection__pgsql_pool', None):
         self.__pgsql_pool = pgpool.SimpleConnectionPool(
             1, 5, **self.__configuration['details'])
     return self.__pgsql_pool.getconn()
示例#21
0
from functools import partial

import psycopg2
from psycopg2 import extensions
from psycopg2 import pool
extensions.register_type(psycopg2.extensions.UNICODE)

import helixtariff.conf.lock_order  #@UnusedImport IGNORE:W0611
import helixcore.db.wrapper as wrapper
from settings import DSN

cp = pool.SimpleConnectionPool(1,
                               10,
                               user=DSN['user'],
                               database=DSN['database'],
                               host=DSN['host'],
                               password=DSN['password'])
get_connection = cp.getconn
put_connection = cp.putconn

transaction = partial(wrapper.transaction, get_connection, put_connection)
示例#22
0
 def initialise_connection(cls, **kwargs):
     Database.my_connection = pool.SimpleConnectionPool(1, 10, **kwargs)
示例#23
0
 def initialise(**kwargs):
     Database.__connection_pool = pool.SimpleConnectionPool(
         1,  # this exsists outside of the connection from pool class
         10,
         **kwargs)
from psycopg2 import pool
import pandas as pd


####################################################################################################
#
#                                   Define the connection pool
#
####################################################################################################
# Parameters are as follows:
# * The number of connections to create at the time the connection pool is created
# * Depends on how many simultaneous connections to the database your program needs.
#   If there is a large amount of traffic to/from the database, you need more.
#   It will create more connections as they are needed.
simple_connection_pool = pool.SimpleConnectionPool(1, 1, database="postgres", user="******", password="******", host="localhost")


####################################################################################################
#
#                       Define a class to work with the connection pool
#
####################################################################################################
class ConnectionPoolHandler:

    def __init__(self):
        self.connection = None
        self.cursor = None

    def __enter__(self):
        self.connection = simple_connection_pool.getconn()
示例#25
0
 def initialise(cls, **kwargs):
     cls.__connection_pool = pool.SimpleConnectionPool(
         1,
         10,
         **kwargs
     )
示例#26
0
 def init(**kwargs):
     DbConnection.connectPool=pool.SimpleConnectionPool(1,20,**kwargs)
     if DbConnection.connectPool:
         print('Postgres veritabanı bağlantısı başarılı.')
            "download-data",
            "clean-dates",
        ],
        required=True,
        type=str,
    )

    args = parser.parse_args()

    MIN_CONNECTIONS = 1
    MAX_CONNECTIONS = 3

    CONNECTION_POOL = pool.SimpleConnectionPool(
        MIN_CONNECTIONS,
        MAX_CONNECTIONS,
        host=args.db_host,
        user=args.db_user,
        password=args.db_pass,
        port=args.db_port,
    )

    CSV_FILES = [
        # genres, budget, revenue, imdbid
        "movies_metadata.csv",
        # userid, movieid, ratings
        "ratings.csv",
        # *
        "links.csv",
    ]
    if args.command == "load-data":
        for csv_file in CSV_FILES:
            load_csv(csv_file)
示例#28
0
 def initialise(cls, **kwargs):
     # Database connection pool constraints
     Database.__connection_pool = pool.SimpleConnectionPool(1, 10, **kwargs)