Python Sample automation code wanted (I'm learning automation) Thanks

can someone provide sample Python automation code please? Thanks
I’m trying to learn task automation using python

1 Like

Hi and welcome to the forum!

Can you explain what it is that you want to automate? Automation is a huge topic and covers many different areas.

Also, if you were looking to ask ChatGPT this question you can do so by visiting https://chat.openai.com


You provided 0 context to what you are looking for… So I had one of my bots write it lol…

import requests

def send_email(api_key, recipient, subject, message):
    endpoint = "https://api.openai.com/v1/engines/davinci-codex/completions"

    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    data = {
        "prompt": f"Send an email to {recipient} with subject '{subject}':\n\n{message}",
        "max_tokens": 100,
        "temperature": 0.7,
        "top_p": 1.0,
        "n": 1
    }

    response = requests.post(endpoint, json=data, headers=headers)
    response_json = response.json()

    if 'choices' in response_json:
        completion = response_json['choices'][0]['text'].strip()
        print(f"Email sent successfully:\n{completion}")
    elif 'error' in response_json:
        print(f"Error encountered: {response_json['error']['message']}")
    else:
        print("Unknown error occurred while sending email.")

# Define your API key here
api_key = "<YOUR_API_KEY>"

# Define your recipients and their corresponding messages here
recipients = {
    "recipient1@example.com": "Hey, just wanted to say hello!",
    "recipient2@example.com": "Here's an important update..."
}

# Iterate through recipients and send emails
for recipient, message in recipients.items():
    subject = "Automated Email"
    send_email(api_key, recipient, subject, message)
1 Like