def update_or_insert(table, fields, values, condition): field = fields[-1] value = values[-1] up = update(table, field, value, condition) if not none_or_empty(up): return up else: store.insert(table, fields, [values]) logger.debug('insert %s: %s' % (table, values)) return None
def exitAndSave(root): root.destroy() global start_date # 应用启动时的时间 global kb_count # 键盘敲击次数 init_data = store.isExist(start_date) if init_data != None: store.update(start_date, kb_count, ms_count) else: store.insert(start_date, kb_count, ms_count)
def motto_reply(display, text): if none_or_empty(text): return None if len(text.split('\n')) > 4: global error error = '箴言最多4行' return None id, name, nick = runner(display) store.insert('motto', ['rid', 'content', 'date'], [[id, text, date.date()]]) return '已添加,将随机展示'
def rose_reply(display, text): if not none_or_empty(text): update_name(display, text) rose = event('七夕西湖玫瑰跑') eid = rose[0] table = 'event_runner' rid, name, nick = runner(display) condition = cond({'eid': eid, 'rid': rid}) if store.exists(table, condition=condition): store.delete(table, condition) else: store.insert(table, ['eid', 'rid', 'date'], [[eid, rid, date.datetime()]]) return event_rank(rose)
def fetch(page): result = newsapi.get_everything(sources=sources, language='en', page=page) articles = result['articles'] for article in articles: if (not article['title']) or (not article['description']): continue values = [ article['source']['name'], article['author'], dumps(article['title']), dumps(article['description']), article['url'], article['urlToImage'], article['publishedAt'] ] text = clean_text(crawl(values[4], article['source']['id'])) category = model.predict(vect.transform([text]))[0] insert(values, category) print(category) print('=' * len(category)) print(text) print('')
print("ERROR 1!") store.writeCsv("./Output1.csv") store.setTitle([ "id", "label", "title_decision", "title_score", "content_decision", "content_score" ]) rs = readcsv.getNext() while rs != -1: res = -1 maxtry = 10 try: while res == -1 and maxtry > 0: res = req.sendRequest(rs) maxtry = maxtry - 1 except: print("Internet Error!Sleep 3 sec!", res, maxtry) time.sleep(3) continue record = [rs[0],rs[3],res["title_decision"],\ res["title_score"],res["content_decision"],\ res["content_score"]] store.insert(record) store.fflush() rs = readcsv.getNext() print(record) print("Done") readcsv.closeCsv() store.closeCsv()