Best Python code snippet using localstack_python
server.py
Source:server.py  
...20	publishing_time = db.Column(db.DateTime)21	def __repr__(self):22		return f'<id = {self.id}, title = {self.title}, publishing_time = {self.publishing_time}>'23api_keys = []24def import_api_keys():25	file1 = open('keys.txt', 'r')26	Lines = file1.readlines()27	for line in Lines:28		api_keys.append(line)29# Function to Call The Youtube API30# And Fetch The Data31def YT_API():32	# Youtube Search URL to send the Request33	search_url = 'https://www.googleapis.com/youtube/v3/search'34	time_now = datetime.now()35	last_req_time = time_now36	req_time = last_req_time.replace(microsecond=0).isoformat()+'Z'37	38	for api_key in api_keys:39		# Youtube API Key40		YOUTUBE_API_KEY = api_key41		# Parameters to Be Passed with the Request42		search_params = {43			'key' : YOUTUBE_API_KEY,44			'q' : 'cricket',45			'part' :'snippet',46			'maxResults' : 50,47			'order' : 'date',48			'type' : 'video',49			'publishedAfter' : req_time50		}51		# Making the Request52		r = requests.get(search_url, params = search_params)53		if r.json().get('items'):54			results = r.json()['items']55			for result in results:56				video_title = result['snippet']['title']57				if(result['id']['videoId'] in vidIds):58					continue59				video_description = result['snippet']['description']60				video_thumbnail_url = result['snippet']['thumbnails']['medium']['url']61				video_publishing_time = result['snippet']['publishedAt']62				vidIds.add(result['id']['videoId'])63				video_publishing_time = datetime.strptime(video_publishing_time, '%Y-%m-%dT%H:%M:%SZ')64				new_video = Video(title = video_title, description = video_description, thumbnail_url = video_thumbnail_url, publishing_time = video_publishing_time)65				try:66					db.session.add(new_video)67					db.session.commit()68				except:69					print('There was an Issue in Adding Video to the DataBase')70			break71# Decorator for Routing Initial GET Request72@app.route('/', methods = ['GET'])73def index():74	page_no = 175	page_size = 1076	if request.args.get('page_no'):77		page_no = int(request.args['page_no'])78	if request.args.get('page_size'):79		page_size = int(request.args['page_size'])80	videos = (81		Video.query82		.order_by(Video83		.publishing_time.desc())84		.limit(page_size)85		.offset((page_no - 1) * page_size)86		.all()87	)88	ret = {"data" : []}89	for vid in videos:90		ret["data"].append({91			'title' : vid.title,92			'description' : vid.description,93			'thumbnail_url' : vid.thumbnail_url,94			'publishing_time' : vid.publishing_time,95			'id' : vid.id96		})97	return ret98# Decorator for Routing Search Request99@app.route('/search', methods = ['GET'])100def search():101	search_txt = set(request.args['q'].split())102	print(search_txt)103	videos = (104		Video.query105		.order_by(Video106		.publishing_time.desc())107		.all()108	)109	ret = {"data" : []}110	for vid in videos:111		if (search_txt.intersection(set(vid.title.split())) or search_txt.intersection(set(vid.description.split()))):112			ret["data"].append({113				'title' : vid.title,114				'description' : vid.description,115				'thumbnail_url' : vid.thumbnail_url,116				'publishing_time' : vid.publishing_time,117				'id' : vid.id118			})119	return ret120if __name__ == "__main__":121	import_api_keys()122	YT_API()123	scheduler = BackgroundScheduler()124	scheduler.add_job(YT_API, 'interval', minutes = 1)125	scheduler.start()126	atexit.register(lambda: scheduler.shutdown())...keygenerator.py
Source:keygenerator.py  
...36        del student["ID"]37        del student["CLASS"]38        writer.writerow(student)39apigateway = boto3.client('apigateway')40response = apigateway.import_api_keys(41    body=open(abs_out_file_path, 'r'),42    format='csv',43    failOnWarnings=True44)45print(response["ids"])46for api_key_id in response["ids"]:47    response = apigateway.create_usage_plan_key(48        usagePlanId=usageplan_ids,49        keyId=api_key_id,50        keyType='API_KEY'51    )...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!!
