def decode(): arr = {} myfile = 'binfile.bin' mycode = 0 arr = opencode(arr) check(arr) mycode = getcode(myfile,mycode,arr)
async def update(context): text_channel = context.message.channel try: user = context.message.author if user.name == main_nickname: async with text_channel.typing(): check() await text_channel.send('Обновил роли!') except Exception as e: await text_channel.send('Ошибка: \n {}'.format(e))
def test_random_grammars(): for _ in range(50): G = generate_random_grammar() T = generate_positive_examples(G) nltk_grammar = convert2_nltk_CFG(G) #print(nltk_grammar) #print(T) for w in T: #print(w) assert check(nltk_grammar, w, nltk=True) assert check(G, w) print( "generate_random_grammar() and generate_positive_examples() functions work" )
def runserver(ctx, host, port): click.echo('Performing system check') with check('Check database settings'): raise check.Failed() web.run_app(make_app(ctx.obj['DEBUG']), host=host, port=port)
def nav(self,x,y,room): if room.contains(x,y) == False: return False if room.cells[y][x] == ' ' or "potion" in room.cells[y][x]: room.cells[self.y][self.x] = ' ' if room.cells[y][x] == "h_potion": print("You found a health potion! +1000 HP!") self.hp += 1000 if room.cells[y][x] == "m_potion": print("You found a mana potion! +150 MP!") self.mp += 150 self.x = x self.y = y self.room = room room.cells[y][x] = self for cell in room.adj_cells(self.x,self.y): if isinstance(cell, monster): self.room.show(self) print("Oh no! You are attacked!") print("What will you do?") choose = 1 war = battle(self,cell) while not choose == '1' and not choose == '2': choose = raw_input("\t1. Fight!\n\t2. Flee!\n?> ") if choose == '1': kq2 = war.fight() check(kq2, "You have been defeated! Loser!") if kq2 == True: print("+%d XP") % cell.xp self.lvup(cell.xp) room.cells[cell.y][cell.x] = ' ' else: kq2 = war.flee() if kq2 == False: kq2 = war.fight() check(kq2, "You have been defeated! Loser!") if kq2 == True: print("+%d XP") % cell.xp self.lvup(cell.xp) room.cells[cell.y][cell.x] = ' ' return True else: return 'F'
def Diagonalize( M, p = 1e-8 ): ''' This function performs the diagonalization of a matrix using Jacobi algorith.''' def findmax(MM): maximum = 0. maxpos = [0,0] for i in range(len(MM)): for j in range(len(MM[0])): if i==j: continue if abs(MM[i][j]) > maximum: maximum = abs(MM[i][j]) maxpos = [i,j] return maxpos def check( M1, M2 ): for i in range(len(M1)): for j in range(len(M1[0])): if abs( M1[i][j] - M2[i][j] ) > p: return False return True D = list( M ) V = identity( len(M) ) while True: row,col = findmax(D) t = ( D[col][col] - D[row][row] )/( 2.*D[row][col] ) t = sign( t )/( abs(t) + math.sqrt( t**2 + 1 ) ) c = 1./math.sqrt( t**2 + 1 ) s = c * t R = identity( len(M) ) R[row][row] = c R[col][col] = c R[row][col] = s R[col][row] = -s DD = mxm( transpose( R ), mxm( D, R ) ) VV = mxm( V, R ) if check(D,DD) and check(V,VV): break D = DD V = VV return D,V
def normal(prompt, check = notcheck): i = 0 while True: i = Get.raw(prompt) if i == "h": Prompt.help() elif i == "i": Prompt.allUserInfo() elif i == "l": Prompt.allAliveUserInfo() elif not type(i) is int and not i.isdigit(): continue else: i = int(i) if check(i): break return i
def runTopo(topoFile, simParams, hostOptions, checkLevel, controller, switch): topo = CustomTopo(topoFilePath = topoFile, simParams = simParams, hostOptions = hostOptions) if checkLevel > 1: topo.setNetOption('link', TCLink) # net = CustomMininet(topo = topo, controller = Beacon, autoSetMacs = True, **topo.getNetOptions()) # net = CustomMininet(topo = topo, controller = Beacon, **topo.getNetOptions()) net = CustomMininet(topo = topo, controller = controller, switch = switch, **topo.getNetOptions()) global netprobes netprobes = collections.OrderedDict() try: lg.output('Constructing virtual network..\n') start(net) check(net, checkLevel) lg.output("Starting hosts") lg.info(": ") for host in net.hosts: lg.info("%s " % host.name) if host.monitor_rules is not None: monitor.start(host, host.monitor_rules) if host.command is not None: lg.info("cmd ") host.command = host.command.format(commandOpts = host.commandOpts, name = host.name).format(name = host.name) if host.isXHost: t = makeTerm(host, cmd = host.command) if len(t) < 1: lg.error("Error while starting terminal for host %s\n" % host.name) continue if len(t) == 2: tunnel, term = t else: term = t try: if term.poll() is not None: lg.error( "Terminal with command %s ended early for host %s : %s\n" % (host.command, host.name, repr(term.communicate()))) except: pass netprobes[host.name] = term else: netprobes[host.name] = runCommand(host) # print(netprobes[host.name].communicate()) else: if host.isXHost: makeTerm(host) lg.info("term ") lg.info("done ") lg.output("\n") EventsManager.startClock(net) interract(net) mon = False counter = monitor.Counter() for host in net.hosts: if host.monitor_rules is not None: monitor.collect(host, monitor_file, counter) monitor.stop(host, host.monitor_rules) mon = True for name, probe in netprobes.iteritems(): lg.info("Send sigint to probe %s\n" % name) import signal try: probe.send_signal(signal.SIGINT) time.sleep(0.05) except OSError as e: lg.error("Failed to send SIGINT to %s : %s\n" % ( name, e)) if mon: monitor.writeSummary(monitor_file, counter) finally: stop(net) # cleanup ! lg.info("Stopping remaining processes...\n") kill = 0 for name, probe in netprobes.iteritems(): if probe.poll() is None: kill += 1 if kill > 0: lg.info("Found %s process(es) to kill\n" % kill) time.sleep(3) for name, probe in netprobes.iteritems(): if probe.poll() is None: try: lg.info("Send terminate signal to %s\n" % name) probe.terminate() time.sleep(0.001) except OSError as e: lg.error("Failed to terminate %s : %s\n" % (name, e)) time.sleep(3) for name, probe in netprobes.iteritems(): if probe.poll() is None: try: lg.info("Send kill signal to %s\n" % name) probe.kill() except OSError as e: lg.error("Failed to kill %s : %s\n" % (name, e)) lg.output("\nAll done\n")
def nextnow(ch_id, m_id, data): key = json.dumps( {'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]]}) if data == '2': text = check() if 'no class scheduled' in text.lower() or 'holiday' in text.lower( ) or 'link not updated' in text.lower() or 'break' in text.lower( ) or 'offline' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'compiler design lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cdlab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'software engineering lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': selab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) """ elif 'microprocessor lab' in text.lower() : key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':mplab()}],[{'text':'Go back','callback_data':'0'}]]}) """ elif 'compiler design' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cd() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'software engineering' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': se() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'Cryptography and network security' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cns() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'digital image processing' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': dip() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'machine learning' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': ml() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'enterprise resource planning' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': erp() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'compiler design lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cdl() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'software engineering lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': sel() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) """" elif 'microprocessor' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':mp()}],[{'text':'Go back','callback_data':'0'}]]}) elif 'industrial training' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':it()}],[{'text':'Go back','callback_data':'0'}]]}) """ elif 'placement and training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': pt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif data == '3': text = nextcl() if 'no classes scheduled' in text.lower() or 'holiday' in text.lower( ) or 'link not updated' in text.lower() or 'break' in text.lower( ) or 'offline' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'compiler design' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cd() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'software engineering' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': se() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'cryptography and network security' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cns() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'digital image processing' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': dip() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'machine learning' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': ml() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'enterprise resource planning' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': erp() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'compiler design lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cdlab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'software engineering lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': selab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) """ elif 'microprocessor lab' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':mplab()}],[{'text':'Go back','callback_data':'0'}]]}) elif 'computer graphics' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':cg()}],[{'text':'Go back','callback_data':'0'}]]}) elif 'computer networks' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':cn()}],[{'text':'Go back','callback_data':'0'}]]}) elif 'microprocessor' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':mp()}],[{'text':'Go back','callback_data':'0'}]]}) elif 'industrial training' in text.lower(): key=json.dumps({'inline_keyboard':[[{'text':'Join class','url':it()}],[{'text':'Go back','callback_data':'0'}]]}) """ elif 'placement and training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': pt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) params = { 'chat_id': ch_id, 'message_id': m_id, 'text': text, 'reply_markup': key, 'parse_mode': 'HTML' } return params
def runTopo(topoFile, simParams, hostOptions, checkLevel, controller, switch): topo = CustomTopo(topoFilePath=topoFile, simParams=simParams, hostOptions=hostOptions) if checkLevel > 1: topo.setNetOption('link', TCLink) # net = CustomMininet(topo = topo, controller = Beacon, autoSetMacs = True, **topo.getNetOptions()) # net = CustomMininet(topo = topo, controller = Beacon, **topo.getNetOptions()) net = CustomMininet(topo=topo, controller=controller, switch=switch, **topo.getNetOptions()) global netprobes netprobes = collections.OrderedDict() try: lg.output('Constructing virtual network..\n') start(net) check(net, checkLevel) lg.output("Starting hosts") lg.info(": ") for host in net.hosts: lg.info("%s " % host.name) if host.monitor_rules is not None: monitor.start(host, host.monitor_rules) if host.command is not None: lg.info("cmd ") host.command = host.command.format( commandOpts=host.commandOpts, name=host.name).format(name=host.name) if host.isXHost: t = makeTerm(host, cmd=host.command) if len(t) < 1: lg.error( "Error while starting terminal for host %s\n" % host.name) continue if len(t) == 2: tunnel, term = t else: term = t try: if term.poll() is not None: lg.error( "Terminal with command %s ended early for host %s : %s\n" % (host.command, host.name, repr(term.communicate()))) except: pass netprobes[host.name] = term else: netprobes[host.name] = runCommand(host) # print(netprobes[host.name].communicate()) else: if host.isXHost: makeTerm(host) lg.info("term ") lg.info("done ") lg.output("\n") EventsManager.startClock(net) interract(net) mon = False counter = monitor.Counter() for host in net.hosts: if host.monitor_rules is not None: monitor.collect(host, monitor_file, counter) monitor.stop(host, host.monitor_rules) mon = True for name, probe in netprobes.iteritems(): lg.info("Send sigint to probe %s\n" % name) import signal try: probe.send_signal(signal.SIGINT) time.sleep(0.05) except OSError as e: lg.error("Failed to send SIGINT to %s : %s\n" % (name, e)) if mon: monitor.writeSummary(monitor_file, counter) finally: stop(net) # cleanup ! lg.info("Stopping remaining processes...\n") kill = 0 for name, probe in netprobes.iteritems(): if probe.poll() is None: kill += 1 if kill > 0: lg.info("Found %s process(es) to kill\n" % kill) time.sleep(3) for name, probe in netprobes.iteritems(): if probe.poll() is None: try: lg.info("Send terminate signal to %s\n" % name) probe.terminate() time.sleep(0.001) except OSError as e: lg.error("Failed to terminate %s : %s\n" % (name, e)) time.sleep(3) for name, probe in netprobes.iteritems(): if probe.poll() is None: try: lg.info("Send kill signal to %s\n" % name) probe.kill() except OSError as e: lg.error("Failed to kill %s : %s\n" % (name, e)) lg.output("\nAll done\n")
from yzm import * from check import * yzm_keys,s=getYzmXx('V1.0.07_001','011001900311','42558341') print(yzm_keys["key1"]+'\n'+yzm_keys['key4']) yzm=input("输入验证码:") print(check(s,"011001900311","42558341","20190829","643785",yzm,yzm_keys))
def test_check(self): q = check(lambda y: y > 0, "Type Error: %s not > 0") self.assertEqual(q(4), 4) self.assertRaises(TypeError, q, -3)
date_today = datetime.now() date = int(str(date_today)[8:10]) #No. of activites = 12 #No. of active hours in a day = 16.5hrs 5am - 9:30pm data_list = list() activities_time = { "Studying": 3, "Assignments": 3, "Coding": 2, "Running": 1, "Reading": 1, "Table Tennis": 3, "Breakfast": 0.5, "Lunch": 0.5, "Dinner": 1, "Misc:": 1.5 } points = 0 for activity in activities_time: if check(activity): points += check_time(activities_time[activity]) x, y = (date, points) data_list.append(tuple((x, y))) write(data_list) lis = read() readdata = list() x_list, y_list = convertlist(lis) plot(x_list, y_list)
def main(): new_offset = 0 print('Launching the bot...') while True: all_updates = niloner_bot.get_updates(new_offset) if len(all_updates) > 0: for current_update in all_updates: print(current_update) first_update_id = current_update['update_id'] if 'callback_query' in current_update: print('call_back') first_update_id = current_update['update_id'] if 'data' in current_update['callback_query']: data_r = current_update['callback_query']['data'] m_id = current_update['callback_query']['message'][ 'message_id'] chat_id = current_update['callback_query']['message'][ 'chat']['id'] niloner_bot.callbackquery(chat_id, m_id, data_r) new_offset = first_update_id + 1 print(data_r, chat_id, m_id) elif 'message' in current_update: m_id = current_update['message']['message_id'] if 'text' not in current_update['message']: first_chat_text = 'New member' #new_offset = first_update_id + 1 else: first_chat_text = current_update['message']['text'] first_chat_id = current_update['message']['chat']['id'] if 'first_name' in current_update['message']: first_chat_name = current_update['message']['chat'][ 'first_name'] elif 'from' in current_update['message']: first_chat_name = current_update['message']['from'][ 'first_name'] else: first_chat_name = "unknown" if 'new_chat_member' in current_update['message']: first_chat_name = current_update['message'][ 'new_chat_member']['first_name'] niloner_bot.send_message( first_chat_id, m_id, 'Welcome ' + '<b><i>' + first_chat_name + '</i></b>' + '\nHope this group will help you.\nType /help for list of commands\n\nI am a bot created by @Renolin\n' + sp) new_offset = first_update_id + 1 elif 'left_chat_participant' in current_update['message']: temp_name = current_update['message']['from'][ 'first_name'] name = current_update['message'][ 'left_chat_participant']['first_name'] rid = current_update['message'][ 'left_chat_participant']['id'] pid = current_update['message']['from']['id'] if rid == pid: niloner_bot.send_message( first_chat_id, m_id, '<b><i>' + name + '</i></b>' + ' left the group chat.') else: niloner_bot.send_message( first_chat_id, m_id, '<b><i>' + name + '</i></b>' + ' was removed by ' + '<b><i>' + temp_name + '</i></b>') new_offset = first_update_id + 1 elif 'pinned_message' in current_update['message']: niloner_bot.send_pinned( first_chat_id, m_id, first_chat_name + ' pinned a message') new_offset = first_update_id + 1 elif first_chat_text == 'Hi' or first_chat_text == 'hi': niloner_bot.send_pinned(first_chat_id, m_id, 'Hi ' + first_chat_name) new_offset = first_update_id + 1 elif first_chat_text == '/notify': niloner_bot.send_notify( first_chat_id, m_id, '<b>NOTIFICATION</b>\n\n' + '<i>' + notification() + '</i>') new_offset = first_update_id + 1 elif first_chat_text == '/start': niloner_bot.send_message( first_chat_id, m_id, 'Hi ' + '<b><i>' + first_chat_name + '</i></b>' + '\n Type /help for list of commands\n\n\n\nThis bot was created by @Renolin' ) new_offset = first_update_id + 1 else: flag = 1 if first_chat_text == '/tt': flag = 0 niloner_bot.send_message(first_chat_id, m_id, table()) new_offset = first_update_id + 1 if first_chat_text == '/help': flag = 0 niloner_bot.send_help(first_chat_id) new_offset = first_update_id + 1 if first_chat_text == '/now': flag = 0 niloner_bot.send_message(first_chat_id, m_id, check()) new_offset = first_update_id + 1 if first_chat_text == '/next': flag = 0 niloner_bot.send_message(first_chat_id, m_id, nextcl()) new_offset = first_update_id + 1 if first_chat_text == '/cd': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Compiler Design </u></b>\n\n' + cd()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_cd' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 1) niloner_bot.send_message( first_chat_id, m_id, '<b>Compiler Design </b> link updated \n\n' + temp[1]) new_offset = first_update_id + 1 if first_chat_text == '/se': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Software Engineering</u></b>\n\n' + se()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_se' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 2) niloner_bot.send_message( first_chat_id, m_id, '<b>Software Engineering</b> link updated \n\n' + temp[2]) new_offset = first_update_id + 1 if first_chat_text == '/cns': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Cryptography and Network Security</u></b>\n\n' + cns()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_cns' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 3) niloner_bot.send_message( first_chat_id, m_id, '<b>Cryptography and Network Security</b> link updated\n\n' + temp[3]) new_offset = first_update_id + 1 if first_chat_text == '/dip': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Digital Image Processing</u></b>\n\n' + dip()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_dip' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 4) niloner_bot.send_message( first_chat_id, m_id, '<b>Digital Image Processing</b> link updated\n' + temp[4]) new_offset = first_update_id + 1 if first_chat_text == '/ml': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Machine Learning</u></b>\n\n' + ml()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_ml' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 5) niloner_bot.send_message( first_chat_id, m_id, '<b>Machine Learning</b> link updated \n\n' + temp[5]) new_offset = first_update_id + 1 if first_chat_text == '/erp': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Enterprise Resource Planning</u></b>\n\n' + erp()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_sat' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7::9] j = first_chat_text[8:] l = changesat(h, j) niloner_bot.send_message(first_chat_id, m_id, l) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_erp' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 6) niloner_bot.send_message( first_chat_id, m_id, '<b>Enterprise Resource Planning</b> link updated\n\n' + temp[6]) new_offset = first_update_id + 1 if first_chat_text == '/cdl': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Computer Design LAB</u></b>\n\n' + cdlab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lcd' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 7) niloner_bot.send_message( first_chat_id, m_id, '<b>Compiler Design LAB</b> link updated\n\n' + temp[7]) new_offset = first_update_id + 1 if first_chat_text == '/sel': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Software Engineering LAB</u></b>\n\n' + selab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lse' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 8) niloner_bot.send_message( first_chat_id, m_id, '<b>Software Engineering LAB</b> link updated\n\n' + temp[8]) new_offset = first_update_id + 1 """if first_chat_text == '/mpl': flag=0 niloner_bot.send_message(first_chat_id,m_id,'<b><u>Microprocessor LAB</u></b>\n\n'+mplab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lmp' == first_chat_text[ :7]: flag=0 h=first_chat_text[7:] change(h,9) niloner_bot.send_message(first_chat_id,m_id, '<b>Microprocessor LAB</b> link updated\n\n'+temp[9]) new_offset = first_update_id + 1 if first_chat_text == '/it': flag=0 niloner_bot.send_message(first_chat_id,m_id,'<b><u>Industrial training</u></b>\n\n'+it()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_it' == first_chat_text[ :6]: flag=0 h=first_chat_text[6: ] change( h,10 ) niloner_bot.send_message(first_chat_id,m_id, '<b>Industrial training </b>link updated\n\n'+temp[10]) new_offset = first_update_id + 1 """ if first_chat_text == '/pt': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Placement and training</u></b>\n\n' + pt()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_pt' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 11) niloner_bot.send_message( first_chat_id, m_id, '<b>Placement and training </b>link updated\n' + temp[11]) new_offset = first_update_id + 1 if first_chat_text == '/ftt': flag = 0 niloner_bot.send_photo( first_chat_id, m_id, 'AgACAgUAAxkBAAIaJ1_yKLh3KEENayD5RDRiPYTTmf16AAKWqjEbGKGRVyKL3mSnTUrrdwGxbnQAAwEAAwIAA3kAA8YJAQABHgQ' ) new_offset = first_update_id + 1 if '/ch_notify' in first_chat_text and first_chat_id in ID: flag = 0 h = first_chat_text[10:] change_notify(h) niloner_bot.send_message( first_chat_id, m_id, 'Notification updated\n' + notification()) new_offset = first_update_id + 1 if flag == 1: niloner_bot.send_message( first_chat_id, m_id, 'My brain does not have a response for that.') new_offset = first_update_id + 1
def fetch(self, json): if self.User is not None: return check(json, self.User, jsonform=True, debug=True) #return a json file with link else: return None
def current(self): if self.User is not None: return check(getData, self.User) #return a json file with link else: return None
def __init__(self,configpath,outputpath,delay=10000): self.configpath = configpath self.outputpath = outputpath self.quit = False self.check = check(path) self.delay = delay/1000
for sl in slist: if sl.isspace(): guessword.append(' ') else: guessword.append('_') print("The No of Blanks:") for ele in guessword: print(ele, end=' ') turns = 5 while turns > 0: guess = input("\nEnter a letter to guess:") if checksingle(guess): if check(s, guess): a = printcheck(s, guess, guessword) if a == slist: break else: print("Wrong Guess!Number of turns left:", turns - 1) turns -= 1 else: print("Please enter one character only") if turns == 0: print("\n\n\t\t\tGame Over!") print("\n\t\t Better Luck Next time") else: finalans = '' for fl in slist:
print "-" * 80 g_totals, h_totals, r_totals, u_totals, c_totals,num=fck(results) print "number of totalurls:",num print "-"*80 print "g_totals, h_totals, r_totals, u_totals, c_totals" print len(g_totals),len(h_totals),len(r_totals),len(u_totals),len(c_totals) #check(ref11) print "-"*80 # check(get01) print "-" * 80 #check(get01) # print ref01 # print "-" * 80 # check(ref11) print "-" * 80 check(ua11) print "-"*80 realua,uanum=RealUA(urls11,ua11) print realua if len(realua)!=0: print realua print uanum realurl = usermt(urls01, urls11, realua) print realurl print "number of possible urls:", len(realurl) F1, R, P, realurls = Realurl(realurl) print "F1:", F1 print "Recall:", R print "Precise:", P print "userurl:", len(realurls) # else:
g_totals, h_totals, r_totals, u_totals, c_totals, num = fck(results) print "number of totalurls:", num print "-" * 80 print "g_totals, h_totals, r_totals, u_totals, c_totals" print len(g_totals), len(h_totals), len(r_totals), len(u_totals), len( c_totals) #check(ref11) print "-" * 80 # check(get01) print "-" * 80 #check(get01) # print ref01 # print "-" * 80 # check(ref11) print "-" * 80 check(ua11) print "-" * 80 realua, uanum = RealUA(urls11, ua11) print realua if len(realua) != 0: print realua print uanum realurl = usermt(urls01, urls11, realua) print realurl print "number of possible urls:", len(realurl) F1, R, P, realurls = Realurl(realurl) print "F1:", F1 print "Recall:", R print "Precise:", P print "userurl:", len(realurls) # else:
def nextnow(ch_id, m_id, data): key = json.dumps( {'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]]}) if data == '2': text = check() if 'no class scheduled' in text.lower() or 'holiday' in text.lower( ) or 'link not updated' in text.lower() or 'break' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'theory of computation' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': toc() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'web technology' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': wt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'mobile app development' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mad() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer graphics and multimedia lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cglab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer networks lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cnlab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'microprocessor lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mplab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer graphics' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cg() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer networks' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cn() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'microprocessor' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mp() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'industrial training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': it() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'placement and training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': pt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif data == '3': text = nextcl() if 'no classes scheduled' in text.lower() or 'holiday' in text.lower( ) or 'link not updated' in text.lower() or 'break' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'theory of computation' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': toc() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'web technology' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': wt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'mobile app development' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mad() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer graphics and multimedia lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cglab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer networks lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cnlab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'microprocessor lab' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mplab() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer graphics' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cg() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'computer networks' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': cn() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'microprocessor' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': mp() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'industrial training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': it() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) elif 'placement and training' in text.lower(): key = json.dumps({ 'inline_keyboard': [[{ 'text': 'Join class', 'url': pt() }], [{ 'text': 'Go back', 'callback_data': '0' }]] }) params = { 'chat_id': ch_id, 'message_id': m_id, 'text': text, 'reply_markup': key, 'parse_mode': 'HTML' } return params
def main(): new_offset = 0 print('Launching the bot...') while True: all_updates = niloner_bot.get_updates(new_offset) if len(all_updates) > 0: for current_update in all_updates: print(current_update) first_update_id = current_update['update_id'] if 'callback_query' in current_update: print('call_back') first_update_id = current_update['update_id'] if 'data' in current_update['callback_query']: data_r = current_update['callback_query']['data'] m_id = current_update['callback_query']['message'][ 'message_id'] chat_id = current_update['callback_query']['message'][ 'chat']['id'] niloner_bot.callbackquery(chat_id, m_id, data_r) new_offset = first_update_id + 1 print(data_r, chat_id, m_id) elif 'message' in current_update: m_id = current_update['message']['message_id'] if 'text' not in current_update['message']: first_chat_text = 'New member' #new_offset = first_update_id + 1 else: first_chat_text = current_update['message']['text'] first_chat_id = current_update['message']['chat']['id'] if 'first_name' in current_update['message']: first_chat_name = current_update['message']['chat'][ 'first_name'] elif 'from' in current_update['message']: first_chat_name = current_update['message']['from'][ 'first_name'] else: first_chat_name = "unknown" if 'new_chat_member' in current_update['message']: first_chat_name = current_update['message'][ 'new_chat_member']['first_name'] niloner_bot.send_message( first_chat_id, m_id, 'Welcome ' + '<b><i>' + first_chat_name + '</i></b>' + '\nHope this group will help you.\nType /list for list of commands\n\nI am a bot created by @Renolin\n' + sp) new_offset = first_update_id + 1 elif 'left_chat_participant' in current_update['message']: temp_name = current_update['message']['from'][ 'first_name'] name = current_update['message'][ 'left_chat_participant']['first_name'] rid = current_update['message'][ 'left_chat_participant']['id'] pid = current_update['message']['from']['id'] if rid == pid: niloner_bot.send_message( first_chat_id, m_id, '<b><i>' + name + '</i></b>' + ' left the group chat.') else: niloner_bot.send_message( first_chat_id, m_id, '<b><i>' + name + '</i></b>' + ' was removed by ' + '<b><i>' + temp_name + '</i></b>') new_offset = first_update_id + 1 elif 'pinned_message' in current_update['message']: niloner_bot.send_pinned( first_chat_id, m_id, first_chat_name + ' pinned a message') new_offset = first_update_id + 1 elif first_chat_text == 'Hi' or first_chat_text == 'hi': niloner_bot.send_pinned(first_chat_id, m_id, 'Hi ' + first_chat_name) new_offset = first_update_id + 1 elif first_chat_text == '/notify': niloner_bot.send_notify( first_chat_id, m_id, '<b>NOTIFICATION</b>\n\n' + '<i>' + notification() + '</i>') new_offset = first_update_id + 1 elif first_chat_text == '/start': niloner_bot.send_message( first_chat_id, m_id, 'Hi ' + '<b><i>' + first_chat_name + '</i></b>' + '\n Type /help for list of commands\n\n\n\nThis bot was created by @Renolin' ) new_offset = first_update_id + 1 else: flag = 1 if first_chat_text == '/tt': flag = 0 niloner_bot.send_message(first_chat_id, m_id, table()) new_offset = first_update_id + 1 if first_chat_text == '/help': flag = 0 niloner_bot.send_help(first_chat_id) new_offset = first_update_id + 1 if first_chat_text == '/now': flag = 0 niloner_bot.send_message(first_chat_id, m_id, check()) new_offset = first_update_id + 1 if first_chat_text == '/next': flag = 0 niloner_bot.send_message(first_chat_id, m_id, nextcl()) new_offset = first_update_id + 1 if first_chat_text == '/toc': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Theory of computation</u></b>\n\n' + toc()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_toc' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 1) niloner_bot.send_message( first_chat_id, m_id, '<b>Theory of computation</b> link updated \n\n' + temp[1]) new_offset = first_update_id + 1 if first_chat_text == '/cg': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Computer graphics and multimedia</u></b>\n\n' + cg()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_cg' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 2) niloner_bot.send_message( first_chat_id, m_id, '<b>Computer graphics and multimedia</b> link updated \n\n' + temp[2]) new_offset = first_update_id + 1 if first_chat_text == '/cn': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Computer networks</u></b>\n\n' + cn()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_cn' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 3) niloner_bot.send_message( first_chat_id, m_id, '<b>Computer networks</b> link updated\n\n' + temp[3]) new_offset = first_update_id + 1 if first_chat_text == '/mad': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Mobile app development</u></b>\n\n' + mad()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_mad' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 6) niloner_bot.send_message( first_chat_id, m_id, '<b>Mobile app development</b> link updated\n' + temp[6]) new_offset = first_update_id + 1 if first_chat_text == '/wt': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Web technology</u></b>\n\n' + wt()) new_offset = first_update_id + 1 if first_chat_text == '/mp': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Microprocessor</u></b>\n\n' + mp()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_sat' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7::9] j = first_chat_text[8:] l = changesat(h, j) niloner_bot.send_message(first_chat_id, m_id, l) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_mp' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 4) niloner_bot.send_message( first_chat_id, m_id, '<b>Microprocessor</b> link updated\n\n' + temp[4]) new_offset = first_update_id + 1 if first_chat_text == '/cgl': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Computer graphics LAB</u></b>\n\n' + cglab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lcg' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 7) niloner_bot.send_message( first_chat_id, m_id, '<b>Computer graphics and multimedia LAB</b> link updated\n\n' + temp[7]) new_offset = first_update_id + 1 if first_chat_text == '/cnl': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Computer networks LAB</u></b>\n\n' + cnlab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lcn' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 8) niloner_bot.send_message( first_chat_id, m_id, '<b>Computer networks LAB</b> link updated\n\n' + temp[8]) new_offset = first_update_id + 1 if first_chat_text == '/mpl': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Microprocessor LAB</u></b>\n\n' + mplab()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_lmp' == first_chat_text[: 7]: flag = 0 h = first_chat_text[7:] change(h, 9) niloner_bot.send_message( first_chat_id, m_id, '<b>Microprocessor LAB</b> link updated\n\n' + temp[9]) new_offset = first_update_id + 1 if first_chat_text == '/it': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Industrial training</u></b>\n\n' + it()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_it' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 10) niloner_bot.send_message( first_chat_id, m_id, '<b>Industrial training </b>link updated\n\n' + temp[10]) new_offset = first_update_id + 1 if first_chat_text == '/pt': flag = 0 niloner_bot.send_message( first_chat_id, m_id, '<b><u>Placement and training</u></b>\n\n' + pt()) new_offset = first_update_id + 1 if first_chat_id in ID and '/ch_pt' == first_chat_text[: 6]: flag = 0 h = first_chat_text[6:] change(h, 11) niloner_bot.send_message( first_chat_id, m_id, '<b>Placement and training </b>link updated\n' + temp[11]) new_offset = first_update_id + 1 if first_chat_text == '/ftt': flag = 0 niloner_bot.send_photo( first_chat_id, m_id, 'AgACAgUAAxkBAAIF_V92plbUjrx94tYKodyeNQmdWPjbAAKaqjEbo6GxV-x6we6XqVjA-3rra3QAAwEAAwIAA3gAA5lYBAABGwQ' ) new_offset = first_update_id + 1 if '/ch_notify' in first_chat_text and first_chat_id in ID: flag = 0 h = first_chat_text[10:] change_notify(h) niloner_bot.send_message( first_chat_id, m_id, 'Notification updated\n' + notification()) new_offset = first_update_id + 1 if flag == 1: niloner_bot.send_message( first_chat_id, m_id, 'My brain does not have a response for that.') new_offset = first_update_id + 1
def test_check(): productions1 = """ NT0 -> 'a' NT1 NT0 -> 'b' NT1 NT1 -> 'c' NT1 NT1 -> 'm' """.strip() test_grammar = nltk.CFG.fromstring(productions1) s2t = lambda string: list(map(lambda x: (x, ), string)) print(s2t("accccccccm")) terminals = set(["a", "b", "c", "m"]) nonterminals = set(["NT0", "NT1"]) productions = { "NT0": [[("a", ), ("NT1", )], [("b", ), ("NT1", )]], "NT1": [[("c", ), ("NT1", )], [("m", )]] } start = set(["NT0"]) G = (terminals, nonterminals, productions, start) #for sentence in generate(convert2_nltk_CFG(G), n=10): assert check(test_grammar, s2t("accccccccm"), nltk=True) assert check(test_grammar, s2t("bcccccccm"), nltk=True) assert check(test_grammar, s2t("am"), nltk=True) assert check(test_grammar, s2t("acccccdccm"), nltk=True) == False assert check(test_grammar, s2t("bccccmc"), nltk=True) == False assert check(test_grammar, s2t("am!"), nltk=True) == False print("check() function works for nltk grammars") # check that convert2_nltk_CFG function works assert check(G, s2t("accccccm")) assert check(G, s2t("bm")) assert check(G, s2t("bccccccm")) assert check(G, s2t("acccccmb")) == False assert check(G, s2t("bmb!")) == False assert check(G, s2t("bcNT0ccccc3m")) == False print("check() function works for this code bases' grammars") print("convert2_nltk_CFG() function works.")