def traverseDate(startDate): now = date.today() delta = timedelta(days=1) name = raw_input("db username:"******"db password:") try: db = dbHelper(name, pw) except Exception, e: raise e
def autocomplete(): search = request.args.get('input') app.logger.debug(search) # Helper utilities to filter the BD based on what's passed into the search db = dbHelper() db.initConnection() products = db.queryDB(filter=search) products = db.formatData(products) return jsonify(json_list=products)
def main(): mdb = dbHelper("stock") for line in open("stock_code.txt"): stock = line.strip("\n").split(" ") sql="insert ignore into stock(`type`,`stock_id`,`stock_name`) values(\"%s\",\"%s\",\"%s\")" % (stock[0],stock[1],stock[2]) if stock[0] == "cyb": print stock print sql mdb.insert(sql)
smObj = sm.SQLModule( sqlObj['selectColumns'], sqlObj['aggregationColumns'], sqlObj['aggregationCommandToColumnMap'], sqlObj['datasetName'], sqlObj['whereColumnNames'], sqlObj['whereColumnNameToValueMap'], sqlObj['whereColumnNameToConditionMap'], sqlObj['groupbyColumns'], sqlObj['orderbyColumns'], sqlObj['orderbyColumnToAscDescMap']) sqlCommand = smObj.formSQLCommand(dbHelper) print('sqlCommand:', sqlCommand) return sqlCommand if __name__ == "__main__": dfName = 'data' df = readDf("data\cand_summary.txt", delimiter="|") # df = readDf("data\dist_pop.txt", delimiter = "|") dbHelper = dbHelper.dbHelper(df) columns = dbHelper.getColumnNames() ob = SimilarityModule(columns, dfName) # inputString = 'give me the total receipts by affiliation' # inputString = 'give me the median of receipts by affiliation' # inputString = 'give me the average of receipts by affiliation' # inputString = 'give me the maximum of receipts by affiliation' # inputString = 'give me the minimum of receipts by year' # inputString = 'find candidates having candidate id H0AK00055' # inputString = 'find candidates in election year 2016' # inputString = 'give me the total receipts in election year 2016 by affiliation' # doesnt work because receipts also has a value of 2016 # inputString = 'give me the number of candidates in election year 2016 by affiliation' # inputString = 'find number of candidates and total receipts by affiliation' # inputString = 'find number of candidates and total receipts by affiliation and year' inputString = 'find the total population by state' sqlCommand = ob.SQLSuggestion(inputString, dbHelper)
# -*- coding:utf-8 -*- import os import sys import redis from dbHelper import dbHelper import urllib2 import time from multiprocessing import Pool reload(sys) sys.setdefaultencoding('utf8') redish = redis.Redis(host="localhost", port="6379", db=0) mdb = dbHelper("stock") def main(): targets = { "ha": "sh", "hb": "sh", "sa": "sz", "sb": "sz", "zs": "sz", "jj": "sh", "etf": "sh" } stk = mdb.select("select * from stock") url = "http://qt.gtimg.cn/" for stock in stk: if stock["type"] in targets.keys(): stock_id = str(stock["stock_id"])
import dbHelper import logHelper import time import unicodeHelper import dateHelper import DataStorer db = dbHelper.dbHelper() isRecording = False if logHelper.getCurrentLog(): isRecording = True def startRecording(name): nameExists = True if db.isValidFilename(name): date = dateHelper.getCurrentDate() currentTime = int(time.time()) if logHelper.nameIsUnique(name, date): logHelper.createNewLog(name, date, currentTime) db.createNewDb(name + date) DataStorer.StoreData() isRecording = True nameExists = false return nameExists def deleteRecording(name): if name == "current":
from dbHelper import dbHelper a = dbHelper('grad.icmc.usp.br', 15215, 'orcl', 'G9763193', '9763193') # print(a.insertIntoEndereco([1011, 'aaa', 'aaa', 'SP', 121, '1860-000'])) # print(a.insertIntoEndereco([101, 'Rua Marciano Magalhaes', 'Petropolis', 'RJ', 1065, '25630-021'])) # a.insert('BEBIDAS_DRINK', ['DRINK', 'BEBIDA', 'VOLUME', 'QUANTIDADE'], ['Jack n Coke', 'Coca-Cola', 2000, 1]) # a.delete('BEBIDAS_DRINK', ['DRINK', 'BEBIDA'], ['Jack n Coke', 'Coca-Cola']) # a.update('BEBIDAS_DRINK', ['DRINK', 'BEBIDA'], ['Jack n Coke', 'Coca-Cola'], ['DRINK', 'VOLUME', 'BEBIDA'], ['Caipirinha', 1000, 'Rum']) # a.getAllAniversarios() # a.getGarconsFesta('165.928.307-86','23/09/2018') # a.getBarracasAniversario('165.928.307-86','23/09/2018') # a.getEnderecoFesta('165.928.307-86','23/09/2018') # a.getGarconsLivres('23/09/2018') # a.getOperadoresLivres('23/09/2018') # a.getGerentesLivres('23/09/2018') # a.getAllCasasFesta() # a.getAllGerentes() # a.getAllOperadores() # a.getAllGarcons() # a.getBebidasInInterval(0,1000) # a.getAllFornecedores() # a.getAllClientes()
import dbHelper import logHelper import time import unicodeHelper import dateHelper import DataStorer db = dbHelper.dbHelper() isRecording = False if logHelper.getCurrentLog(): isRecording = True def startRecording(name): nameExists = True if db.isValidFilename(name): date = dateHelper.getCurrentDate() currentTime = int(time.time()) if logHelper.nameIsUnique(name,date): logHelper.createNewLog(name, date, currentTime) db.createNewDb(name+date) DataStorer.StoreData() isRecording = True nameExists = false return nameExists def deleteRecording(name): if name == "current": logDetails = logHelper.getCurrentLog() isRecording = False
# -*- coding: utf-8 -*- import cherrypy import json from dbHelper import dbHelper db = dbHelper() print "connect SQL server!" category_mapping = { u"热点": "hot", u"财经": "finance", u"军事": "military", u"社会": "society", u"科技": "tech", u"体育": "sports", u"教育": "education", u"娱乐": "entertainment", u"法律": "law", u"旅游": "travel", u"国内": "china", u"国际": "internation", u"港澳台": "gangao", u"其他": "other" } category = [ u"热点", u"财经", u"军事", u"社会", u"科技", u"体育", u"教育", u"娱乐", u"法律", u"旅游", u"国内", u"国际", u"港澳台", u"其他" ] source = [ u"腾讯网", u"网易", u"中国新闻网", u"凤凰网", u"人民网", u"新华网", u"新浪网"
groupbyColumns = [i for i in self.groupbyColumns if i] if( groupbyColumns ): groupByPhrase = ' group by ' + ', '.join( groupbyColumns ) print( 'groupByPhrase: ', groupByPhrase ) return groupByPhrase def constructOrderByPhrase( self ): orderByPhrase = '' if( self.orderbyColumns ): orderByPhrase = 'order by ' + ', '.join( self.orderbyColumns ) + ' asc' # To do: enhance with asc desc map, etc return orderByPhrase if __name__ == "__main__": df = readDf("data\cand_summary.txt", delimiter = "|") dbHelper = dbh.dbHelper( df ) print( '\nSize: ', dbHelper.getDfSize() ) print( '\nColumns: ', dbHelper.getColumnNames() ) print( '\nCol Types: ', dbHelper.getColumnTypes() ) sqlObj = { 'selectColumns': ['other_pol_cmte_contrib', 'cand_id'], 'aggregationColumns': [], 'aggregationCommandToColumnMap': {}, 'datasetName': 'data', 'whereColumnNames': {'other_pol_cmte_contrib', 'cand_id'}, 'whereColumnNameToValueMap': {'other_pol_cmte_contrib': [], 'cand_id': ['h0ak00055']}, 'whereColumnNameToConditionMap': {'other_pol_cmte_contrib': [], 'cand_id': ['=']}, 'groupbyColumns': [], 'orderbyColumns': [], 'orderbyColumnToAscDescMap': {}}