Best Python code snippet using yandex-tank
indeed_scraper OLD.py
Source:indeed_scraper OLD.py  
...117        website = USA_DOMAIN + '/jobs?q=' + \118            search_keywords + '&l=' + city + '%2C+' + state + '&radius=100'119    print(website)120    return website121def get_job_summary(urls):122    job_summary_df = pd.DataFrame(columns=SUMMARY_COLUMNS)123    # summary_to_csv write to the file simultaneously124    # summary_to_csv = pd.DataFrame(columns=SUMMARY_COLUMNS)125    # first_row = True126    jobcard_jks = []127    print('get_job_summary started...')128    options = Options()129    options.add_experimental_option("detach", True)130    #options.add_argument("--incognito")131    driver = webdriver.Chrome(132        options=options, executable_path=CHROME_PATH)133    driver.implicitly_wait(1)134    for url in urls:135        _flag = True136        next_url_counter = 0137        driver.implicitly_wait(1)138        while(_flag):139            time.sleep(1)140            new_site = url + '&start=' + str(next_url_counter)141            # print(new_site)142            driver.get(new_site)143            # can not have space in by_class_name. Must be one word144            jobcards = driver.find_elements_by_class_name(145                'jobsearch-SerpJobCard')146            job_check = 0147            for jobcard in jobcards:148                time.sleep(1)149                # summary_to_csv = summary_to_csv.head(0)  # Reset150                jobcard_jk = jobcard.get_attribute('data-jk')151                if jobcard_jk not in jobcard_jks:152                    jobcard_jks.append(jobcard_jk)153                    jobcard_html = BeautifulSoup(jobcard.get_attribute(154                        'innerHTML'), 'html.parser')155                    try:156                        location = jobcard_html.find(class_="location").get_text()157                        loc = location.split(',')158                        if len(loc) > 1:159                            city = loc[0]160                            state = loc[1].strip().split(' ')[0]161                        else:162                            city = 'None'163                            state = 'None'164                    except:165                        location = 'None'166                        city = 'None'167                        state = 'None'168                    try:169                        company = jobcard_html.find(class_="company").text.replace(170                            "\n", "").strip()171                    except:172                        company = 'None'173                    try:174                        salary = jobcard_html.find(class_="salary").text.replace(175                            "\n", "").strip()176                    except:177                        salary = 'None'178                    try:179                        rating = jobcard_html.find(class_="ratingsContent").text.replace(180                            "\n", "").strip()181                    except:182                        rating = 'None'183                    try:184                        remote_work = jobcard_html.find(class_="remote").text.replace(185                            "\n", "").strip()186                    except:187                        remote_work = 'None'188                    try:189                        date_posted = jobcard_html.find(class_="date").text.replace(190                            "\n", "").strip()191                    except:192                        date_posted = 'None'193                    if CANADA_DOMAIN in new_site:194                        country = 'Canada'195                    elif USA_DOMAIN in new_site:196                        country = 'USA'197                    else:198                        country = 'None'199                    job_summary_df = job_summary_df.append({"Primary_Key": jobcard_jk, 'Location': location, 'City': city, 'State': state, 'Country': country, "Company": company, "Salary": salary,200                                                            "Ratings": rating, "Remote_work": remote_work, "Date_posted": date_posted201                                                            }, ignore_index=True)202                    # summary_to_csv = summary_to_csv.append({"Primary_Key": jobcard_jk, 'Location': location, 'Country': country, "Company": company, "Salary": salary,203                    #                                         "Ratings": rating, "Remote_work": remote_work, "Date_posted": date_posted204                    #                                         }, ignore_index=True)205                    # if first_row:206                    #     summary_to_csv.to_csv('summary-'+FILE_NAME_END, mode='a',207                    #                           index=False)208                    #     first_row = False209                    # else:210                    #     summary_to_csv.to_csv('summary-'+FILE_NAME_END, mode='a',211                    #                           header=False, index=False)212                    job_check += 1213                    # print("Got these many results:", job_summary_df.shape)214            # Exit if no new jobs found215            if job_check == 0:216                _flag = False217            next_url_counter += 10218    driver.close()219    print('get_job_summary ended...')220    return jobcard_jks, job_summary_df221def get_job_description(url_jks):222    counter = 0223    job_description_df = pd.DataFrame(columns=DESCRIPTION_COLUMNS)224    # description_to_csv write to the file simultaneously225    # description_to_csv = pd.DataFrame(columns=DESCRIPTION_COLUMNS)226    # first_row = True227    print('get_job_description started...')228    for jk in url_jks:229        time.sleep(1)230        # description_to_csv = description_to_csv.head(0) # Reset231        full_link = BASE_JOB_URL + jk232        # print(full_link)233        source = requests.get(full_link).text234        job_page = BeautifulSoup(source, 'html.parser')235        # print(job_page.prettify())236        try:237            description = job_page.find(238                'div', id='jobDescriptionText').get_text("|", strip=True)239        except:240            description = 'None'241        try:242            title = job_page.find(243                'h1', class_='jobsearch-JobInfoHeader-title').get_text("|", strip=True)244            pass245        except:246            title = 'None'247        job_description_df = job_description_df.append({"Primary_Key": jk, 'Title': title,248                                                        "Full_Description": description}, ignore_index=True)249        counter += 1250        if (counter % 50 == 0):251            print("At job:", counter)252        # description_to_csv = description_to_csv.append({"Primary_Key": jk, 'Title': title,253        #                                                 "Full_Description": description}, ignore_index=True)254        # if first_row:255        #     description_to_csv.to_csv('description-'+FILE_NAME_END, mode='a',256        #                               index=False)257        #     first_row = False258        # else:259        #     description_to_csv.to_csv('description-'+FILE_NAME_END, mode='a',260        #                               header=False, index=False)261    print('get_job_description ended...')262    return job_description_df263def merge_dataframes(df1, df2):264    df1_columns = list(df1.columns.values)265    df2_columns = list(df2.columns.values)266    common_columns = list(set(df1_columns) & set(df2_columns))267    Key = common_columns[0]268    df3 = df1.merge(df2, how='inner', on=Key)269    df3 = df3[ALL_COLUMNS]270    return df3271def get_total_num_jobs(job_site):272    source = requests.get(job_site).text273    page = BeautifulSoup(source, 'html.parser')274    count_div = page.find(id='searchCountPages')275    unpack_div_string = count_div.contents[0]276    unpack_div_string = unpack_div_string.strip()277    unpack_div_list = unpack_div_string.split(" ")278    if ',' in unpack_div_list[3]:279        numbers = unpack_div_list[3].split(",")280        number = ''.join(numbers)281        num_jobs = int(number)282    elif int(unpack_div_list[3]):283        num_jobs = int(unpack_div_list[3])284    return num_jobs285def open_browser(url):286    # Check chrome version: top right corner(3dots)-> help -> about chrome287    # keep the broswer open288    chrome_options = Options()289    chrome_options.add_experimental_option("detach", True)290    driver = webdriver.Chrome(291        chrome_options=chrome_options, executable_path=CHROME_PATH)292    driver.get(url)293def create_urls():294    urls = []295    # Validate Radius296    if 'RADIUS' not in globals():297        sys.exit("Please define Radius!")298    else:299        if RADIUS not in RADIUS_OPTIONS:300            sys.exit("Please define Radius Correctly!")301    # Validate Date Posted302    if 'DATE_POSTED' not in globals():303        sys.exit("Please define DATE POSTED!")304    else:305        if DATE_POSTED not in DATE_POSTED_OPTIONS:306            sys.exit("Please define DATE POSTED Correctly!")307    # Create Canadian URLs308    for location in CANADIAN_LIST:309        website = CANADA_DOMAIN + '/jobs?q=' + JOB_TITLE + \310            '&l=' + location[0] + \311            '%2C+' + location[1] + \312            '&radius=' + RADIUS + \313            '&fromage=' + DATE_POSTED + \314            '&sort=date'315         316        urls.append(website)317    # Create American URLs318    for location in AMERICAN_LIST:319        website = USA_DOMAIN + '/jobs?q=' + JOB_TITLE + \320            '&l=' + location[0] + \321            '%2C+' + location[1] + \322            '&radius=' + RADIUS + \323            'fromage=' + DATE_POSTED + \324            '&sort=date'325        urls.append(website)326    return urls327def create_csv_upload_gcp(dataset, source_folder, filename):328    # create csv329    dataset.to_csv(source_folder + filename, index=False)330    # upload to Google Cloud Storage331    storage_client = storage.Client.from_service_account_json(SERVICE_KEY)332    # Create a Bucket Object333    bucket = storage_client.get_bucket(BUCKET_NAME)334    blob = bucket.blob(DESTINATION_BLOB_NAME)335    blob.upload_from_filename(source_folder + filename)336def main():337    start_time_main = time.time()338    firstpage_urls = create_urls()339    pprint(firstpage_urls)340    jobcard_jks, job_summary_df = get_job_summary(firstpage_urls)341    print("get_job_summary time: %s minutes" %342          ((time.time() - start_time_main)/60))343    middle_time_main = time.time()344    job_description_df = get_job_description(jobcard_jks)345    print("get_job_description time: %s minutes" %346          ((time.time() - middle_time_main)/60))347    # TODO:348    # check if file exist and only add the new rows349    final_df = merge_dataframes(job_summary_df, job_description_df)350    create_csv_upload_gcp(final_df, DATA_FOLDER, FILE_NAME)351    print('End!')352    # for testing353    # number_of_jobs = get_total_num_jobs(main_url)354    # print('Number of Jobs:', number_of_jobs)355    # open_browser(main_url)356    # job_url_jks, job_summary_df = get_job_summary(main_url)357    # job_description_df = get_job_description(job_url_jks)358    # merge_dataframes(job_summary_df, job_description_df, user_input_list)359if __name__ == "__main__":360    start_time = time.time()361    main()...doctorprofileviews.py
Source:doctorprofileviews.py  
1from annoying.decorators import render_to, ajax_request2from annoying.functions import get_object_or_None3from common.models import Profile, Job, Pic4def get_job_summary(job):5    """6    Get some kind of link text associated with the job. Just grab the first7    Pic associated with this job and get it's general description8    """9    ret = None10    pics = Pic.objects.filter(album=job.album).order_by('group')11    for pic in pics:12        if pic.description:13            ret = pic.description14            break15    return ret or "No description available"16@render_to('doctor_profile.html')17def doctor_profile(request, nickname ):18    profile = get_object_or_None(Profile, nickname=nickname)19    if not profile:20        return { 'doctor_exists' : False }21    profile_pic_url = None22    if profile.pic:23        profile_pic_url = profile.pic.get_preview_url()24    jobs = Job.objects.filter(doctor=profile).order_by('created').reverse()25    jobs = [ (j,get_job_summary(j)) for j in jobs if j.album.allow_publicly]26    return {27            'doctor_exists'     : True,28            'nickname'          : nickname,29            'profile_pic_url'   : profile_pic_url,30            'doc_profile_desc'  : profile.doc_profile_desc,31            'jobs'              : jobs,...kube_burner.py
Source:kube_burner.py  
1def get_results(benchmark, es_client):2    pod_latencies = get_pod_latency_results(benchmark, es_client)3    job_summary = get_job_summary(benchmark, es_client)4    return {**pod_latencies, **job_summary}5def get_pod_latency_results(benchmark, es_client):6    query = {7        "query":{ 8            "query_string": {9                "query": f'uuid:"{benchmark["uuid"]}" AND (metricName:"podLatencyQuantilesMeasurement")'10            }11        }12    }13    index = 'ripsaw-kube-burner'14    query_results = es_client.search(index='ripsaw-kube-burner', body=query, size=10000)15    perf_data = {doc['_source']['quantileName']: doc['_source'] for doc in query_results['hits']['hits']}16    17    return perf_data18def get_job_summary(benchmark, es_client):19    query = {20        "query": {21            "query_string": {22                "query": f'uuid:"{benchmark["uuid"]}" AND (metricName:"jobSummary")'23            }24        }25    }26    index = 'ripsaw-kube-burner'27    query_results = es_client.search(index='ripsaw-kube-burner', body=query, size=10000)28    perf_data = {"jobSummary": doc['_source'] for doc in query_results['hits']['hits']}29    ...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!!
