Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Question #8

Open
RobertCrom opened this issue Nov 20, 2023 · 2 comments
Open

Python Question #8

RobertCrom opened this issue Nov 20, 2023 · 2 comments

Comments

@RobertCrom
Copy link

So I am trying to use Kameleo in my python script that goes to a website and logs into it. I am saving the profile and then loading back when executing the script next time. I want a functionality check if the profile was deleted from Kameleo during the last execution of the script and if it still exists then the script will first delete it and then load it again...

@JonathanR25
Copy link

Try to load the profile with a try-catch statement. If you catch an exception you can check for the error. If the returned HTTP Status Code is 409 (Conflict - already loaded), then you can delete it and load again.
Something like this:

    client.load_profile("YOUR_PATH")
except ProblemResponseException as e:
    if (e.status_code == 409)
         # delete and reload

@HuBeilxy
Copy link

To check if a configuration file has been deleted from Kameleo during the last script execution, you can perform the following steps:

  1. Retrieve the list of available configurations from Kameleo using the Kameleo API or command-line interface.
  2. Check if the configuration file that you are looking for is present in the list.
  3. If the configuration file is found, delete it using the appropriate API or command-line command.
  4. Reload the configuration file for further use in your script.

Here is an example to perform these steps using the Kameleo API in Python:

import requests

def check_and_delete_configuration(configuration_id):
    # Retrieve the list of available configurations
    response = requests.get('https://kameleo.local/api/v1/configurations')
    configurations = response.json()

    # Check if the desired configuration is present
    for config in configurations:
        if config['id'] == configuration_id:
            # Delete the configuration
            requests.delete(f'https://kameleo.local/api/v1/configurations/{configuration_id}')
            print('Configuration deleted.')

            # Reload the configuration for further use
            reload_configuration(configuration_id)
            break
    else:
        print('Configuration not found.')

def reload_configuration(configuration_id):
    # Your code to reload the configuration file goes here
    pass

# Call the function with the desired configuration ID
check_and_delete_configuration('12345')

Make sure to replace 'https://kameleo.local/api/v1' with the appropriate URL of your Kameleo instance. Also, implement the reload_configuration function according to your specific requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants