This Python script allows you to fetch and download the Gravatar image of a user based on their email address. The image is saved to a specified directory.
- Fetches Gravatar images based on the email address.
- Supports saving the image to a custom directory.
- Automatically creates the directory if it does not exist.
- Utilizes the MD5 hash of the email to access the Gravatar API.
Before running the script, make sure you have Python installed. Additionally, you'll need to install the requests library. You can install it using pip:
pip install requestsTo use the script, pass the email as an argument. You can also specify the directory where the image will be saved.
To fetch the Gravatar image and save it in the default ./pictures directory:
python gravatar.py user@domain.tldYou can specify a different directory to save the image using the --save-dir option:
python gravatar.py user@domain.tld --save-dir ./my-directoryIf the directory does not exist, it will be created automatically.
email: The email address of the user for which to fetch the Gravatar image.--save-dir: (Optional) The directory where the Gravatar image will be saved. The default is./pictures.
python gravatar.py johndoe@example.com --save-dir ./avatarsThis command will fetch the Gravatar image for johndoe@example.com and save it in the ./avatars directory.
- The email address is stripped of extra spaces and converted to lowercase.
- An MD5 hash of the email is created.
- The script constructs the Gravatar URL using the hashed email.
- A GET request is sent to the Gravatar API to retrieve the image.
- The image is saved to the specified directory with the name based on the MD5 hash of the email.
This project is licensed under the MIT License.