Scraping Buy: Scripting for a Purchase

An Opening Tune

The piece of code I’ve written within the final two months most fascinating to me is not something I’ve executed for work. It is not something I wrote to find a brand new job. It would not have checks. It would not actually have a class. It is soiled, less than my requirements, and would not deal with edge circumstances. Nevertheless it does what I want it to.

Unhappy Track

I do not (and certain won’t ever) take into account myself a guitarist, however I just like the guitar. I might wish to have a Les Paul to associate with my Stratocaster, however I additionally like having cash for issues like meals and shelter. I am unable to justify it within the funds, and that is high-quality. However possibly I might discover one thing shut sufficient for much less cash.

I zeroed in on a duplicate, and I made a decision on a Firefly. There was just one drawback – I could not purchase one. A minimum of, not from them. Holding them in inventory was problematic. Not solely due to provide chain points, however due to their enterprise mannequin. They batch up a small variety of guitars a couple of instances a 12 months on the market. I wasn’t the one particular person with the identical plan to purchase one. They promote out shortly more often than not.

You could find them on the secondhand market. Sometimes, they’re priced greater than their new value direct from the producer. The demand is there. They do not make them usually sufficient. And if you need one, you have to be quick.

Composing A Quantity

That is concerning the furthest factor from an vital use of my time. Nonetheless, I grew to become a bit…overtaken by the prospect of ordering one. I might refresh the location many instances a day, simply to test in. As soon as, I occurred to refresh the location after they have been importing their contemporary stock. I used to be in! However, I didn’t get to the mannequin I wished in time. It bought out earlier than I might discover it.

Lastly, I remembered that computer systems can do repetitive give you the results you want, and that I knew the way to request them to take action. I resolved to cease refreshing their product itemizing web page. A minimum of, I might cease refreshing it myself. I wrote a small script to do it for me.

require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML("#{root_url}/collections/fflp-electric-guitars"))

guitars ="a").
  map a.
  choose a.
  map{ |a| "#{root_url}#{a}" }.

places guitars
Enter fullscreen mode

Exit fullscreen mode

I would not put this in manufacturing at work. It would not have constant formatting! It is not clear precisely what that is doing! It is not examined. Actually. I do not imply it would not have automated checks. I imply I had no thought if this might work. Once I wrote it, I could not check it in opposition to a web page that had any merchandise. I discovered considered one of their different merchandise that did have stock in inventory, and constructed it in opposition to that. I hoped that the web page for this product line would work the identical, and that I did not have a typo.

This does not preserve observe of their full stock. It has no consciousness of if there are pages of outcomes. However, it is adequate to inform me that there are guitars on the market. That is a begin. Hopefully. I uninterested in seeing the “bought out” web page. And I would not even know if it might work till that “bought out” web page went away.

Automated Playback

Having the script is nice, but when I’ve to run it myself, I would as nicely refresh the web page in my browser. As soon as once more, I wanted to remind myself what I do for a dwelling, and the way I can ask computer systems to do issues for me. After all, that solely occurred once I got here throughout this post. In it, the creator makes use of GitHub Actions to automate diff checks of internet sites. Now positive, their instance was for trivial issues like forest fires in California. However I might take the identical strategy for vital issues like guitars being in inventory.

I modified my script to dump its output to a file, arrange the GitHub Motion, and subscribed to the repository. When the motion pushed a commit as a result of the web page modified, I might get an electronic mail with a hyperlink to the commit. I might use that to then see the listing of guitars on the market.

In principle. I nonetheless wanted to see it occur. Ever.


It lastly occurred. And it simply arrived.

Code would not should be good. It would not at all times want to stick to your regular requirements. Generally, it may be adequate to resolve an issue you might have – particularly if it is momentary. Even higher in case you know it’s going to be momentary. I’ve written numerous “momentary” code that I am positive continues to be in manufacturing, years later. Writing code like this can be a gamble.

However the stakes have been extremely low right here. I would not put this in my portfolio if I have been in search of a job. It served its function although. I am blissful to retire this code. Because of it, I’ve different issues to play with quite than preserve this.

Add a Comment

Your email address will not be published. Required fields are marked *