def get_text_messages(message): string = str(message.text).lower() ifbot = re.findall(r'бот,скажи|эй,бот|эй, бот|бот, скажи',string) if message.chat.type == "private" or message.chat.type == "group" and len(ifbot) > 0: Logs.log(message) result = re.findall(r'доллар|евро|юан|фунт|йен',string) result += re.findall(r'саратов|москв|санкт-петербург|казан|питер|екатеринбург' + r'|нижн|новосибирск|самар|ростове-на-дону|красноярск|воронеж|краснодар|' + r'тюмен|ижевск|иркутск|хабаровск|благовещенск|архангельск|астрахан|белгород|брянск' + r'|владимир|волгоград|вологд|иваново|калининград|калуга|петропавловске-камчатский|кемерово' + r'|киров|костром|курган|курск|липецк|магадан|мурманск|велик|омск|оренбург|пенз|перм|псков' + r'|рязан|южно-сахалинск|смоленск|тамбов|тул|тюмен|ульяновск|челябинск|чит|ярославл|майкоп' + r'|горно-алтайск|уф|улан-уде|махачкал|биробиджан|нальчик|элист|черкесск|петрозаводск|сыктывкар|симферопол' + r'|йошкар-ол|саранск|якутск|владикавказ|казан|кызыл|ижевск|абакан|грозн|чебоксар|барнаул|краснодар|' + r'владивосток|ставропол|нарьян-мар|ханты-мансийск|анадыр|салехард' ,string) resultcb = re.findall(r'доллар|евро|юан|фунт|йен',string) resultcb += re.findall(r'..-..-....',string) if len(result) < 2 and len(re.findall(r'цб',string)) == 0 or len(resultcb) == 0 or resultcb[0][0].isnumeric(): Logs.log(bot.send_message(message.chat.id,"Прости, по твоему запросу ничего не удалось найти(")) elif len(re.findall(r'цб',string)) != 0 and len(resultcb) != 0: date = None currency = DAO.parse(resultcb) if len(resultcb) == 2: date = resultcb[1] Logs.log(bot.send_message(message.chat.id,CentralBank.GetCurrency(currency,date))) elif(len(result) >= 2): currency,city = DAO.parse(result) print(currency,city) Logs.log(bot.send_message(message.chat.id,Parser.GetCurrency(currency,city)))
def create_feature_object(self, feature): feat = DAO.get_python_feature_obj(feature) i = 0 # iterate over every function name in the list and get a python object # for that function, replace the list element with this object while i < len(feat['functions']): feat['functions'][i] = DAO.get_python_function_obj(feat['functions'][i]) i += 1 malwareFeat = MalwareFeatures.MalwareFeature() malwareFeat.add_imports(feat['imports']) malwareFeat.add_global_variables(feat['globals']) for func in feat['functions']: if len(func['imports']) > 0: malwareFeat.add_imports(func['imports']) if len(func['globals']) > 0: malwareFeat.add_global_variables(func['globals']) malwareFeat.add_func_declarations(func['header']) malwareFeat.add_func_definitions(func['definition']) malwareFeat.add_feat_body(feat['body']) malwareFeat.set_feat_priority(feat['priority']) malwareFeat.set_feat_name(feat['name']) return malwareFeat
def test08_visualize_post(self): self.assertTrue(self.mysql_open_connection()) try: self.assertTrue(self.send_query('START TRANSACTION')) now = datetime.now() id = 1 formatted_date = now.strftime('%Y-%m-%d %H:%M:%S') self.assertTrue( DAO.add_view( self.connection, "INSERT INTO viu_post (id_usuario, id_post, id_OS, id_browser, IP, horario) VALUES (%s,%s,%s,%s,%s,%s);", (2, 1, 1, 3, "172.195.29.2", formatted_date))) self.assertTrue( DAO.add_view( self.connection, "INSERT INTO viu_post (id_usuario, id_post, id_OS, id_browser, IP, horario) VALUES (%s,%s,%s,%s,%s,%s);", (4, 1, 2, 1, "192.168.0.12", formatted_date))) self.assertTrue( DAO.add_view( self.connection, "INSERT INTO viu_post (id_usuario, id_post, id_OS, id_browser, IP, horario) VALUES (%s,%s,%s,%s,%s,%s);", (1, 2, 1, 2, "192.168.1.25", formatted_date))) self.assertTrue( DAO.add_view( self.connection, "INSERT INTO viu_post (id_usuario, id_post, id_OS, id_browser, IP, horario) VALUES (%s,%s,%s,%s,%s,%s);", (3, 1, 1, 4, "192.168.1.24", formatted_date))) self.assertTrue(self.send_query('COMMIT')) except Exception as e: self.assertTrue(0 == 1) self.assertFalse(self.send_query('ROLLBACK')) print(e)
def isMySQL(on_off, add_check, *tmp): if on_off == 'off': return noMySQL(add_check, *tmp) if add_check == 'check': return DAO.verifyData(tmp[0], tmp[1]) if add_check == 'add': return DAO.insertData(tmp[0], tmp[1], tmp[2])
def __init__(self): self._conn = sql.connect('moncafe.db') self.employees = DAO._Employees(self._conn) self.suppliers = DAO._Suppliers(self._conn) self.coffeeStands = DAO._CoffeeStands(self._conn) self.products = DAO._Products(self._conn) self.activities = DAO._Activities(self._conn)
def agendamento(): if (request.method == 'POST'): jss = request.get_json() return DAO.createAgendamento(jss["id_medico"], jss["data_inicio"], jss["data_fim"]) else: return DAO.getAgendamentoById(jss["id_agendamento"])
def add_feature(request): if request.method == "POST": print(request.body) postData = re.split(r'{\"(.+|\[+|\]+)\]\}', str(request.body))[1] jsonData = '{\"' + postData + "]}" print(jsonData) feat = json.loads(jsonData) type_name = feat['type'] feat_type = Feature_Type.objects.get_or_create(name=type_name)[0] featObj = {} featObj['name'] = feat['name'] featObj['body'] = feat['body'] featObj['globals'] = feat['global'] featObj['import'] = feat['import'] featObj['priority'] = feat['priority'] featObj['functions'] = feat['functions'] featObj['type'] = feat_type featObj['prompt'] = feat['prompt'] featObj['options'] = feat['options'] DAO.add_new_feature(featObj) # tell the BotMaster that a new action sequence is available if (type_name == 'Action Sequence'): sendAction(featObj['name']) return HttpResponse(200)
def main(): print('Welcome!') entry = None while entry != '2': entry = input( '\n1. Current Student\n2. New Student\n3. Quit\nPlease, enter 1, 2 or 3: ' ) if entry == '1': student_dao = DAO.StudentDAO() email = input('\nEnter Your Email: ') pw = input('Enter Your Password: '******'\nWhat Would You Like To Do?') while entry != '2': entry = input( '\n1. Register To Course\n2. Logout\nPlease, enter 1 or 2: ' ) if entry == '1': show_all_courses(course_list) course_id = input('\nSelect Course By ID Number: ') print("\nAttempting to Register...") if attending_dao.register_student_to_course( email, course_id, course_list): show_my_courses(student, course_list) elif entry == '2': print('\nYou Have Been Logged Out.') else: print('\nInvalid Option...') else: print('\nWrong Credentials!') elif entry == '2': print("Welcome to the school!") student_dao = DAO.StudentDAO() email = input('Please provide your email : ') if not student_dao.get_student_by_email(email): name = input("What is your full name? : ") password = input("What would you like your password to be? : ") student_dao.add_new_student(email, name, password) entry = '-1' continue else: print("That email is already taken") elif entry == '3': print("Programming is closing, ") break else: print('Invalid Option...') print('\nClosing Program. Goodbye.')
def __init__(self): self._conn = sqlite3.connect("moncafe.db") self.employees = DAO.Employees(self._conn) self.suppliers = DAO.Suppliers(self._conn) self.coffee_stands = DAO.Coffee_stands(self._conn) self.activities = DAO.Activities(self._conn) self.products = DAO.Products(self._conn)
def test_insertar(self): client = MongoClient('localhost', 27017) dbUsuario = client.usuarios.usuarios DAO.insertarNuevoUsuario(555) cursor = dbUsuario.find_one({'_id': 555}) #print("soy cursor",cursor) self.assertTrue(cursor != None)
def getusergroups(userid, cache, gcache): '''Obtiene todos los roles del usuario devolviendo un dicionario que los contiene, en el que se marcan por defecto como permisos de aplicación''' # roles = {} roles = collections.OrderedDict() # data = DAO.sendrequest('GET', 'user/' + userid, None) data = DAO.sendrequest('GET', 'user/memberof/' + userid, None, 1) message = DAO.checkresponse(data) if message[0]: print "Ha entrado por aquí" response = ElementTree.fromstring(data) # for role in response[0][0].findall("attribute[@name='cn']"): for role in response[0]: # Crea una lista con los textos y su tipo bla = re.sub('cn=', '', role[1].text) ble = re.sub( ',ou=grupos,ou=usuariosTFSE,dc=wbsvision,dc=es,dc=toyota-fs,dc=com', '', bla) ble = re.sub(',ou=grupos,dc=wbsvision,dc=es,dc=toyota-fs,dc=com', '', ble) print ble # if role.text in cache: if ble in cache: if cache[role.text]['father'] == 'PuestoDeTrabajo': # if cache[ble]['father'] == 'PuestoDeTrabajo': roles['Puesto'] = role.text # roles['Puesto'] = ble roles[role.text] = cache[role.text] # roles[ble] = gcache[ble] else: print message[1] return roles
def results(request): template_name = 'emr/results.html' search_query = request.GET.get('searchstring') daoobject = DAO() daoobject.set_tables_config() daoobject.setEasyUser(request.user) regularsearch = render( request, template_name, { 'searchresults': daoobject.search(search_query, '1'), 'lastId': daoobject.getLastId('tabla_1', 'campo_1'), 'easyUser': daoobject.easy_user }) try: searchInt = int(search_query) searchStr = str(searchInt) zerosToAdd = 6 - len(searchStr) IdToReturn = '' for i in xrange(zerosToAdd): IdToReturn = IdToReturn + '0' if daoobject.doesIdExist(IdToReturn + searchStr): return patient(request, daoobject.doesIdExist(IdToReturn + searchStr)) else: return regularsearch except ValueError: return regularsearch
def user_join(): new_id = request.form['new_id'] new_pw = request.form['new_pw'] new_pwConfirm = request.form['new_pwConfirm'] new_email = request.form['new_email'] if new_pw != new_pwConfirm: return -1 user = User(new_id, new_pw, 1, 0) if DAO.emailCheck(new_email) == False: return -1 DAO.join(user) uniqueCode = createJoinCode() ''' joining = joiningUsers( email=new_email, code = uniqueCode ) ''' #db.session.add(joiningUsers) #db.session.commit() sendEmail(new_email, new_id, uniqueCode) return render_template("index.html")
def load_checkin(): checkin_file = '../brightkite/Brightkite_totalCheckins.txt' with open(checkin_file, "r") as f2: conn = sqlite3.connect('brightkite.db') c = conn.cursor() i = 0 lines = f2.readlines() for line in lines: i += 1 if i % 10000 == 0: print(i) line0 = line.strip().split() if len(line0) == 5: usr_id, checkin_time, latitude, longitude, loc_id = line.strip( ).split() if loc_id == '0': continue checkin_time = checkin_time[:-1] checkin = Checkin(user=usr_id, location_id=loc_id, checkin_time=checkin_time, latitude=latitude, longitude=longitude) DAO.execute_checkin(c, checkin) conn.commit()
def populateValues(boardPosition): currentBoardPosition = fetchEntry(boardPosition) if currentBoardPosition['touched'] == 1: return currentBoardPosition['tscore'] children = currentBoardPosition['tchildrens'] childlist = children.split(",") if currentBoardPosition['tscore'] == 0: #print "hello" + currentBoardPosition['turn'] if (currentBoardPosition['turn'] == "P1"): myValue = -100000 else: myValue = 100000 else: myValue = currentBoardPosition['tscore'] if children == '': DAO.updateTouched(boardPosition) return myValue for child in childlist: if currentBoardPosition['turn'] == "P1": myValue = max(populateValues(child), myValue) else: myValue = min(populateValues(child), myValue) updateScore(boardPosition, myValue) #myValue = (details[turn]=="P1") ?max(populateValues(value.boardposition)) :min(sdafs) #updateScore(boardPosition, myValue); DAO.updateTouched(boardPosition) return myValue
def updateStockMinQuotation(MysqlCursor , MysqlConn): # grab data per min,and save to each database(loop) shutDownFlag = 0 while shutDownFlag == 0: start_id = 1 end_id = start_id + 1800 while end_id <= 5001: nowDate = my_Time.transTimestampToDate(my_Time.getNowTimestamp()) shutDownFlag = my_Utils.shutDownTimeDetector(nowDate) print '-------------------update a mini-batch------------------' print '[' + str(nowDate) + ']' print str(start_id) + ' to ' + str(end_id) stockList = DAO.getStockBasicData(MysqlCursor, MysqlConn, start_id, end_id) stockMinDataPair = my_URL.getMinDataFromURL(1, stockList = stockList) DAO.setStockMinData(MysqlCursor, MysqlConn, stockMinDataPair) start_id = start_id + 500 end_id = end_id + 500 time.sleep(5) print '---------oneMin stock data got,now waiting for the next minute---------' time.sleep(10) return shutDownFlag
def agendar(): if (request.method == 'POST'): jss = request.get_json() return DAO.scheduleAgendamento(jss["id_paciente"], jss["id_agendamento"]) else: return DAO.getAgendamentoByVoucher(jss["voucher"])
def send_query(self, data): try: DAO.run_db_query(self.connection, data) return True except Exception as e: print(e) return False
def train(): """Train CIFAR-10 for a number of steps.""" with tf.Graph().as_default(): global_step = tf.train.get_or_create_global_step() # Get images and labels for CIFAR-10. # Force input pipeline to CPU:0 to avoid operations sometimes ending up on # GPU and resulting in a slow down. with tf.device('/cpu:0'): images, labels = DAO.distorted_inputs() # Build a Graph that computes the logits predictions from the # inference model. logits = DAO.inference(images) # Calculate loss. loss = DAO.loss(logits, labels) # Build a Graph that trains the model with one batch of examples and # updates the model parameters. train_op = DAO.train(loss, global_step) class _LoggerHook(tf.train.SessionRunHook): """Logs loss and runtime.""" def begin(self): self._step = -1 self._start_time = time.time() def before_run(self, run_context): self._step += 1 return tf.train.SessionRunArgs(loss) # Asks for loss value. def after_run(self, run_context, run_values): if self._step % FLAGS.log_frequency == 0: current_time = time.time() duration = current_time - self._start_time self._start_time = current_time loss_value = run_values.results examples_per_sec = FLAGS.log_frequency * FLAGS.batch_size / duration sec_per_batch = float(duration / FLAGS.log_frequency) format_str = ( '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' 'sec/batch)') print(format_str % (datetime.now(), self._step, loss_value, examples_per_sec, sec_per_batch)) with tf.train.MonitoredTrainingSession( checkpoint_dir=FLAGS.train_dir, hooks=[ tf.train.StopAtStepHook(last_step=FLAGS.max_steps), tf.train.NanTensorHook(loss), _LoggerHook() ], config=tf.ConfigProto(log_device_placement=FLAGS. log_device_placement)) as mon_sess: while not mon_sess.should_stop(): mon_sess.run(train_op)
def read(self): dao = DAO() articles = dao.find("random") for article in articles: title = article["title"] content = article["content"] cont = content.encode('utf-8') self.article_dict.update({title:cont})
def read(self): dao = DAO() articles = dao.find("random") for article in articles: title = article["title"] content = article["content"] cont = content.encode('utf-8') self.article_dict.update({title: cont})
def best_fit(f, racks=None): flavor = dao.get_flavor(f) servers = dao.get_all_servers(racks) server = None for s in servers: if Controller.can_host(flavor, s): server = s break return server
def get_recommended_product_by_product(user_id): if request.method == 'GET': conn = ConnectionHelper() table, labels = dao.get_recommended_products_table(conn) recommended_item_id = recommend.get_recommended_item( user_id, table, labels) recommended_product = dao.get_product_by_product_id( conn, recommended_item_id) return dumps(recommended_product), 200
def __init__(self): myfile = 'database.db' if os.path.isfile(myfile): os.remove(myfile) self._dbcon = sqlite3.connect('database.db') self.vaccines = DAO.Vaccines(self._dbcon) self.clinics = DAO.Clinics(self._dbcon) self.suppliers = DAO.Suppliers(self._dbcon) self.logistics = DAO.Logistics(self._dbcon)
def update_recommendation(): conn = ConnectionHelper() table, labels = dao.get_recommended_tribe_table(conn) df_tribe, data_recommend_tribe = recommend.get_recommended_item( table, labels) table, labels = dao.get_recommended_products_table(conn) df_prod, data_recommend_prod = recommend.get_recommended_item( table, labels) return df_prod, data_recommend_prod, df_tribe, data_recommend_tribe
def get_recommended_tribe(user_id): if request.method == 'GET': global data_recommend_tribe, df_tribe conn = ConnectionHelper() table, labels = dao.get_recommended_tribe_table(conn) recommended_item_id = recommend.get_recommended_item( user_id, table, labels) recommended_tribe = dao.get_tribe_by_id(conn, recommended_item_id) return dumps(recommended_tribe), 200
class Decision(object): def __init__(self): self.dao = DAO() def takeDecision(self): # Recupération de la liste scénarios scenarios = self.dao.getListScenarios() # Boucle sur les scénarios définis par l'utilisateur for scenario in scenarios: # Booléen pour savoir si toutes les conditions sont vérifiées status = 0 # Récupération des conditions du scénario states = self.dao.getListStatesByScenario(scenario) for state in states: # La condition est-elle vérifiée ? if self.isStateChecked(state): status = 1 else : status = 0 if status: notification = Notification() notification.send(scenario) else: print scenario.name + ": SCENARIO PAS VERIFIE" def isStateChecked(self, state): # Identification du capteur sensor = self.dao.getSensorByState(state) # Séparation des capteurs booléens ou numériques if sensor.type_sensor == "boolean": return sensor.current_value == state.value else: # type_sensor == "numeric" if state.operator == "=": return sensor.current_value == state.value elif state.operator == "<": return sensor.current_value < state.value elif state.operator == ">": return sensor.current_value > state.value elif state.operator == "<=": return sensor.current_value <= state.value elif state.operator == ">=": return sensor.current_value >= state.value
def create_images(file_name): with open(file_name, "r") as f: # The first line indicates how many images store images_cnt = f.readline().split() images_list = [] for i in range(int(images_cnt[0])): line = f.readline().split() image = Image(line[0], validator.validate_int_value(line[1]), line[2]) images_list.append(image) dao.create_images(images_list)
def deleterecord(request, table_id, record_id): daoobject = DAO() daoobject.set_tables_config() daoobject.setEasyUser(request.user) if daoobject.backEndUserRolesCheck(table_id, 'delete_table'): daoobject.delete(table_id, record_id) return index(request)
def create_flavors(file_name): with open(file_name, "r") as f: # The first line indicates how many flavors store flavors_cnt = f.readline().split() flavors_list = [] for i in range(int(flavors_cnt[0])): line = f.readline().split() flavor = Flavor(line[0], validator.validate_int_value(line[1]), validator.validate_int_value(line[2]), validator.validate_int_value(line[3])) flavors_list.append(flavor) dao.create_flavors(flavors_list)
def declare_interest(): if request.method == 'POST': request_json = request.get_json() conn = ConnectionHelper() interest = {} interest['user_id'] = request_json['user_id'] interest['product_id'] = request_json['product_id'] interest['category_id'] = request_json['category_id'] interest['tribe_id'] = request_json['tribe_id'] dao.declare_interest(conn, interest) return dumps(interest), 200
def main(): print('Welcome!') entry = None while entry != '2': entry = input( '\n1. Student\n2. Quit\n3. Register as a New Student\nPlease, enter 1, 2 or 3: ' ) if entry == '1': student_dao = DAO.StudentDAO() email = input('\nEnter Your Email: ') pw = input('Enter Your Password: '******'\nWhat Would You Like To Do?') while entry != '2': entry = input( '\n1. Register To Course\n2. Logout\nPlease, enter 1 or 2: ' ) if entry == '1': show_all_courses(course_list) course_id = input('\nSelect Course By ID Number: ') print("\nAttempting to Register...") if attending_dao.register_student_to_course( email, course_id, course_list): show_my_courses(student, course_list) elif entry == '2': print('\nYou Have Been Logged Out.') else: print('\nInvalid Option...') else: print('\nWrong Credentials!') elif entry == '3': email = input('\nEnter Your Email: ') name = input('Enter Your Full Name: ') pw = input('Enter A Password: '******'students.csv', 'a') as f: f.write(f'{email},{name},{pw}\n') print('\nRegistration Successful!') elif entry != '2': print('\nInvalid Option...') print('\nClosing Program. Goodbye.')
def get_query(self): if not self.detour: blank = ''.encode('utf-8') content = blank dao = DAO() while content == blank: article = dao.pop('random') title = article["title"] content = article["content"].encode('utf-8') query = {title: content} return query else: return self.get_detour()
def get_query(self): if not self.detour: blank = ''.encode('utf-8') content = blank dao = DAO() while content == blank: article = dao.pop('random') title = article["title"] content = article["content"].encode('utf-8') query = {title:content} return query else: return self.get_detour()
class article_handler: def __init__(self): self.DAO = DAO() self.wikipedia = Wikpedia_API() self.db_count = 0 def fetch_documents(self): random_title = self.wikipedia.get_random(1,[],0) new_article = self.wikipedia.get_article_info(random_title) self.DAO.insert_one(new_article, "new_articles") def update_database(self): count = self.DAO.count("new_articles") if count < 20: self.fetch_documents()
def getAllSchedule(): tempInfo = init().find_all('table', width="950", border="0", align="center")[0] allTrInfo = tempInfo.find_all('tr') # 当前时间 curDate = None # 当前星期 curWeek = None # 需要插入的比赛数据 schedules = [] year = ['2013', '2014'] for trInfo in allTrInfo: # 为标题,需要取当天时间 if trInfo['bgcolor'] == '#FFD200': # date = 10月05日星期六,替换掉月、日 tempDate = trInfo.find_all('td')[0].getText() curWeek = tempDate[-3:] curDate = tempDate.replace(curWeek,'').replace(u'月', '-').replace(u'日', '') # 截取前两位,获得月份 curMonth = curDate[0:2] # 判断是第一年,还是第二年 if curMonth == '10' or curMonth == '11' or curMonth == '12': curDate = year[0] + '-' + curDate else: curDate = year[1] + '-' + curDate # 为具体比赛,需要取当前数据,不包括比分,只有日期、时间、主队、客队 else: tdInfo = trInfo.find_all('td') # 具体时间 # 比赛对象 pointInfo = Domain.Point() pointInfo.time = tdInfo[0].getText().replace(u'完场', '').replace(u'未赛','') pointInfo.date = curDate pointInfo.type = tdInfo[1].string pointInfo.weekday = curWeek pointInfo.guest = tdInfo[2].a.string pointInfo.home = tdInfo[4].a.string schedules.append(pointInfo) # 插入schedule数据 DAO.insertSchedules(schedules)
class Trainingset: def __init__(self): self.DAO = DAO() self.api = Wikipedia_API() self.links = self.read_file("links.txt") ## self.random = self.api.get_random(10, [], 0) def annotate(self, input): print("Beginning annotation of {} titles.".format(len(input))) inserted = 0 for title in input: try: page_info = self.api.get_article_info(title) inserted_id = self.DAO.insert_one(page_info, "topics") print("Inserted: {}".format(inserted_id)) inserted += 1 except Exception as e: print(e) print("Inserted: {} article objects.".format(inserted)) def test(self, input): successfully_parsed = 0 errored_out = [] for title in input: try: page_info = self.api.get_article_info(title) if page_info["links"] is not None: successfully_parsed += 1 print("Parsed {}".format(title)) except Exception as e: print(e) errored_out.append(title) return successfully_parsed, errored_out def read_file(self, file): file = open("links.txt", "r+") lines = file.readlines() file.close() return [line[:-1] for line in lines]
def savePlayers(): playerList = getPlayersInfo() DAO.insertPlayer(playerList)
def __init__(self): self.dao = DAO()
def __init__(self): self.DAO = DAO() self.api = Wikipedia_API() self.links = self.read_file("links.txt")
def __init__(self): self.DAO = DAO() self.wikipedia = Wikpedia_API() self.db_count = 0
def saveTeams(): DAO.insertTeam(getTeamInfo())