Demo entry 6789031



Submitted by anonymous on Apr 24, 2019 at 15:58
Language: Python 3. Code size: 1.5 kB.

import requests
import json
import time

def request_data(file_name):
    with open(file_name, 'w', encoding='utf-8') as my_jason_data:

        num_of_times_for_collecting_data = 100
        json_counter = 0
        cities = ['budapest', 'dublin', 'geneva', 'hamburg', 'lisbon', 'london', 'naples', 'nice', 'oslo', 'rome', 'paris', 'sofia', 'verona', 'aarhus', 'athens', 'antwerp', 'bern', 'bari', 'basel', 'amsterdam', 'atlanta', 'austin', 'boston','budapest', 'dublin', 'geneva', 'hamburg', 'lisbon', 'london', 'naples', 'nice', 'oslo', 'rome', 'paris', 'sofia', 'verona', 'aarhus', 'toronto', 'dubai', 'adelaide', 'paris', 'sofia', 'verona', 'aarhus', 'athens', 'antwerp', 'bern', 'bari', 'basel', 'amsterdam']  

        for n in range(num_of_times_for_collecting_data+1):
            for city in cities:
                start_time = time.time()

                response = requests.get("" + city + "&apiKey=nwkneh4q6xz8fw6yjwacvqfe")
                content = response.json()

                run_time = time.time() - start_time

                json_counter += 1

                json_data = json.dumps(content)
                print(json_data, file=my_jason_data)
                print(f'data collection rate for Json number {json_counter} is:\t{run_time}\n')
    print('Finished! your data is ready to be explored in your text file, enjoy.')

request_data('C:/Users/yafitat/Desktop/Private/MBA/Data science/Jason_dataset.txt')

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).