def __init__(self): self.db_client = db() if not self.db_client: log.critical("DATABASE inititialization failure") if self.db_client.open_db(os.path.join(ROOT_DIR,"db","db.db")) == 0: log.critical("DATABASE opening failure") return
def get_user_info(self,host,port,mysql_host,mysql_port,session): """select user_name from mysql instance""" if self.mysql_user: _kwargs = {'host':mysql_host,'port':mysql_port,'user':self.mysql_user,'passwd':self.mysql_passwd} dd = db(**_kwargs) user_name,db_name = dd.get(host,port) if db_name in ('null' , 'Null') or db_name is None: db_name = '' if user_name: self.all_session_users[session] = {'status':True,'user':user_name,'pre':False,'db':db_name,'date':time.time()} dd.close() return user_name else: return ''
def main(): print("Pense em um animal, iremos tentar acertar!") animal = animalHelper.animalHelper().createAnimal() data_base = db.db() allAnimals = data_base.executeQuery("select * from animais") listAnimalCharacteristics = [] listAnimalNames = [] for ani in allAnimals: listAnimalCharacteristics += [ani[1:len(ani) - 1]] listAnimalNames += [ani[0]] nbrs = NearestNeighbors( n_neighbors=1, algorithm='ball_tree').fit(listAnimalCharacteristics) distance, indice = nbrs.kneighbors(np.array([animal])) print("O animal que você pensou foi " + listAnimalNames[int(indice)])
def init(self): log.info("Local service init") self.db_client = db() if not self.db_client: log.critical("DATABASE initialization failure") exit(1) if self.db_client.open_db(os.path.join(ROOT_DIR, "db", "db.db")) == 0: log.critical("DATABASE opening failure") exit(1) self.conf = self.db_client.get_config() if not self.conf: log.critical("CONFIGURATION initialization failure") exit(1) log.debug("Initialization OK") self.is_initialized = True return
def init(self): log.info("Local service init") self.db_client = db() if not self.db_client: log.critical("DATABASE initialization failure") exit(1) if self.db_client.open_db(os.path.join(ROOT_DIR,"db","db.db")) == 0: log.critical("DATABASE opening failure") exit(1) self.conf = self.db_client.get_config() if not self.conf: log.critical("CONFIGURATION initialization failure") exit(1) log.debug("Initialization OK") self.is_initialized = True return
def run(self): self.db_client = db() if not self.db_client: log.critical("DATABASE initialization failure") exit(1) if self.db_client.open_db(os.path.join(ROOT_DIR,"db","db.db")) == 0: log.critical("DATABASE opening failure") exit(1) log.info("New connection from "+self.ip+":"+str(self.port)) while(True): try: command = self.s.recv(1) except Exception, e: log.error("Network receive command error") log.debug("Exception %s" % e) self.must_stop = True self.stop() return if len(command) == 0: command = 0xFF else: command = ord(command) if command == 0x01: self.new_task() elif command == 0x02: self.file_receive() elif command == 0x03: self.meta_receive() elif command == 0x0F: log.info("Client has finished") self.must_stop = True elif command == 0xFF: log.warning("Remote connection closed") self.must_stop = True else: log.error("Invalid command received: "+hex(command)) self.must_stop = True if self.must_stop == True: self.stop() return
def run(self): self.db_client = db() if not self.db_client: log.critical("DATABASE initialization failure") exit(1) if self.db_client.open_db(os.path.join(ROOT_DIR, "db", "db.db")) == 0: log.critical("DATABASE opening failure") exit(1) log.info("New connection from " + self.ip + ":" + str(self.port)) while (True): try: command = self.s.recv(1) except Exception, e: log.error("Network receive command error") log.debug("Exception %s" % e) self.must_stop = True self.stop() return if len(command) == 0: command = 0xFF else: command = ord(command) if command == 0x01: self.new_task() elif command == 0x02: self.file_receive() elif command == 0x03: self.meta_receive() elif command == 0x0F: log.info("Client has finished") self.must_stop = True elif command == 0xFF: log.warning("Remote connection closed") self.must_stop = True else: log.error("Invalid command received: " + hex(command)) self.must_stop = True if self.must_stop == True: self.stop() return
def compare(self): dbHandle = db.db() target = "{}/contents/{}".format(self.target_api, self.target_dir) updatePOCS = [] try: r = requests.get(target, verify=False) pocs = json.loads(r.text) print("共{}条poc".format(len(pocs))) for poc in pocs: if not dbHandle.get(poc): dbHandle.insert(poc) updatePOCS.append(poc) if updatePOCS: self.sendEmail(updatePOCS) dbHandle.commit() except KeyError: traceback.print_exc() except: traceback.print_exc()
def init(self): log.info("Remote service init") db_client = db() if not db_client: log.critical("DATABASE initialization failure") exit(1) if db_client.open_db(os.path.join(ROOT_DIR,"db","db.db")) == 0: log.critical("DATABASE opening failure") exit(1) self.remote_sources = db_client.get_active_remote_sources() if len(self.remote_sources) == 0: log.critical("No available remote sources") exit(1) db_client.close() log.debug("Initialization OK") #self.hostname = socket.gethostname() self.hostname = "0.0.0.0" self.port = 6666 self.is_initialized = True return
def init(self): log.info("Remote service init") db_client = db() if not db_client: log.critical("DATABASE initialization failure") exit(1) if db_client.open_db(os.path.join(ROOT_DIR, "db", "db.db")) == 0: log.critical("DATABASE opening failure") exit(1) self.remote_sources = db_client.get_active_remote_sources() if len(self.remote_sources) == 0: log.critical("No available remote sources") exit(1) db_client.close() log.debug("Initialization OK") #self.hostname = socket.gethostname() self.hostname = "0.0.0.0" self.port = 6666 self.is_initialized = True return
def test_getConnection(self): conn = db.db() self.assertTrue(conn.getConnection())
#Monitoria que valida se os animais mamiferos estão certos from lib import db data_base = db.db() consulta = data_base.executeQuery( "select name, type from animais where milk = 1") def vefiricaMamiferos(consulta): mensagem = "" num = 0 for animal in consulta: if (animal[1] != 1): mensagem += "O animal " + animal[0] + " não é mamifero. " num = 2 return mensagem, num msg, num = vefiricaMamiferos(consulta) if (num == 0): mensagem = "OK - Os dados dos mamíferos estão corretos" else: mensagem = "CRITICAL - " + msg print(mensagem)
from flask import Flask, request, abort, jsonify from flask.templating import render_template from lib.db import db import sqlalchemy as sa from lib.People import Person import json app = Flask(__name__) sqlite_engine = sa.create_engine('sqlite:///db/advanced_flask.db') db_object = db(sqlite_engine) @app.route('/', methods=['GET']) def index(): return render_template('index.html') @app.route('/people', methods=['GET']) def people(): people = db_object.get_people() return render_template('people.html', people=people) @app.route('/new/person', methods=['GET']) def new_person_view(): return render_template('person_add.html') @app.route('/new/person', methods=['POST']) def new_person():
__author__="kayapo" __date__ ="$2011.02.14. 12:22:35$" import cgi import json import time import re from lib.log import log from lib.db import db from lib.setup import setup from lib.JSONify import JSONify SET = setup() dbObj = db(SET.getMySQLhost(), SET.getMySQLuser(), SET.getMySQLpassword(), SET.getMySQLdatabase()) dbConn = dbObj.connector() def getTags(): tags = list() unreliableTags = dbObj.runQuery(dbConn, "SELECT tag FROM %s GROUP BY tag;" % SET.getMySQLtable()) for tag in unreliableTags: tags.append( {"tag":cgi.escape(tag["tag"], 1)} ) if SET.getLogLevel() >= 3: L = log(0, 0, "logwalker.getTags") L.logger(str(tags)) return tags def getHosts():
'FeaturedCommentsCount']) + "', PaidType = '" + str(tmp_list['PaidType']) + "', LikeNum = '" + str(tmp_list['LikesCount']) + "', NotebookId = '" + str(tmp_list['NotebookId']) + "', ViewsCount = '" + str(tmp_list['ViewsCount']) + "', LastUpdatedAt = '" + str(tmp_list[ 'LastUpdatedAt']) + "', FirstSharedAt = '" + str(tmp_list['FirstSharedAt']) + "' where ID = " + str(article['ID'])) sql = "update jianshu_article_list set Status = '%s' where ArticleID = '%s'" % ( status, article['ArticleID']) db.db_reconnect() db.query(sql) sleep(1) def getArticleList(db, page): sql = "select ID, UID, ArticleID, Title from jianshu_article_list where Status in ('NEW', 'RECENT_UPDATE') order by ID desc limit " + str( page) + ", 1000;" return db.get_rows(sql) for page in range(1000): article_list = getArticleList(db(), page) if len(article_list) < 1: break for article in article_list: url = base_url + 'p/' + article['ArticleID'] spider(url, db(), article) browser.quit() print('endtime:' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
def main(): tup = csv2Tuple("C:\\Workshop Python\\AnimalFinder\\docs\\zoo.data") data_base = db.db() data_base.createAnimalsTable() data_base.insertData(tup)
else: pass # print(sql.encode('utf-8')) sleep(1) error_num = 0 else: if error_num > 5: return False error_num = error_num + 1 return True urls = [] page = 1 url = 'https://www.jianshu.com/recommendations/users?page={}' while page <= 200: print('-------------------- page --------------------') print('-------------------- ' + str(page) + ' --------------------') print('-------------------- page --------------------') page_url = url.format(page) flag = spider(page_url, db()) if flag: pass else: break page = page + 1 browser.quit() print('endtime:' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
import lib.api as api import lib.functions as f import lib.lookML as l import configparser as ConfigParser config = ConfigParser.RawConfigParser(allow_no_value=True) config.read('settings/settings.ini') try: import lib.db as db #Create a single db instance, accessed globally to save resources DB = db.db() l.DB_FIELD_DELIMITER_START = DB.literalDelimeterStart l.DB_FIELD_DELIMITER_END = DB.literalDelimeterEnd except: logging.info( 'Failed to import or connect to the DB, operating in offline mode. Obtaining delimiter from config file' ) class db: literalDelimeterStart = config.get('db', 'delimeter_start') literalDelimeterEnd = config.get('db', 'delimeter_end') DB = db() class viewFactory: ''' view factory has 2 primary modes: 1) DB Driven A) Prefetch -- This is fastest when you are generating many tables B) Query 1 Table -- This is simple when you are generating only a single table 2) Looker API Driven
else: pass # print(sql.encode('utf-8')) sleep(1) last_user = user else: return False return True def getUserList(db): sql = "select UserId, NickName from jianshu_user order by ID desc;" return db.get_rows(sql) user_list = getUserList(db()) type_list = ['following', 'followers'] for user in user_list: for type_ in type_list: url = base_url + 'users/' + user['UserId'] + '/' + type_ + '?page={}' page = 1 db_ = db() while page <= 99999: page_url = url.format(page) print('-------------------- page --------------------') print('-------------------- user: '******'UserId'] + ' page: ' + str(page) + ' url: ' + page_url + ' --------------------') print('-------------------- page --------------------') flag = spider(page_url, db_, user) if flag: pass
def before_request(): g.db = connect_db() g.mydb = db.db ()