import requests import pandas as pd from datetime import datetime, timedelta def get_historical_data(uid, field_id, date): endpointUrl = "https://us-central1-farmbase-b2f7e.cloudfunctions.net/requestPreviousSatelliteData" bodyObj = { "UID": uid, "FieldID": field_id, "RequestedDate": date, } response = requests.post(endpointUrl, json=bodyObj) print("Status code: ", response.status_code) return response # Function to generate dates def generate_dates(start_year, start_month, end_year, end_month): start_date = datetime(start_year, start_month, 1) end_date = datetime(end_year, end_month, 31) dates = [] current_date = start_date while current_date <= end_date: if current_date.day in [1, 15]: dates.append(current_date.strftime("%Y%m%d")) current_date += timedelta(days=1) return dates filename = "UUID_FieldID_coordinates.xlsx" df3 = pd.read_excel(filename) uid = "ipRHhCOFIDV2pxgg7Nfz1ufZBmV2" # Generate dates for both periods dates_2022_2023 = generate_dates(2022, 7, 2023, 1) dates_2023_2024 = generate_dates(2023, 7, 2024, 1) for index, row in df3.iterrows(): print(row["Field ID"]) field_id = row["Field ID"] for date in dates_2022_2023: get_historical_data(uid, field_id, date) #print(date) for date in dates_2023_2024: get_historical_data(uid, field_id, date) #print(date) #print("\n") #break