File size: 2,508 Bytes
1e66e59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import pandas as pd

import requests
import json
from datetime import datetime, timedelta

def get_rainfall_day(date_time, location):
    # Replace this with your logic to fetch rainfall data for a specific date and time in the given location
    print(f"Fetching rainfall data for {date_time} in {location}")

def loop_through_dates(start_date, end_date, location):
    date_format = "%Y-%m-%d %H-%M-%S"  # Define your date format
    current_date = datetime.strptime(start_date, date_format)
    end_date = datetime.strptime(end_date, date_format)

    while current_date <= end_date:
        # Invoke the method for each date
        get_rainfall_day(current_date.strftime(date_format), location)
        current_date += timedelta(days=1)  # Increment date by 1 day

def get_rainfall_day(date,filename):
    url = "https://www.chennaifloodsdss.in/Master/GetRainfallBasedondistrict"
    params = {"district":filename, "datetime": date}
    response = requests.request("GET", url, params=params)
    data = json.loads(json.loads(response.text))
    if data not in ("", [], None):
        with open("data/" + filename + "_" + date + ".json", 'w') as file:
            json.dump(data, file, indent=4)

def merge_data():

    # Folder containing JSON files
    folder_path = './data'

    # List to store individual DataFrames
    data_frames = []

    # Loop through each file in the folder
    for filename in os.listdir(folder_path):
        if filename.endswith('.json'):
            file_path = os.path.join(folder_path, filename)

            # Read JSON file into a DataFrame
            with open(file_path, 'r') as file:
                json_content = pd.read_json(file)
                data_frames.append(json_content)

    # Concatenate all DataFrames into a single DataFrame
    combined_df = pd.concat(data_frames, ignore_index=True)

    # Export combined DataFrame to a single JSON file
    combined_json_file = 'combined_data.json'
    combined_df.to_json(combined_json_file, orient='records')

    print(f"Combined data exported to '{combined_json_file}'")



def main():
    # start_date = "2021-11-03 09-30-00"
    # end_date = "2023-12-12 09-30-00"
    start_date = "2022-11-03 09-30-00"
    end_date = "2023-11-03 09-30-00"


    # locations = ["Kancheepuram", "Ranipet", "Chengalpattu", "Tiruvallur"]
    # location = "Chennai"
    # for location in locations:
    #     loop_through_dates(start_date, end_date, location)
    merge_data()


if __name__ == "__main__":
    main()