def myregister(self): print("회원 가입.. ") db = DbConnect("192.168.0.68", "orcl", "scott", "tiger", "1521") resultList = db.execute("SELECT * FROM EMP") print(resultList) # 1. connection 객체 생성 connection = cx_Oracle.connect("scott", "tiger", "192.168.0.68:1521/orcl") print(connection) # 2. cursor 객체 cur = connection.cursor() # 3. 사용할 sql문 객체 sql = """ INSERT INTO member VALUES (:id, :pw, :name, 1) """ # 4. 실행 cur.execute(sql, id=self.le2Id.text(), pw=self.le2Pw.text(), name=self.le2Name.text()) connection.commit() # 6. 자원반납 connection.close() self.parent.hide()
def psqlEqServer(dbname, dbuser, pwd): """ loops through eq csv files and inserts rows into database. csv file must have date at the end as ddmm @param dbname - database name, e.g. 'PNM' @param dbuser - user for db, e.g. 'postgres' @param pwd - password for db """ db = DbConnect.psql(dbname, dbuser, pwd) for csvFile in os.listdir(os.getcwd()): if csvFile.endswith('.csv'): data = [] columns = loader(csvFile) date = csvFile.replace('.csv', '') date = date[len(date)-4:] polldate = '2016-' + date[2] + date[3] + '-' + date[0] + date[1] for i in range(len(columns['Mac'])): mac = columns['Mac'][i].upper() if len(mac) == 12: us = columns['US'][i] eqhex = columns['EqHex'][i] row = {"mac":mac, "us":us, "eqhex":eqhex, "polldate":polldate} data.append(row) else: pass db.insertBatchEq(data) print "succesful- " + csvFile
def prepareData(self): mongo_object, connection = DbConnect.Database.ConnectMongo( DbConnect.Database()) mongo_object = mongo_object["processedTags"] for i in mongo_object.find(): self.tag.append(i["tag"]) self.content.append(i["content"]) connection.close()
def insertServer(data, dbname, dbuser, pwd): """ connection to the database to push the geocoded set of data @param data - data to be pushed, created in loadServerData @param dbname - name of the database to push to @param dbuser - user of db """ db = DbConnect.psql(dbname, dbuser, pwd) db.insertBatchMac(data)
def runEngine(self): mongo_object, connection = DbConnect.Database.connectMongo( DbConnect.Database()) mongo_object = mongo_object['dataSources'] main_list = [] for x in mongo_object.find(): main_list.append(self.fetchFromUrl([x['tag'], x['url']])) connection.close() response = self.dataAdd(main_list) return response
def loaderSQL(dbname, dbuser, pwd, node, franchise): """ load latitude and longitude data from the SQL db @param dbname - name of database @param dbuser - corresponding user for database @param node - name of node to grab information from @param franchise - badger franchise of node @return db.getLatLon - list of row elements [lat,lon] """ db = DbConnect.psql(dbname, dbuser, pwd) return db.getLatLon(node, franchise)
def on_btnLogin_clicked(self, button, data=None): conn = DbConnect.user() username = self.entryUser.get_text() password = self.entryPass.get_text() role = conn.dbLogin(username,password) if role: self.logged_in = True self.dlg.hide() else: print "Username or password is incorrect!"
def __init__(self,config): ''' Constructor ''' self.dbConfig = config self.langs = ['java', 'python', 'cSharp', 'cPP', 'php', 'c', 'ruby', 'ruby_on_rails', 'javascript', 'jquery', 'asp_dot_net', 'objective_c','sql', 'xml', 'perl', 'cocoa', 'delphi', 'node_dot_js', 'scala', 'visual_cPP'] self.languages = ['java', 'python'] self.dbConnect =DbConnect(self.dbConfig) Session, self.engine = self.dbConnect.openConnection() self.session = Session()
class StackService(): ''' classdocs ''' def __init__(self,config): ''' Constructor ''' self.dbConfig = config self.langs = ['java', 'python', 'cSharp', 'cPP', 'php', 'c', 'ruby', 'ruby_on_rails', 'javascript', 'jquery', 'asp_dot_net', 'objective_c','sql', 'xml', 'perl', 'cocoa', 'delphi', 'node_dot_js', 'scala', 'visual_cPP'] self.languages = ['java', 'python'] self.dbConnect =DbConnect(self.dbConfig) Session, self.engine = self.dbConnect.openConnection() self.session = Session() def getCommonTagsAccrossLangs(self): commonTags = Set() for lang in self.languages: tags = self.getTagsOfLanguage(lang) print len(tags) commonTags = commonTags.intersection(tags) return commonTags def getTagsOfLanguage(self, lang): filterString = "Tag_Post_Map."+ lang returnSet = Set() i=0; window = 20000 j=i+window count = i keepLoading = True while keepLoading: keepLoading=False for row in self.session.query(TagQuestionAcceptedAnswerMap).filter(eval(filterString)==True)[i:j]: keepLoading=True returnSet.add(row) count +=1 i=j j=j+window print "done", count return returnSet
def dataAdd(self, list): mongo_object, connection = DbConnect.Database.connectMongo( DbConnect.Database()) mongo_object = mongo_object['data'] """list is the current fetched data. this is to check if the current fetched data already exists in the db. if it exists then, we will not store it. we will match current news title with all the news titles of the same day. """ if (mongo_object.count() == 0): # checks if it is empty or not. mongo_object.insert(list) print("found count=0, all news inserted") else: # does not allow duplicate news to be stored. for i1 in list: if (mongo_object.count({"tag": i1['tag']}) == 0): mongo_object.insert(i1) print("new tag news found, all news inserted") else: for j1 in mongo_object.find({ "$or": [{ "content.date_stamp": str(datetime.datetime.now().date()) }, { "content.date_stamp": str(datetime.datetime.now().date() - datetime.timedelta(days=1)) }, { "tag": i1['tag'] }], "tag": i1['tag'] }): for i2 in i1['content']: flag = True for j2 in j1['content']: if (i2['title'] == j2['title']): flag = False if (flag == True): print(i1['tag']) mongo_object.update({'tag': i1['tag']}, {'$push': { 'content': i2 }}) print('added news: ', i2['title']) connection.close() return 'data updated'
def objLoaderDb(node, date, pwd): start_time = time.time() objList = list() db = DbConnect.psql('PNM', 'postgres', pwd) eq = db.getEqData(node, date) rows = 0 for row in eq: rows += 1 try: #if rows == 1: print row[2] objList.append( EqObjects.EqAnalyser(row[0], row[1], row[2], row[3], row[4], row[5], (float(row[6]), float(row[7])))) except (ZeroDivisionError, ValueError, IndexError): pass #print("Invalid string, mac address: " + columns['Mac'][i] + " upstream: " + columns['US'][i]) print("--- %s seconds ---" % (time.time() - start_time)) print("objects loaded: " + str(len(objList)) + "/" + str(rows)) return objList
def infoExtract(self): print("Information Extraction start") """ Information architecture first 3 steps: 1. Sentence tokenization 2. Word tokenization 3. Pos tag for each word """ mongo_object, connection = DbConnect.Database.connectMongo(DbConnect.Database()) mongo_object = mongo_object["processedTags"] for i in self.dict: data=self.dict[i] # removed unwanted symbols filtered=func.filterSentences(func(),data) # split the files sentences =filtered.split("<br>") # removed stopwords stopwords=func.stopWords(func(),sentences) # find frequency of twoGrams words twoGramsFrequency = func.twoGramsFrequency(func(), stopwords) print(twoGramsFrequency[:50]) # find frequency of oneGram words oneGramsFrequency = func.oneGramsFrequency(func(), stopwords) # remove unwanted words cleanWords=func.unwantedWordsRemoval(func(),oneGramsFrequency[:70]) cleanWords=json.dumps(list(cleanWords)) print(cleanWords) if(mongo_object.find({"tag":i,"date_stamp":str(datetime.datetime.now().date())}).count()!=0): mongo_object.remove({"tag":i,"date_stamp": str(datetime.datetime.now().date())}) print("data already exists for today, removed") mongo_object.insert({"tag":i,"content":cleanWords,"date_stamp":str(datetime.datetime.now().date())}) print(str(i)+"complete")
def findTags(self): mongo_object, connection = DbConnect.Database.connectMongo(DbConnect.Database()) mongo_object = mongo_object["data"] tags=mongo_object.distinct("tag") print(tags) return tags,mongo_object,connection
def ShowCollection(self,collection): DbConnect.Database.showMongo(DbConnect.Database(),collection)
def SourcesAdd(self, source, tag): mongo_object, connection = DbConnect.Database.connectMongo(DbConnect.Database()) mongo_object = mongo_object['dataSources'] mongo_object.insert({"tag": tag, "url": source}) connection.close()
import DbConnect from flask import Flask,request,make_response import pymysql,json from xml.dom.minidom import parseString import CreateXML app = Flask(__name__) if __name__ == '__main__': con = pymysql.Connect(host='127.0.0.1', port=3306, db='android', user='******', passwd='demo12345', charset='utf8') dbConnect = DbConnect.DbConnect(con) #登录: @app.route('/login',methods=['POST']) def login(): args = request.json phone = args['phone'] password = args['password'] return dbConnect.transfor("login", phone, password) # 注册: @app.route('/register', methods=['POST']) def register(): args = request.json phone = args['phone'] password = args['password'] return dbConnect.transfor("register", phone, password) #更新: @app.route('/update', methods=['POST'])