def delete(id): #GET the correct items based on item id if request.method == 'GET': conn = db.conn_db() get = conn.execute('SELECT * FROM list WHERE id = ?', (id, )).fetchone() return render_template('delete.html', get=get) #POST data from database #By POSTing we will be editing the database by deleting the id based on the user's choice elif request.method == 'POST': #Connect to database conn = db.conn_db() error = None if not id: error = 'Item does no exist.' #If no error then execute delete id list if error is None: conn.execute('DELETE from list WHERE id = ?', (id, )) conn.commit() posts = conn.execute('SELECT * FROM list').fetchall() return render_template('home.html', posts=posts) #If delete is not successful else: post = conn.execute('SELECT * FROM list WHERE id = ?', (id, )).fetchone() flash(error) return render_template('delete.html', post=post)
def is_word_exist(query_word): conn = conn_db() cur = conn.cursor() row_num = cur.execute('SELECT * FROM word WHERE word = "%s"' %(query_word)) cur.close() conn.close() return row_num !=0
def is_word_exist(query_word): conn = conn_db() cur = conn.cursor() row_num = cur.execute('SELECT * FROM word WHERE word = "%s"' % (query_word)) cur.close() conn.close() return row_num != 0
def store_talks(talks): cols = Talk._fields placeholders = ', '.join(['?'] * len(cols)) with conn_db() as c: c.executemany( 'INSERT INTO {} ({}) VALUES ({})'.format(TABLE, ', '.join(cols), placeholders), talks)
def create_table(): cols = ', '.join(Talk._fields) idx = 'id INTEGER PRIMARY KEY AUTOINCREMENT,' with conn_db() as c: try: c.execute('CREATE TABLE {} ({} {})'.format(TABLE, idx, cols)) except sqlite3.OperationalError: print('Table already exists')
def write_word_entries(query_word, entry, word_found): conn = conn_db() cur = conn.cursor() word = query_word if not word_found: ref_word = entry[0][0] hashchar = hashlib.md5(query_word).hexdigest() try: cur.execute("INSERT INTO word (hash, word, ref_word) VALUES (%s,%s,%s)", (hashchar, word, ref_word) ) except MySQLdb.IntegrityError, e: #print "Dup %s" % (query_word) pass except MySQLdb.Error, e: print "MySQL Error: %s" % str(e) raise
def write_word_entries(query_word, entry, word_found): conn = conn_db() cur = conn.cursor() word = query_word if not word_found: ref_word = entry[0][0] hashchar = hashlib.md5(query_word).hexdigest() try: cur.execute( "INSERT INTO word (hash, word, ref_word) VALUES (%s,%s,%s)", (hashchar, word, ref_word)) except MySQLdb.IntegrityError, e: #print "Dup %s" % (query_word) pass except MySQLdb.Error, e: print "MySQL Error: %s" % str(e) raise
def merge_company(company_key): match = aggregator_util.match_company(source, company_key) if match is None: return print 'merge .....' conn = db.conn_db() try: aggregator_util.insert_company(source, company_key, conn) aggregator_util.insert_member(source, company_key, conn) aggregator_util.insert_funding(source, company_key, conn) aggregator_util.insert_footprint(source, company_key, conn) aggregator_util.insert_job(source, company_key, conn) conn.commit() except Exception, e: logger.info(e)
def add(): #POST= want to POST new item made by user to the database if request.method == 'POST': item_name = request.form['item_name'] amount = request.form['amount'] category = request.form['category'] conn = db.conn_db() error = None #If user has not completed all fields, flash an error if not item_name or not amount or not category: error = 'You have incomplete fields.' #If no error then insert new list item into the database if error is None: conn.execute( 'INSERT INTO list (item_name, amount, category) VALUES (?, ?, ?)', (item_name, amount, category)) conn.commit() flash('Item added successfully!') return render_template('add.html') flash(error) return render_template('add.html')
response = urllib.request.urlopen(url) navigator=BeautifulSoup(response, 'html.parser') table=navigator.find('table', class_='list_netizen') print(table) list_records=[] for i,r in enumerate(table.find_all('tr')): # i는 인덱스 r은 tr 개체 for j,c in enumerate(r.find_all('td')): # j는 인덱스값 c는 개체 if j==0: record=int(c.text.strip()) elif j==2: record1=int(c.text.strip()) elif j==3: record2=str(c.find('a', class_='movie').text.strip()) record3=str(c.text).split("\n")[2] elif j==4: record4=str(c.find('a', class_='author').text.strip()) record5=str(c.text).split("****")[1] try: record_t=tuple([record, record1, record2, record3, record4, record5]) list_records.append(record_t) except: pass print(list_records) db.conn_db() db.create_table() db.insert_movie(list_records)
print(url) response = urllib.request.urlopen(url) navigator = BeautifulSoup(response, 'html.parser') table = navigator.find('table', class_='list_netizen') print(table) list_records = [] for i, r in enumerate(table.find_all('tr')): #i 는 tr의 인덱스값 for j, c in enumerate(r.find_all('td')): #j는 td의 인덱스값 if j == 0: record = int(c.text.strip()) #j==1이 없는 이유는 별표는 지금 쓸 필요 없어서 elif j == 2: record1 = int(c.text.strip()) elif j == 3: record2 = str(c.find('a', class_='movie').text.strip()) record3 = str(c.text).split('\n')[2] elif j == 4: record4 = str(c.find('a', class_='author').text.strip()) record5 = str(c.text).split("****")[1] try: record_t = tuple([record, record1, record2, record3, record4, record5]) list_records.append(record_t) except: pass print(list_records) conn = db.conn_db() db.create_table() db.insert_movie(list_records)
#!/usr/bin/env python # -*- coding: utf-8 -*- import MySQLdb import sys, re, time from db import conn_db conn = conn_db() cur = conn.cursor() def get_word(word): word = word.strip() word_list = [] cur.execute('SELECT * FROM word WHERE word = "%s"' % (word)) rows = cur.fetchall() for row in rows: word_map = {} word_map["word"] = row[0] word_map["hash"] = row[1] word_map["ref_word"] = row[2] word_map["part_of_speech"] = row[3] word_map["definition"] = row[4] word_map["examples"] = row[5] word_map["commonness"] = row[6] word_map["pron"] = row[7] if word_map["ref_word"] != None: ref_list = get_word(word_map["ref_word"]) word_list = word_list + ref_list else: word_list.append(word_map) return word_list
def index(): conn = db.conn_db() items = conn.execute('SELECT * FROM list').fetchall() return render_template('home.html', items=items)
#!/usr/bin/env python # -*- coding: utf-8 -*- import MySQLdb import sys,re,time from db import conn_db conn = conn_db() cur = conn.cursor() def get_word(word): word = word.strip() word_list = [] cur.execute('SELECT * FROM word WHERE word = "%s"' %(word)) rows = cur.fetchall() for row in rows: word_map= {} word_map["word"] = row[0] word_map["hash"] = row[1] word_map["ref_word"] = row[2] word_map["part_of_speech"] = row[3] word_map["definition"] = row[4] word_map["examples"] = row[5] word_map["commonness"] = row[6] word_map["pron"] = row[7] if word_map["ref_word"] != None: ref_list = get_word(word_map["ref_word"]) word_list = word_list + ref_list else: word_list.append(word_map) return word_list def add_color(word):