def insert_news(news_id, title, source_name, source_url, author, count, ico, type, imgs, summary=''): db = Database('insert') sql = """insert ignore into news (news_id, title, source_name, source_url, author, read_count, source_ico, type, summary) values('%s', '%s', '%s', '%s', '%s', %d, '%s', '%d', '%s') """ re_title = recombination(title) title = re_title if len(re_title) > 0 else title re = db.execute(sql, par=(news_id, title, source_name, source_url, author, count, ico, type, summary)) for img in imgs: if len(img) < 5: continue if img.find('https:') != 0 and img.find('http:') != 0: img = 'https:' + img db.execute( """insert ignore into image (news_id, url) values('%s', '%s')""", par=(news_id, img)) return re
def insert_detail(news_id, title, content, source, publishTime): db = Database('detail') sql = """insert ignore into detail (news_id, title, content, source, publish_time) values('%s', '%s', '%s', '%s', '%s') """ re_title = recombination(title) re_content = recombination(content) title = re_title if len(re_title) > 0 else title content = re_content if len(re_content) > 0 else content re = db.execute(sql, par=(news_id, title, content, source, publishTime)) return re
def delete(news_id): db = Database('error') sql = """update news set status = -1 where news_id = '%s'""" db.execute(sql, (news_id, )) del db
def increase(id): db = Database('increase') sql = """update news set read_count = read_count + 1 where news_id = '%s'""" db.execute(sql, (id, )) del db