AHK: How to Fix an Airbnb Scraper

webscraper1

Just when I thought I was going to have a nice, relaxing Processing weekend, I realized my Airbnb scraper is broken. Fun fact: If they change their HTML, this script is WILDLY unlikely to work. I’m getting the sense that Airbnb is going to be the wild duck to my Sumatran tiger.

Since the scraper is how I’m gathering data for all the other scripts I’m trying to write, I spent the weekend fixing it.

Continue reading “AHK: How to Fix an Airbnb Scraper”

AHK: Visualizing ELSE/IF with Arrays

So Hopper’s Amazing Decipherer Script 1.0 was about 472 lines because it included ELSE IF clauses for every letter in the alphabet.

HADS 2.0 cuts it down to 77 lines because arrays, as it turns out, are incredibly useful when paired with loops.

Making a Rotated Alphabet

Deciphering a Caesar cipher requires that the alphabet be moved up by a certain number. Like so.

ROTchart

Notice that this is basically a 2-step process. Turn the letters of the alphabet into numbers 1-26. Then add the rotational value to each of them to find their new positions, in the code below that’s assigned to a variable called indexVar. In ROT1, A =1 and the rotational value is 1, so A = 1+1 = 2.

But what happens when you hit Z? Z=26 and the rotation is 1, so Z =  26+1 = 27.

So, you want to tell the computer IF the number goes above 27, then you want to reset it to 1 and continue.

A Slow Motion Loop

Continue reading “AHK: Visualizing ELSE/IF with Arrays”

AHK: What is an Array?

Arrays are a damn godsend. More specifically, they’re an easy way to deal with large lists. Why is this useful you ask? Imagine you want to run the same code on multiple items. The items could be numbers, letters, words, full sentences—anything.  By putting those things in a list, or an array, you can loop through hundreds, even thousands, of items with just a few lines of code.

ArrayGif1

Continue reading “AHK: What is an Array?”

AHK: How to Decipher the Caesar Shift with Code

VG JNF N OEVTUG PBYQ QNL VA NCEVY NAQ GUR PYBPXF JRER FGEVXVAT GUVEGRRA JVAFGBA FZVGU UVF PUVA AHMMYRQ VAGB UVF OERNFG VA NA  RSSBEG GB RFPNCR GUR IVYR JVAQ FYVCCRQ DHVPXYL GUEBHTU GUR TYNFF QBBEF BS IVPGBEL ZNAFVBAF GUBHTU ABG DHVPXYL RABHTU GB CERIRAG N FJVEY BS TEVGGL QHFG SEBZ RAGREVAT NYBAT JVGU UVZ

-No idea what this says. Damn you, Caesar.

The Caesar Shift is supposed to be ridiculously easy to decipher. I say supposed to be because while it might be easy to crack, translating the bastard is mind-numbingly painful if you have a substantial block of text.

There are quite a few resources online that’ll do it for you, but for kicks, I wrote an AHK that automates it—if you know how many positions you want to shift.

So How Does the Shift Work?

Continue reading “AHK: How to Decipher the Caesar Shift with Code”

AHK: How to Loop Code through Images

Need to make changes to every pixel in an image? As it turns out, that’s not so difficult with AutoHotkey. From what I’ve been able to gather, all you really need is the height and width of the picture so that the loop knows how many times to run and the XY coordinates of the picture’s upper left corner.

The Code

Note that CoordMode, Pixel, Screen tells the computer to use the XY coordinates relative to the screen rather than the window.

CoordMode, Pixel, Screen

Height:=Height of the Image
Width:=Width of the Image
Xaxis:=X-Coordinate to start at
Yaxis:=Y-Coordinate to start at

loop, %Height%
{
loop, %Width%
{

Do This Code, Xaxis, Yaxis

Xaxis++

}
Xaxis:= Xaxis-Width
Yaxis++
}

How the Loops Work

Continue reading “AHK: How to Loop Code through Images”

AHK: How BGR Color Works

Sadly, in AutoHotkey scripts  you can’t just demand “LIME” or “GENTLY BURNT ORANGE”. The computer will spit out an error message if you try. It requires a color ID in hexadecimal BGR (Blue, Green, Red) format.

If you’re wondering what the hell that is, you’re not alone.

The simple answer? It’s an 8 digit code assigned to each color. Look them up on Google if you want to preserve your mental health.

Keep reading if you’re less partial to your sanity.

The Complicated Answer

I just relearned how to count, damn it. That’s how complicated this is.

Hex Explained

You see, Color ID’s are made up of a fixed prefix and numbers that represent a combination of blue, green and red.

The amount of those colors can be anywhere between 0 and 255. Here starts the problem of counting. How do you tell the computer to use the max green value (255) if you can only use a 2 digit number?

You use a different counting system by adding letters A-F. That’s how.

BASE10LOWRES

It’s Base-16 because you’re counting by combining 16 characters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f.

If you’re only manipulating one color while the others are at 0, all you really need to know is that lower values are darker than higher ones.

16-BASE EXPLAINED

When you start combining colors, the same normal color rules apply. To make yellow, you jack up the red and green values, so the BGR will read 0x00ffff. Blue and red makes purple, so 0xff00ff.

The oddest thing to get used to is white being the max value of blue, green and red combined, 0xffffff. Just remember that the higher the value, the more they cancel each other out until they reach nothing. White.