This project automates the process of downloading and forwarding prescription files associated with orders from a Shopify store.
The client needed an automated solution to handle prescription files associated with orders from their Shopify store. Each order contains a link to the prescription file, which is uploaded using the LensAdvisor app. The process involves the following steps:
- An email is received with the order details and a link to the prescription.
- The prescription link sometimes requires a login to access the file.
- The prescription file (PDF, PNG, JPG) needs to be downloaded.
- The downloaded file should be labeled with the order number.
- The labeled file needs to be sent to the supplier via email.
To address the client's needs, a Python script was created to automate the entire process. The solution includes the following components:
- Email Fetching: Using the
imaplib
andemail
libraries to connect to the email server, search for relevant emails, and extract order information and prescription links. - Prescription Link Extraction: Using
BeautifulSoup
to parse the email content and extract the prescription link. - File Downloading: Accessing the LensAdvisor API to download the prescription file.
- Email Sending: Using
smtplib
to send an email with the prescription file attached to the supplier. - Flask Web Interface (Optional): A simple Flask app to manually trigger the script and monitor the process.
- Python: Core scripting language.
- IMAPLIB: For fetching emails.
- BeautifulSoup: For parsing HTML content.
- Requests: For making HTTP requests to the LensAdvisor API.
- SMTPLIB: For sending emails.
- Flask (Optional): For creating a web interface to trigger the script manually.
- AWS EC2: For hosting the script and running it in a scheduled manner using cron jobs.
- An AWS account and EC2 instance.
- A Gmail account with IMAP enabled (or any other email provider with IMAP support).
- Python 3.x installed on the server.
- PuTTY for SSH access to the server (if using Windows).
-
Clone the Repository
git clone https://github.com/yourusername/Shopify-Prescription-Automation.git cd Shopify-Prescription-Automation
2. Set Up a Virtual Environment
python3 -m venv venv source venv/bin/activate
3. Install Dependencies
pip install -r requirements.txt
4. Configure the Script Update the configuration section in prescription_automation.py with your email credentials, LensAdvisor token, and other necessary details.
5. Run the Script
python prescription_automation.py
6. Set Up Automated Execution Add a cron job to run the script at regular intervals (e.g., every 15 minutes):
crontab -e Add the following line:
*/15 * * * * /path/to/your/venv/bin/python /path/to/your/script/prescription_automation.py
Optional: Run the Flask App
python app.py
Access the web interface at http://yourserver:5000/run-script.