- import requests
- import os
- # Import the Databricks API for DBFS
- from dbutils import DBUtils
- # URL for the main action
- url = 'https://toolkit.tesco.com/partner/reports/'
- # 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_period = ['Last full week (Wk 08)']
- # Function to prompt user to select an option
- def select_option(options, prompt):
- print(prompt)
- for i, option in enumerate(options):
- print(f"{i + 1}. {option}")
- while True:
- choice = input("Enter your choice (1-{}): ".format(len(options)))
- if choice.isdigit() and 1 <= int(choice) <= len(options):
- return options[int(choice) - 1]
- else:
- print("Invalid choice. Please enter a number between 1 and {}.".format(len(options)))
- # Prompt user to select options
- country = select_option(Country, "Select country:")
- report_type = select_option(Report_type, "Select report type:")
- product_subgroup = select_option(Product_subgroup, "Select product subgroup:")
- product = select_option(Products, "Select product:")
- view = select_option(View, "Select view:")
- time_period = select_option(Time_period, "Select time period:")
- # 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
- }
- try:
- response = requests.get(url)#, params=options_data)
- response.raise_for_status() # Raise exception for 4xx or 5xx errors
- # Process the response as needed
- print("Options selected:", options_data)
- # Save the response content to a file with .xlsx extension
- file_name = f"{country}_{report_type}_{product}_{view}_{time_period}.xlsx"
- file_path = os.path.join("/dbfs", "path", "to", "save", file_name)
- with open(file_path, "wb") as f:
- f.write(response.content)
- # Print the file path where the report is saved
- print("Report saved to DBFS:", file_path)
- except requests.exceptions.HTTPError as err:
- print("An error occurred:", err)
[text] B
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: