Posts Tagged ‘atwood’
Peter Atwood is a hobbyist who creates limited edition pocket tools and puts them up for sale on his site at Planet Pocket Tool. His tools are fairly popular and being limited are hard to acquire.
Peter posts the sales randomly and the tools generally sell out within a few minutes of being listed. The best way to capture a sale is to periodically check his site and get alerted when a sale is in progress. This write-up is about automating the check and sending an alert via SMS and email using Python.
Blogspot publishes a RSS feed for their blogs. I wrote a simple function to use feedparser to grab the datetime of the first item in the feed and compare it against the previous version. I send out an alert if the datetime of the first item is different from the one I have saved.
#Get the blog entry feed = feedparser.parse('http://atwoodknives.blogspot.com/feeds/posts/default') #Figure out the publish time of the first entry firstEntryPubTime = time.strftime('%Y%m%d%H%M%S', feed.entries.published_parsed) #The newest post time did not match the previously saved post time #We have a new post if firstEntryPubTime != currentUpdateTime: #Save the new first blog entry time setCurrentUpdateTime(firstEntryPubTime) url = feed.entries.link subject = 'Atwood: ' + feed.entries.title body = url + feed.entries.summary #Send an alert send_alert(subject, body, url) else: print "No Update"
Now, to send the alert we leverage Amazon Web Services and BOTO the AWS Python interface. Amazon has a service called Simple Notification Service or SNS. SNS is a push service that lets users push messages in various formats like SMS and email.
Getting started is simple. First create a topic to which people can subscribe using create_topic. Then subscribe your phone number, email address, and any other form of communication using subscribe. Now you are all set.
def send_alert(message_title, message_body, message_url): #Connect with boto using the AWS token and secret key c = boto.connect_sns('token','secret_key') topicarn = "arn:aws:sns:us-east-1:TopicName" #Publish or send out the URL of the blog post for quick clicking publication = c.publish(topicarn, url, subject=url[:110]) #Close connection c.close()
I set up this script on a server at DigitalOcean and ran it periodically using cron. I was able to get to the buy link for most of Atwood’s sales with this methodology and eventually bought a Fancy Ti Atwrench. While nice and well made, it is definitely not worth what Peter Atwood charges for it.