1. import schedule
  2. import time
  3. import logging
  4. logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
  5. def run_url_parameter_task(url_params):
  6. """Executes a task based on URL parameters."""
  7. try:
  8. # Access URL parameters (example: get('param1'))
  9. param1 = url_params.get('param1')
  10. param2 = url_params.get('param2')
  11. if param1 and param2:
  12. # Perform the task based on parameters
  13. logging.info(f"Executing task with param1: {param1}, param2: {param2}")
  14. # Replace with your actual task logic
  15. print(f"Task executed with param1: {param1}, param2: {param2}")
  16. else:
  17. logging.warning("Missing required URL parameters.")
  18. except Exception as e:
  19. logging.error(f"Error executing task: {e}")
  20. def schedule_task(interval, url_params):
  21. """Schedules the task to run repeatedly."""
  22. schedule.every(interval).do(run_url_parameter_task, url_params=url_params)
  23. logging.info(f"Task scheduled to run every {interval}")
  24. while True:
  25. schedule.run_pending()
  26. time.sleep(1)
  27. if __name__ == '__main__':
  28. # Example usage:
  29. url_parameters = {'param1': 'value1', 'param2': 'value2'} # Replace with your URL parameters
  30. schedule_task(60, url_parameters) # Schedule to run every 60 seconds

Add your comment