[text] H

Viewer

  1. import requests
  2.  
  3. # Function to download the file
  4. def download_file(url, filename):
  5.     with open(filename, 'wb') as f:
  6.         response = requests.get(url)
  7.         f.write(response.content)
  8.  
  9. # URL to the endpoint that provides details of the file
  10. details_url = "https://toolkit.tesco.com/partner/reports/api/v1/generated-reports-v2?pageNumber=0&pageSize=18"
  11.  
  12. # Making a request to get the report details
  13. response = requests.get(details_url)
  14.  
  15. # Assuming the response contains the necessary details, including the URLs of the files
  16. # Extracting the URLs of the files from the response JSON
  17. report_details = response.json()
  18.  
  19. # Find the report with the latest createdOn timestamp
  20. latest_report = max(report_details['reports'], key=lambda x: x['createdOn'])
  21.  
  22. # Extract the URL of the CSV file with the latest createdOn timestamp
  23. csv_url = latest_report['reportName']
  24.  
  25. # Download the CSV file
  26. download_file(csv_url, "/dbfs/path/to/save/latest_sales_and_stock_mapping.csv")
  27.  
  28. print("Latest file saved to DBFS successfully!")

Editor

You can edit this paste and save as new:


File Description
  • H
  • Paste Code
  • 29 Apr-2024
  • 1.02 Kb
You can Share it: