Hackathon Day 1
• Mark Eschbach
As usual for a hackathon day I’m begining my journey early on this hackathon day. First project is a harvester of Jelly Bell names. I’ll be using Selenium to harvest them since it’s an easy interface to hack on; and I wouldn’t expect this application to run more than once a day if it runs more than once. I’ve tended to stay away from magic source file generators since a really long time. Now they aren’t trying to generate solutions for the world I feel like they are a lot more reasonable. For example
bundle init generates the simple stub file.
General plan of attack for this project: boot up selenium with a version of Chrome driver, navigate to the flavor guide, then extract the image and name pairs for the Jelly Bellys. Interesting Selenium has moved over to using Go for their build system, I suppose it makes sense though being heavily backed by Google. I alway forget how to connect Ruby to a remote WebDriver instance. Well there we go. Right, usually easier to start with a headed browser instead of a headless one.
I’ve recently become a huge fan of
pry for this kind of development since there is a lot of exploration at the end of the script. To keep progress I keep new calls in a development file. Then when I’ve gotten to a milestone I’ll rerun and ensure
binding.pry is at the end so I can resume the last known safe path. Well, their site is realtively esay to navigate with classes on the correct items and everything! In order to get the image for the Jelly Belly I needed to use a gnarly regex:
/[^\"]+\"([^\"]*)\".*/. No the worst in the world, but definitely not something I look forward to using. Interestingly it looks like they block their main JS thread (and thus rendering) while loading in the massive number of Jelly Bellys they have. I’m probably wrong there. But I did get Selenium to trigger in between loads!
I learned a new technique for Selenium! If the element exists but isn’t visible you can query it’s state with
element.displayed?. Good times, that will make some things much easier. Especially with sites containing multiple layers. I’m sure I’ll forgot this agian next time I need it.
On to the next portion of the problem: how is the user going to access the data? We already have a slack bot integration setup, so that part is easy. I think the first iteration will have the application simply choose a random jelly bean. Integrating the bot was rather easy. So I have the bot repsonding to queries I send it. Now I just need to select a random name from teh list.
Math.random() has the problem of returning the range of
Coool, oeverall that worked well and how I intended. I struggled with getting Slack to send attachments through the WebSocket API only to realize the documentation only mentions web hooks and not the websocket API. Disappointing. Anyway, project mostly complete.