def main(): global db db = mydb() # try: measure_mood(24) db.close()
def funcion_noticias(fuente='none'): dictUrls = {} bd = mydb() news = bd.query('SELECT * FROM bot.noticias') print(news) bd.close() for medio in news: dictUrls.update({medio[0]: medio[1]}) if fuente == 'none': submenu = [] disponibles = dictUrls.keys() for medio in disponibles: submenu.append('/noticias %s\n' % medio) return submenu else: salida = requests.get(dictUrls[fuente]) reddit_root = etree.fromstring(salida.text) item = reddit_root.findall('channel/item') news_feed = [] for entry in item: #get description, url, and thumbnail desc = entry.findtext('title') link = entry.findtext('guid') news_feed.append('%s\n%s' % (desc, link)) return news_feed
def getparam_db(apiname): """ :rtype : object """ id = 3 testdb = mydb.mydb() # if apiname=='totalDetail': if id == 1: tmpsql = 'SELECT testcasename,methodurl,param,expect_value,param_type from testcase where apiname=' + "'" + apiname + "' and id=" + id print tmpsql # tmpsql='SELECT testcasename,methodurl,param,expect_value,param_type from testcase where apiname=\'%s\''%apiname else: tmpsql = 'SELECT testcasename,methodurl,param,expect_value,param_type from testcase where apiname=' + "'" + apiname + "'" print tmpsql # else: # tmpsql='SELECT testcasename,param,expect_value,param_type from testcase where apiname='+"'"+apiname+"'" # # print tmpsql # print testdb.mydb_select(tmpsql) tmplist = [] try: for i in testdb.mydb_select(tmpsql): tmplist.append(i) except Exception, e: print e.message
def getparam_db(group='All'): """ :rtype : object """ testdb=mydb.mydb() # if apiname=='totalDetail': # tmpsql='SELECT id,testcasename,methodurl,param,expect_value,param_type from testcase where status=1 and apiname='+"'"+apiname+"'" if group== 'All': tmpsql = '''SELECT id,testcasename,methodurl,param,expect_value,param_type,remarks,actresult,`group` from testcase_adv where status=1 and apiState=1 and param_type in ('A','B','C');''' else: tmpsql = '''SELECT id,testcasename,methodurl,param,expect_value,param_type,remarks,actresult,`group` from testcase_adv where status=1 and apiState=1 and group={} and param_type in ('A','B','C');'''.format(group) # -- and actresult=200 # else: # tmpsql='SELECT testcasename,param,expect_value,param_type from testcase where apiname='+"'"+apiname+"'" # print tmpsql # print testdb.mydb_select(tmpsql) tmplist=[] try: for i in testdb.mydb_select(tmpsql): tmplist.append(i) except Exception , e: print e.message
def main(pages): mydb_beau = mydb() mydict_beau = mydict() mydb_beau.create_table('customer') row_count = mydb_beau.get_count() try: for i in range(pages): if i == 0: url = 'https://sclub.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv3436&productId=100002795955&score=0&sortType=5&page=0&pageSize=10&isShadowSku=0&fold=1' else: url = 'https://sclub.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98vv3423&productId=100002795955&score=0&sortType=5&page={}&pageSize=10&isShadowSku=0&rid=0&fold=1'.format( i) r_dict = get_page(url, headers=headers) for element in r_dict['comments']: customer_list = [ element['id'], element['content'].replace(" ", "").replace( "\n", "").replace('"', "'")[0:255], element['productColor'], element['creationTime'] ] mydb_beau.insert_data(customer_list) if row_count == mydb_beau.get_count(): raise Already_exists() else: row_count = mydb_beau.get_count() if i >= 10 and i % 10 == 0: #每十页休息30s sleep(30) except Already_exists: pass if i == pages - 1: print('数据收集完成!') else: print('数据更新完成!') list_kinds = ['天空之境', '亮黑色', '极光色', '赤茶橘', '珠光贝母'] color_list = mydb_beau.get_color_data() list_numbers = [ color_list.count('天空之境'), color_list.count('亮黑色'), color_list.count('极光色'), color_list.count('赤茶橘'), color_list.count('珠光贝母') ] for comment in mydb_beau.get_str_comments(): mydict_beau.add_into_comment_dictionary( mydict_beau.divide_commint(comment)) if (mydict_beau.draw_dictionary(mydict_beau.sort_dictionary())): print("高频词词云已经绘好!") mydb_beau.close() if (draw_color(list_kinds, list_numbers)): print('颜色饼状图已经更新!')
def getparam_db(): testdb = mydb.mydb() tmpsql = 'SELECT testcasename,param,expect_value,param_type from testcase' print testdb.mydb_select(tmpsql) tmplist = [] for i in testdb.mydb_select(tmpsql): tmplist.append(i) print tmplist return tmplist
def getCmp_cases(): testdb = mydb.mydb() sql = '''SELECT id,testcasename,param,expect_value,param_type,`group` from testcase_adv where status=1 and apiState=1 and param_type='D' ''' tmplist=[] try: for i in testdb.mydb_select(sql): tmplist.append(i) except Exception , e: print e.message
def __init__(self): super(Ui, self).__init__() uic.loadUi('UserManagerGUI/saveuserGUI.ui', self) self.shortcutSave = QShortcut(QKeySequence('Ctrl+S'), self) self.shortcutSave.activated.connect(self.saveuser) self.shortcutSearch = QShortcut(QKeySequence('Ctrl+E'), self) self.shortcutSearch.activated.connect(self.searchuser) self.mydb = mydb() self.edited = False self.statusbar = self.findChild(QtWidgets.QStatusBar, 'statusbar') self.name = self.findChild(QtWidgets.QTextEdit, 'namebox') self.age = self.findChild(QtWidgets.QTextEdit, 'agebox') self.gender = self.findChild(QtWidgets.QComboBox, 'genderbox') self.phone = self.findChild(QtWidgets.QTextEdit, 'phonenumberbox') self.role = self.findChild(QtWidgets.QComboBox, 'rolebox') self.address = self.findChild(QtWidgets.QTextEdit, 'addressbox') self.save = self.findChild(QtWidgets.QPushButton, 'savebox') self.search = self.findChild(QtWidgets.QPushButton, 'searchbox') self.lastfive = self.findChild(QtWidgets.QTableWidget, 'lastfivebox') self.delete = self.findChild(QtWidgets.QPushButton, 'deletebox') self.check1 = self.findChild(QtWidgets.QCheckBox, 'checkBox') self.check2 = self.findChild(QtWidgets.QCheckBox, 'checkBox_2') self.check3 = self.findChild(QtWidgets.QCheckBox, 'checkBox_3') self.check4 = self.findChild(QtWidgets.QCheckBox, 'checkBox_4') self.check5 = self.findChild(QtWidgets.QCheckBox, 'checkBox_5') self.save.setToolTip('Ctrl + S') self.search.setToolTip('Ctrl + E') self.name.setFocus() tabSeq = self.setTabOrder tabSeq(self.name, self.save) tabSeq(self.save, self.search) tabSeq(self.search, self.address) tabSeq(self.address, self.role) tabSeq(self.role, self.phone) tabSeq(self.phone, self.gender) tabSeq(self.gender, self.age) tabSeq(self.age, self.name) self.DisplayLastFive() self.statusbar.hide() self.save.clicked.connect(self.saveuser) self.search.clicked.connect(self.searchuser) self.delete.clicked.connect(self.deleteLine) self.lastfive.cellDoubleClicked.connect(self.editRow) self.show()
def GET(self): db = mydb() user_data = web.input() data_id = int(web.websafe(user_data.data_id)) cursor = db.query("select * from twitter where id > %s limit 100", data_id) rows = cursor.fetchall() db.close() web.header('Content-Type', 'application/json') result = {} for row in rows: index = row[0] result[index] ={} result[index]['s'] = row[2] result[index]['lo'] = row[3] result[index]['la'] = row[4] return json.dumps(result, default=json_encode_decimal)
def del_gdatas(): ''' 删除上一次自动化,遗留的测试数据 :return: ''' logging.setLoggerClass(CommonLog) logger = logging.getLogger(__name__) testdb = mydb.mydb() #定义sql中的变量 ad_key_word = '用后删除的' aid = '2222455' #分别查询广告主订单、计划、创意ids order_ids = testdb.mydb_select("select id from voyager.ad_order ao where ao.name like '%{}%' and ao.advertiser_id='{}';".format(ad_key_word,aid)) plan_id = testdb.mydb_select(" select id from voyager.ad_plan ap where ap.name like '%{}%' and ap.advertiser_id='{}';".format(ad_key_word,aid)) creative_id = testdb.mydb_select("select id from voyager.ad_creative ac where ac.name like '%{}%' and ac.advertiser_id='{}';".format(ad_key_word,aid)) #根据返回的ids值,删除历史数据 if len(order_ids) > 0: for i in order_ids: # print ("delete from voyager.ad_order_creative aoc where aoc.order_ids in ({});".format(i[0])) logger.info("delete from voyager.ad_order_creative where order_id in ({})".format(i[0])) logger.info("delete from voyager.ad_order_direction where order_id in ({})".format(i[0])) logger.info("delete from voyager.ad_order where id in ({})".format(i[0])) testdb.mydb_select("delete from voyager.ad_order_creative where order_id in ({})".format(i[0])) testdb.mydb_select("delete from voyager.ad_order_direction where order_id in ({})".format(i[0])) testdb.mydb_select("delete from voyager.ad_order where id in ({})".format(i[0])) if len(plan_id)>0: for i in plan_id: logger.info( "delete from voyager.ad_plan where id in ({});".format(i[0])) testdb.mydb_select("delete from voyager.ad_plan where id in ({});".format(i[0])) if len(creative_id)>0: for i in creative_id: logger.info("delete from voyager.ad_creative_link where creative_id in ({});".format(i[0])) logger.info("delete from voyager.ad_creative where id in ({});".format(i[0])) testdb.mydb_select("delete from voyager.ad_creative_link where creative_id in ({});".format(i[0])) testdb.mydb_select("delete from voyager.ad_creative where id in ({});".format(i[0]))
def main(): gpio = mygpio(LED_RED, LED_GREEN, LED_BLUE, BUZZER) db = None ldap = None while True: try: # Init ldap = myldap(LDAP_SRV) db = mydb(DB_HOST, DB_USER, DB_PASS, DB_NAME) # Ready to start gpio.startSeq() gpio.ledForTime(LED_GREEN, mygpio.INFINITY) while True: line = sys.stdin.readline() chipidsearch = re.search( r'SN=\[([a-f0-9]*)\]', line, re.M) chipid = None if chipidsearch: chipid = chipidsearch.group(1) #print "CardID = %s" % (chipid) user = db.getUserByChipId(chipid) if not user: ldapuser = ldap.getLdapUserByChipId(chipid) if ldapuser is None: # chipid not in LDAP, invalid user gpio.failSeq() continue username = ldapuser.get('uid') user = db.getUserByUsername(username) if user: # username in db, but with different chipcard db.updateChipCard(user, chipid) else: # new username, adding to db db.insertUserFromLdap(ldapuser, chipid) user = db.getUserByUsername(username) else: # it's ok # user with chipcard already in db pass gpio.successSeq() db.insertCoffee(user) else: gpio.failSeq() sleep(0.1) except Exception as error: # Bad state (mysql, ldap, ...), reboot of raspberry is needed print error if db: db.close() if ldap: ldap.close() #15s blinking RED gpio.ledFail(LED_RED, 1) print "Error occurred, restarting rca-reader"