def RegisterUser(username,email,password): #first of all check if the user is already present into the database if exists('user','email',email): d={} d['description']='the email is already registered' d['esit_register']=1 return d if username==None:username=id_generator() if existsS('user','username',username): d={} d['description']='the username is already registered' d['esit_register']=3 return d #if the user is not present... db=MySQLdb.connect(host=HOST,user=DBUSER,passwd=DBPASS,db=DBNAME, use_unicode=True,charset="utf8") #db=MySQLdb.connect(HOST,DBUSER,DBPASS,DBNAME) cursor=db.cursor(MySQLdb.cursors.DictCursor) sql="INSERT INTO user (username,email,password,active) VALUES ('%s','%s','%s',1);"%(username,email,password) userid=0 try: cursor.execute(sql) userid=db.insert_id() db.commit() except: db.rollback() cursor.close() db.close() try: emailsend.sendemail(email) except Exception ,ems: ErrorLog("RegisterUser %s %s %s , exception:%s"%(username,email,password,ems))
def sendcmd(id,port,msg): exIP = utility.get_ip() arr_ex_IP = exIP.split('.') # print arr_ex_IP IP_ = arr_ex_IP[0] + '.' + arr_ex_IP[1] + '.' + arr_ex_IP[2] + '.' + id BC_IP = arr_ex_IP[0] + '.' + arr_ex_IP[1] + '.' + arr_ex_IP[2] + '.255' msg['dest'] = IP_ msg['src'] = exIP msg['id'] = utility.id_generator(10) print msg s = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP for i in range(1,255): itr_ip = arr_ex_IP[0] + '.' + arr_ex_IP[1] + '.' + arr_ex_IP[2] + '.'+str(i) #print itr_ip s.sendto(json.dumps(msg), (itr_ip, port))
def create_random_generator(self, num, min, max, base="acctname"): min = int(min) max = int(max) for _ in range(num): a = self.get_acc_obj(base + id_generator(), True) self.post_sys_create(a, randint(min, max), randint(min, max), randint(min, max)) toTransfer = Asset(randint(min, max)) BootStrapper.transfer(self.host_address, 'eosio', a.name, toTransfer, "Initial TLOS Liquid") a.amount += toTransfer yield a
def create_random_accounts(self, num_accounts, min, max, base="acctname"): accounts = [] min = int(min) max = int(max) for _ in range(num_accounts): a = self.get_acc_obj(base + id_generator(), True) cpu = randint(min, max) net = randint(min, max) ram = randint(min, max) self.post_sys_create(a, net, cpu, ram) accounts.append(a) return accounts
def train(evaluation): n = len(evaluation['training']) for i, example in enumerate(evaluation['training']): example_name = example['file'] hint = example['expected_words_count'] rate, samples = wavfile.read('../wav/{0}.wav'.format(example_name)) rate, speech_words = extract_words(rate, samples, hint) if len(speech_words) != len(example['words']): 'Error during training for {0}'.format(example_name) continue for word, speech in zip(example['words'], speech_words): wav_name = id_generator() + '.wav' save_wav(word, wav_name, rate, speech, '../dictionary') print('Completed {0}%'.format(100.0 * (i + 1) / float(n)))
def train(dirs): print('Training on {0}'.format(dirs)) reset_dir(DICTIONARY) for i, dir in enumerate(dirs): for file in os.walk(DIR_NAME + '/' + dir).next()[2]: word = file.split('_')[0] if not filter(word): continue rate, samples = wavfile.read('{0}/{1}/{2}'.format( DIR_NAME, dir, file)) _, speech_words = extract_words(rate, samples, 1) if len(speech_words) != 1: print('Error extracting {0}/{1}'.format(dir, file)) continue wav_name = id_generator() + '.wav' save_wav(word, wav_name, rate, speech_words[0], DICTIONARY) print('Completed {0}%'.format(100.0 * (i + 1) / float(len(dirs)))) print('Done training.')