def getStudents(): dao = Dao() allstud = dao.getStudents() students = [] for s in allstud: students.append(Model(s)) return students
def ex1(): # Singleton instance dao = d.Dao() print("\n( Basic data )\n") pcs = dao.pc_list() for pc in pcs: print("Model : {}, Speed : {}, Ram : {}, HD : {}, CD : {}, Price : {}" .format(pc.model, pc.speed, pc.ram, pc.hd, pc.cd, pc.price)) print("\n - Insert a data\n") dao.pc_insert(9999, 999, 99, 9.9, "9x", 9999) print("\n( After inserting data )\n") pcs = dao.pc_list() for pc in pcs: print("Model : {}, Speed : {}, Ram : {}, HD : {}, CD : {}, Price : {}" .format(pc.model, pc.speed, pc.ram, pc.hd, pc.cd, pc.price)) print("\n - Delete the data\n") dao.pc_delete("9999") print("\n( After deleting data )\n") pcs = dao.pc_list() for pc in pcs: print("Model : {}, Speed : {}, Ram : {}, HD : {}, CD : {}, Price : {}" .format(pc.model, pc.speed, pc.ram, pc.hd, pc.cd, pc.price))
def getProducts(): dao = Dao() allprod = dao.getProducts() products = [] for s in allprod: products.append(Model(s)) return products
def purchase(product_Id): dao = Dao() item = dao.get(product_Id); if not item: return None if item["inventory_count"] <= 0: return None item["inventory_count"] = item["inventory_count"] -1 purchase=dao.update(product_Id, productInfo) return purchase
def read_file(filename): dao = Dao.Dao() dao.connect() col_name = '' value = '' names = '' values = '' with open(filename, 'r') as file_reader: lines = file_reader.readlines() for i in lines[2:-1]: i = i.replace("'", "''") if i == '\n': pass if i == "ER\n": # ER标志一篇论文信息结束 names += col_name if len(value.split(';')) == 2: value = value.replace(';', '') values += value + "'" sql = 'insert into RawMedicine2 ' + " ( " + names + " ) " + \ "values " + " ( " + values.replace(';;', ';') + " ); " print(sql) dao.insert(sql) col_name = '' names = '' values = '' else: temp = i.split(' ') if temp[0] == "MA" or temp[0] == "D2" or temp[0] == "BA" or temp[0] == "BF"\ or temp[0] == "GP": continue if not temp[0] == '' and not temp[0] == '\n' and not temp[0] == '\r': if not col_name == '': names += col_name + "," if len(value.split(';')) == 2: value = value.replace(';', '') values += value + "'," col_name = temp[0] col_name = col_name.replace('IS', 'IMPIS') value = "'" value += i.replace(col_name, '').replace('\n', ';') else: value += i.replace('\n', ';')
def create_table(): dao = Dao.Dao() dao.connect() sql = 'CREATE TABLE [dbo].[RawMedicine2](' \ '[paperid][numeric](18, 0) IDENTITY(1, 1)NOT NULL, [PT][nvarchar](max)NULL,[AU][nvarchar](max)NULL,' \ '[AF][nvarchar](max)NULL, [TI][nvarchar](max)NULL, [SO][nvarchar](max)NULL, [LA][nvarchar](max)NULL,' \ '[DT][nvarchar](max)NULL, [DE][nvarchar](max)NULL,[ID][nvarchar](max)NULL, [AB][nvarchar](max)NULL,' \ '[C1][nvarchar](max)NULL,[RP][nvarchar](max)NULL,[EM][nvarchar](max)NULL, [FU][nvarchar](max)NULL,' \ '[FX][nvarchar](max)NULL,[CR][nvarchar](max)NULL,[NR][nvarchar](max)NULL, [TC][nvarchar](max)NULL,' \ '[Z9][nvarchar](max)NULL,[U1][nvarchar](max)NULL,[U2][nvarchar](max)NULL, [PU][nvarchar](max)NULL,' \ '[PI][nvarchar](max)NULL, [PA][nvarchar](max)NULL,[SN][nvarchar](max)NULL, [J9][nvarchar](max)NULL,' \ '[JI][nvarchar](max)NULL, [PD][nvarchar](max)NULL,[PY][nvarchar](max)NULL, [VL][nvarchar](max)NULL,' \ '[AR][nvarchar](max)NULL, [DI][nvarchar](max)NULL,[PG][nvarchar](max)NULL, [WC][nvarchar](max)NULL,' \ '[EI][nvarchar](max)NULL,[IMPIS][nvarchar](max)NULL,[BP][nvarchar](max)NULL,[OI][nvarchar](max)NULL,' \ '[EP][nvarchar](max)NULL,[RI][nvarchar](max)NULL,[CT][nvarchar](max)NULL,[CY][nvarchar](max)NULL,' \ '[CL][nvarchar](max)NULL,[SP][nvarchar](max)NULL,[BE][nvarchar](max)NULL,[SE][nvarchar](max)NULL,' \ '[BN][nvarchar](max)NULL,[SU][nvarchar](max)NULL,[SI][nvarchar](max)NULL, [PN][nvarchar](max)NULL,' \ '[HO][nvarchar](max)NULL, [CA][nvarchar](max)NULL,' \ '[SC][nvarchar](max)NULL, [GA][nvarchar](max)NULL,[UT][nvarchar](max)NULL, [PM][nvarchar](max)NULL,'\ '[OA][nvarchar](max)NULL,[DA][nvarchar](max)NULL' \ ')' dao.create(sql) dao.close()
def deleteAll(): dao=Dao() dao.deleteAll() return
def addProduct(productInfo): dao = Dao() new= dao.addProduct(productInfo) if not new: return None return Model(new)
def get_by_id(product_Id): dao = Dao() product = dao.get_by_id(product_Id) if not product: return None return Model(product)
def update(student_Id, studentInfo): dao = Dao() updated = dao.update(student_Id, studentInfo) if not updated: return None return Model(updated)
#-*- coding:utf-8 -*- #读取d2017.bin 用于对创新度的计算,将数据存入数据库中。 #需要三个关键字 ENTRY(入口词)、MN(树形路径)、AN(注释) #ENTRY每个都有、MN(XXX.XXX.XXX)可能有几个、AN有些没有 import Dao dao = Dao.Dao() dao.connect() #col_name = '' MH_value = '' MN_value = '' ENTRY_value = '' AN_value ='' #names='' values='' count = 0 wrong = 0 with open("d2017.bin", "r") as readMesh: for line in readMesh: line = line.strip() if line == '': # 到了结尾 # if AN_value == '': # AN_value = 'null' values = "'" + MH_value + "','" + ENTRY_value + "','" + MN_value + "','" + AN_value +"'" sql = 'insert MeshStructure ' + " (MH , EN , MN , AN) " + \ "values " + " ( " + values + " ); " try: dao.insert(sql) count += 1
select = b.find('select') if select != None: options = select.findAll('option') if len(options) > 0: others = map(lambda x: x.get('value'), options) resp['links'].extend(others) # Look for other pages with links to listings days = b.findAll('a', {'class': 'days_whch'}) resp['links'].extend(map(lambda day: day.get('href'), days)) # Look for properties pages properties = b.findAll('td', {'class': 'addr_pcct'}) for prop in properties: link = prop.find('a').get('href') resp['links'].append(link) return resp ################################################ # Instantiate Crawler and execute ################################################ dao = Dao.Dao(access_key, secret_key, bucket_name) crawler = Crawler.Crawler(dao, expiration_rules, parse_detail_page, process_content) #rootpage = 'http://www.everyhome.com/Homes-For-Sale-By-Listing-Date/Mercer-County-New-Jersey' def lambda_handler(event, context): crawler.process_queue(event['queue'], verbose=True)
def get_by_id(student_Id): dao = Dao() student = dao.get_by_id(student_Id) if not student: return None return Model(student)
def delete(student_Id): dao = Dao() deleted=dao.delete(student_Id) return deleted
def __init__(self): self.dao = Dao()
# coding=utf-8 from Dao import * dao = Dao() conn = dao.getConn() cur = conn.cursor() f = open('WORD1.csv') for line in f.readlines(): word, english, inter, book, id = str(line).split(',') english = str(english).strip('"') inter = str(inter).strip('"') sql = 'insert into words value(%s,%s,%s,%s,%s)' param = (word, english, inter, book, id) cur.execute(sql, param) f.close()
def addStudent(studentInfo): dao = Dao() new= dao.addStudent(studentInfo) if not new: return None return Model(new)