- import requests
- import subprocess
- # URLs for various actions
- select_options_url = 'https://toolkit.tesco.com/partner/reports/select_options'
- download_report_url = 'https://toolkit.tesco.com/partner/reports/download_report'
- # Define options for each category/subcategory
- Country = ['UK', 'ROI']
- Report_type = ['Sales_and_stock', 'Range_conformance', 'Promotional_funding', 'Auto_sales_out_retro_deals', 'Fulfilment_fee', 'Performance_summary', 'Cost_price_amendments', 'Purchase_order_amendments']
- Product_subgroup = ['All_product_subgroups']
- Products = ['All_products']
- 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']
- time_periods = ['Last full week (Wk 08)']
- # Iterate over combinations of options
- for country in Country:
- for report_type in Report_type:
- for product_subgroup in Product_subgroup:
- for product in Products:
- for view in View:
- for time_period in time_periods:
- # Send request to select options
- options_data = {
- 'Country': country,
- 'Report_type': report_type,
- 'product_subgroup': product_subgroup,
- 'product': product,
- 'view': view,
- 'time_period': time_period
- }
- response_options = requests.post(select_options_url, data=options_data)
- # Check response if needed
- # Simulate clicking "Download Report" button
- response_download = requests.get(download_report_url)
- # Check if download request was successful
- if response_download.status_code == 200:
- # Save the downloaded report to a local file
- with open('report.xlsx', 'wb') as f:
- f.write(response_download.content)
- print("Report downloaded successfully.")
- # Copy the local file to DBFS
- subprocess.run(['databricks', 'fs', 'cp', 'report.xlsx', '/mnt/dbfs/report.xlsx'])
- print("Report saved to DBFS successfully.")
- else:
- print("Failed to download report. Status code:", response_download.status_code)
[text] H
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: