import schedule
import time
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def run_url_parameter_task(url_params):
"""Executes a task based on URL parameters."""
try:
# Access URL parameters (example: get('param1'))
param1 = url_params.get('param1')
param2 = url_params.get('param2')
if param1 and param2:
# Perform the task based on parameters
logging.info(f"Executing task with param1: {param1}, param2: {param2}")
# Replace with your actual task logic
print(f"Task executed with param1: {param1}, param2: {param2}")
else:
logging.warning("Missing required URL parameters.")
except Exception as e:
logging.error(f"Error executing task: {e}")
def schedule_task(interval, url_params):
"""Schedules the task to run repeatedly."""
schedule.every(interval).do(run_url_parameter_task, url_params=url_params)
logging.info(f"Task scheduled to run every {interval}")
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
# Example usage:
url_parameters = {'param1': 'value1', 'param2': 'value2'} # Replace with your URL parameters
schedule_task(60, url_parameters) # Schedule to run every 60 seconds
Add your comment