Best Python code snippet using avocado_python
minu_assistant_bot.py
Source: minu_assistant_bot.py
...57 if n >= prefix[s]:58 value = float(n) / prefix[s]59 return '%.1f%s' % (value, s)60 return "%sB" % n61def get_diskspace():62 disk_usage = psutil.disk_usage('/')63 total_used_free_text = 'Total {total}, Used {used}, Free {free}\64 '.format(total=bytes2human(disk_usage.total),65 used=bytes2human(disk_usage.used),66 free=bytes2human(disk_usage.free))67 return total_used_free_text68def get_liveprocesses():69 alive_bots_text = ''70 for p in psutil.process_iter(attrs=['name', 'status', 'cmdline']):71 if len(p.info['cmdline']) > 1:72 if ('bot' in p.info['cmdline'][1]):73 alive_bots_text = alive_bots_text + \74 'id: {}, name: {}, status: {}, cmdline: {} '.format(p.pid,p.info['name'],p.info['status'],p.info['cmdline'][1])75 return alive_bots_text76# Error handling77def unknown(update, context):78 context.bot.send_message(chat_id=update.message.chat_id,79 text="Sorry, I didn't understand the command!\80 Please try again!")81#def callback_daily(context: telegram.ext.CallbackContext):82def callback_daily(context):83 m_text = get_diskspace()84 chat_id = context.job.context['chat_id']85 context.bot.send_message(chat_id=chat_id,86 text=m_text)87def button(update, context):88 query = update.callback_query89 if query.data == 'diskspace':90 result_text = get_diskspace()91 elif query.data == 'uptime':92 result_text = get_uptime()93 elif query.data == 'liveprocesses':94 result_text = get_liveprocesses()95 else:96 result_text = 'Unknown command'97 query.edit_message_text(text="Status is: {}".format(result_text))98def main():99 # Importing the Updater object with token for updates from Telegram API100 # Declaring the Dispatcher object to send information to user101 # Creating the bot variable and adding our token102 updater = Updater(token=config.token, use_context=True)103 dispatcher = updater.dispatcher104 bot = telegram.Bot(token=config.token)...
diskinfo.py
Source: diskinfo.py
...20 last_drivespaces = dict()21 cur_drivespaces = dict()22 for drive in filter((lambda x: (x.type == 'Fixed')), cur_drives.driveitem):23 try:24 last_drivespaces[drive.drive[0].upper()] = ops.files.drives.get_diskspace(drive.drive[0].upper(), maxage=datetime.timedelta.max)25 cur_drivespaces[drive.drive[0].upper()] = ops.files.drives.get_diskspace(drive.drive[0].upper(), maxage=datetime.timedelta(seconds=options.maxage))26 except ops.cmd.OpsCommandException as ex:27 ops.warn(('Had a problem when trying to get disk space on drive %s.' % drive.drive[0].upper()))28 ops.warn('It might be a memory card reader or something similar that only pretends to be fixed')29 drive_remove = list()30 drive_add = list()31 for old_drive in last_drives.driveitem:32 match_drive = filter((lambda x: ((x.drive[0].upper() == old_drive.drive[0].upper()) and (x.type == old_drive.type) and (x.serialnumber == old_drive.serialnumber))), cur_drives.driveitem)33 if (len(match_drive) == 0):34 drive_remove.append(old_drive)35 for new_drive in cur_drives.driveitem:36 match_drive = filter((lambda x: ((x.drive[0].upper() == new_drive.drive[0].upper()) and (x.type == new_drive.type) and (x.serialnumber == new_drive.serialnumber))), last_drives.driveitem)37 if (len(match_drive) == 0):38 drive_add.append(new_drive)39 ops.survey.print_agestring(cur_drives.dszobjage)
...
usbDisk.py
Source: usbDisk.py
...16 stdout = subprocess.check_output("sudo mount '%s' '/shots'" % (self.name,), shell=True, timeout=60, stderr=subprocess.STDOUT, ).decode("UTF-8")17 except:18 stdout = ""19 time.sleep(5)20 self.get_diskspace()21 def umount(self):22 try:23 stdout = subprocess.check_output("sudo mxount '%s' '/shots'" % (self.name,), shell=True, timeout=10, stderr=subprocess.STDOUT, ).decode("UTF-8")24 except:25 stdout = ""26 def get_diskspace(self):27 try:28 stdout = subprocess.check_output('df -h | grep "/shots"', shell=True, timeout=10, stderr=subprocess.STDOUT, ).decode("UTF-8")29 except:30 stdout = ""31 line = stdout.split("\n")[0]32 while " " in line:33 line = line.replace(" ", " ")34 try:35 print(line)36 fs, size, used, avail, usedp, mount = line.split(" ")37 self.disk_total = size38 self.disk_free = avail39 except Exception as e:40 print(e)...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!