Best Python code snippet using autotest_python
app.py
Source:app.py
...8socketio = SocketIO(app, cors_allowed_origins='*', engineio_logger=True)9@app.route('/')10def serve_static_index():11 return send_from_directory('../../client/todo_task_app/public', 'index.html')12def get_status_counts():13 counts = {}14 counts['New'] = todo.count_documents({'status': 'new'})15 counts['Progress'] = todo.count_documents({'status': 'progressing'})16 counts['Completed'] = todo.count_documents({'status': 'completed'})17 counts['Deleted'] = todo.count_documents({'delete': 'yes'})18 return counts19def get_counts():20 counts = {}21 counts['Total'] = 022 counts['ToStudy'] = todo.count_documents({'type': 'study'})23 counts['Travelling'] = todo.count_documents({'type': 'travelling'})24 counts['Shopping'] = todo.count_documents({'type': 'shopping'})25 counts['Total'] = sum(counts.values())26 return counts27@socketio.on('connect')28def test_connect():29 print('CONNECT EVENT happened...')30 emit('Success', {'data': 'Connected'})31@socketio.on('FetchRecords')32def fetch_all_records():33 data = []34 records = todo.find({'delete': {'$eq': 'no'}}, {35 '_id': 0}).sort('item_id', -1)36 for i in records:37 data.append(i)38 # records = todo.find({'delete': 'yes'}, {'_id': 0})39 # for i in records:40 # data.append(i)41 response = {'code': 200, 'records': data,42 'Counts': get_counts(), 'statusCounts': get_status_counts()}43 emit('SendingRecords', response, broadcast=True)44def notify(text):45 emit('Notify', text, broadcast=True)46# ["AddRecord",{"value":"Paris","type":"travelling"}]47@socketio.on('AddRecord')48def add_record(data):49 # print('adding', data)50 cnt = todo.count_documents({})51 todo.insert_one(52 {'item_id': cnt+1, 'name': data['value'], 'type': data['type'], 'status': 'new', 'delete': 'no'})53 # socketio.emit('ChangeData')54 notify({'response': 'One Data Added'})55 emit('ChangeData', broadcast=True)56@socketio.on('MarkAsComplete')...
get_banner_history_data.py
Source:get_banner_history_data.py
...31 conf = SparkConf()32 conf.set("spark.app.name", 'banner history %s' % args.campaign)33 sc = SparkContext(conf=conf)34 donor_data, sample_data = get_campaign_data(sc, args.campaign, args.banner_reg, args.start, args.stop)35 sample_status_counts = get_status_counts(sample_data)36 def mapping(count):37 if count <=5:38 return '0' + str(count)39 elif count < 11:40 return '06-10'41 elif count < 16:42 return '11-15'43 else:44 return '16+'45 sample_impression_counts = get_previous_impression_counts(sample_data, mapping = mapping, hour = True)46 donor_impression_counts = get_previous_impression_counts(donor_data, mapping = mapping, hour = True)47 pickle.dump( sample_status_counts, open( "sample_status_counts_%s" % campaign, "wb" ) )48 pickle.dump( sample_impression_counts, open( "sample_impression_counts_%s" % campaign, "wb" ) )49 pickle.dump( donor_impression_counts, open( "donor_impression_counts_%s" % campaign, "wb" ) )...
update_stats.py
Source:update_stats.py
...16 The host option has been set up so it's always safe to just toss that17 parameter in.18 """19 mongo_access = MongoAccess(options['host'])...
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!!