Best Python code snippet using stestr_python
calc_time.py
Source: calc_time.py
1from datetime import datetime23def day_formatter(start_time, end_time, lunch_start, lunch_end, total_time):4 width = 245 l1_l = 'Start Time:'.ljust(width - 4)6 l1_r = start_time.strftime('%H%M')7 l2_l = 'Lunch Start Time:'.ljust(width - 4)8 l2_r = lunch_start.strftime('%H%M')9 l3_l = 'Lunch End Time:'.ljust(width - 4)10 l3_r = lunch_end.strftime('%H%M')11 l4_l = 'End Time:'.ljust(width - 4)12 l4_r = end_time.strftime('%H%M')13 l5_l = 'Total Time:'.ljust(width - 4)14 l5_r = str(total_time)[:-3]1516 print()17 print("=" * width)18 print(l1_l + l1_r)19 print(l2_l + l2_r)20 print(l3_l + l3_r)21 print(l4_l + l4_r)22 print()23 print(l5_l + l5_r)24 print("=" * width)25 print()2627def calc_time():28 print('Enter all times as four digit 24 hr times without colons (e.g. "1415").')29 start_time = str(input('Enter start time: '))30 lunch_start = str(input('Enter lunch start time: '))31 if lunch_start not in ['n', '']:32 lunch_end = str(input('Enter lunch end time: '))33 else:34 lunch_start = '0000'35 lunch_end = '0000'36 end_time = str(input('Enter end time: '))37 38 times = [start_time, lunch_start, lunch_end, end_time]39 try:40 format_times = [datetime.strptime(time, '%H%M') for time in times]41 total_time = format_times[3] - format_times[0] - (format_times[2] - format_times[1])42 day_formatter(format_times[0], format_times[3], format_times[1], format_times[2], total_time)43 except ValueError:44 print()45 print('Entered time formats are invalid. Please enter times as "HHMM".')46 calc_time()47 input('Press ENTER to exit...')4849if __name__ == '__main__':
...
app.py
Source: app.py
...12@app.route("/calculate_balance", methods=['POST'])13def calculate_balance():14 args = request.get_json(force=True)15 print(args)16 start_time = format_times(args.get('start_time'))17 end_time = format_times(args.get('end_time'))18 bed_time = format_times(args.get('bed_time'))19 20 print(start_time, end_time, bed_time)21 calculation = calculate_nightly_charge(start_time, end_time, bed_time)22 return jsonify(calculation)23if __name__ == '__main__':...
test_format_times.py
Source: test_format_times.py
...5from backend.calculate_charge import format_times6TODAY = datetime.today()7TOMORROW = datetime.today() + timedelta(days=1)8def test_format_regular_first_leg():9 formatted = format_times('18:00')10 assert(formatted == TODAY.replace(hour=18, minute=0, second=0, microsecond=0))11def test_format_regular_last_leg():12 formatted = format_times('04:00')13 assert(formatted == TOMORROW.replace(hour=4, minute=0, second=0, microsecond=0))14def test_format_none():15 formatted = format_times(None)...
Check out the latest blogs from LambdaTest on this topic:
In recent times, many web applications have been ported to mobile platforms, and mobile applications are also created to support businesses. However, Android and iOS are the major platforms because many people use smartphones compared to desktops for accessing web applications.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
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!!