June 06, 2022

Automating Parsehub to Sealfit to Things Todo


Moriondo, the first Expresso Machine

Since I'm cheap and I didn't want to buy the Alfred Power Pack for this, I did it myself in Python and Parsehub, a free point to click web scraper. First thing is to download and install Parsehub for Mac. Go through the tutorial and get it able to log into a website and select the content. Export to CSV. Set it to kick off a script. Create the following small python script program in VS Code. Cleanup of the data can be done with other tools in the pipeline like the regular expression as shown.

import re
import smtplib
from email.message import EmailMessage

msg = EmailMessage()

with open("/Users/you/Downloads/run_results.csv", "r", encoding='utf-8') as f:
s = f.read()
message = re.search(r'(?s)Baseline:([\S\s]*)Leave', s).group(1)
msg.set_content(message)
from datetime import datetime
mydate = datetime.today().strftime('%Y-%m-%d')

msg['Subject'] = 'Sealfit '+mydate
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"

# Send the message via our own SMTP server.
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("[email protected]", "YourAppPassword")
server.send_message(msg)
server.quit()

This will automate web scraping almost any website with a point to click interface and then sending the file to Things ToDo automatically. 

No comments:

Post a Comment