I've subscribe to a food delivery service called HelloFresh (referral link for free trial). They send recipes and ingredients every week for my wife and I to turn into meals. It's a great service because I come in contact with ingredients I typically wouldn't pick up and we eat fresh and healthy meals at least 3 times a week. Also on the rare occasion when some ingredients are missing or spoiled, we get to play Chopped like on Food Network!

Over the past few weeks, I have had some problems with deliveries. It is frustrating because it's not cheap and the grocery shopping for the week is done with 3 full meals from HelloFresh in the equation. The problem with deliveries has been that the food arrives late and in yesterday's delivery, it didn't even arrive until a day late.

This got me thinking. I know a few folks who personally emailed CEOs of companies that they've had grievances and suggestions for and had pretty decent responses. With that fresh in my head I thought it would be a perfect chance to reach out to the HelloFresh team with not only a complaint, but a suggestion that can help quality control. I originally wrote this long letter saying they have a guy write a script that can parse the pick up time and the delivery time and see if that data is useful. But after typing it all out, it looked simple enough and figured, I may as well brush up on my Python and show them what I mean.

HF_Stats.py was born as well as the first actual post on this blog in years.

import requests
import re
import urllib.request
import datetime
from datetime import datetime

### Hello Fresh has a u, id, and e strings in the URL from their emails. Removing for privacy.
hfu = 'REMOVED'
hfid = 'REMOVED'
hfe = 'REMOVED'


## Buld HF Tracking URL with the different strings
hf_url = 'http://hellofresh.us7.list-manage1.com/track/click?u='+hfu+'&id='+hfid+'&e='+hfe

req = urllib.request.Request(hf_url)
resp = urllib.request.urlopen(req)
respData = resp.read()

fullEx = '(Picked Up|Delivered).*?(\d{2}\/\d{2}\/\d{4}\s+(\d{1}|\d{2})\:\d{2}\s(A|P)M)'
paragraphs = re.findall(r''+fullEx,str(respData))

## Time Object Created
c_Event = paragraphs[0][0]
c_Time = paragraphs[0][1]
print ("Created", c_Time)

## Time Object Picked up by Shipping Company
p_Event = paragraphs[1][0]
p_Time = paragraphs[1][1]
print (p_Event, p_Time)

## Time Delivered
d_Event = paragraphs[2][0]
d_Time = paragraphs[2][1]
print (d_Event, d_Time)

## Converting strings to find total hours between creation,arrival and delivery
t_Format = '%m/%d/%Y  %I:%M %p'
cT = datetime.strptime(c_Time, t_Format)
pT = datetime.strptime(p_Time, t_Format)
dT = datetime.strptime(d_Time, t_Format)
t_Delta = dT - pT
h_Delta = (t_Delta.days * 24)+(t_Delta.seconds/60/60 )

## Final Print Statement
print ('Hours taken from pickup to delivery', h_Delta)

In my case I found the following:

Created 02/24/2017 2:50 PM
Picked Up 02/26/2017 9:07 PM
Delivered 02/28/2017 1:47 PM

Assuming that the delivery was not refrigerated from Pickup to Delivery the entire time, the box of food was not refrigerated for 40.67 hours.
Assuming that the delivery was not refrigerated from Creation on the shipping page to Delivery, the box of food was no refrigerated for 94.95 hours.

At the end of the day, my wife and I love HelloFresh. We hope that they look at this or already look at these numbers and work on delivery times to ensure fresh food is delivered.

Thanks for reading.