[text] H

Viewer

  1. import requests
  2. import subprocess
  3.  
  4. # URLs for various actions
  5. select_options_url = 'https://toolkit.tesco.com/partner/reports/select_options'
  6. download_report_url = 'https://toolkit.tesco.com/partner/reports/download_report'
  7.  
  8. # Define options for each category/subcategory
  9. Country = ['UK', 'ROI']
  10. Report_type = ['Sales_and_stock', 'Range_conformance', 'Promotional_funding', 'Auto_sales_out_retro_deals', 'Fulfilment_fee', 'Performance_summary', 'Cost_price_amendments', 'Purchase_order_amendments']
  11. Product_subgroup = ['All_product_subgroups']
  12. Products = ['All_products']
  13. View = ['TPNB_Total_sales', 'TPNB_Sales_x_store', 'TPNB_Sales_x_store_format', 'TPNB_Sales_x_DC', 'Product_subgroup_Total_sales', 'Stores_Total_sales', 'Store_Format_Total_sales']
  14. time_periods = ['Last full week (Wk 08)']
  15.  
  16. # Iterate over combinations of options
  17. for country in Country:
  18.     for report_type in Report_type:
  19.         for product_subgroup in Product_subgroup:
  20.             for product in Products:
  21.                 for view in View:
  22.                     for time_period in time_periods:
  23.                         # Send request to select options
  24.                         options_data = {
  25.                             'Country': country,
  26.                             'Report_type': report_type,
  27.                             'product_subgroup': product_subgroup,
  28.                             'product': product,
  29.                             'view': view,
  30.                             'time_period': time_period
  31.                         }
  32.                         response_options = requests.post(select_options_url, data=options_data)
  33.                         # Check response if needed
  34.  
  35.                         # Simulate clicking "Download Report" button
  36.                         response_download = requests.get(download_report_url)
  37.  
  38.                         # Check if download request was successful
  39.                         if response_download.status_code == 200:
  40.                             # Save the downloaded report to a local file
  41.                             with open('report.xlsx', 'wb') as f:
  42.                                 f.write(response_download.content)
  43.                             print("Report downloaded successfully.")
  44.  
  45.                             # Copy the local file to DBFS
  46.                             subprocess.run(['databricks', 'fs', 'cp', 'report.xlsx', '/mnt/dbfs/report.xlsx'])
  47.                             print("Report saved to DBFS successfully.")
  48.                         else:
  49.                             print("Failed to download report. Status code:", response_download.status_code)

Editor

You can edit this paste and save as new:


File Description
  • H
  • Paste Code
  • 25 Apr-2024
  • 2.57 Kb
You can Share it: