Earn some easy brownie points from your SO with Python, CRON & Pair
Pair has been cropping up a lot recently. Nearly every ‘Top X from Y Combinator’s Demo Day’ has Pair somewhere on the list. One of the cutsey features is a “Thinking of you” button. A single tap and you can let your loved one know they’re on your mind. ♥ ♥ Awwwww.
But it can work to your disadvantage. What if you don’t tap that button often enough? Instant cold shoulder. Now I’m not suggesting that you don’t think about your loved one on a regular basis, but when you do you’re not going to immediately reach for your phone, open the app and tap the button. So how can we make things easier? Lets estimate you think about your SO once an hour. Anytime I have a task I perform on a regular basis I tend to automate it with CRON. So lets do that here.
First thing I had to do was create a Pair account, and persuade my fiancé to actually pair with me (after a lot of eye-rolling she finally agreed). Then it was time to break out mitmproxy. There’s quite a big API to explore, but for this task I just focused on the “Thinking of you” requests, which is called a “nudge” by their API. But before you can send a nudge you have to authenticate.

The authenticate request returns an ‘authenticationToken’ (when successful) which we can use in subsequent requests. I’m unsure as to the life-span of this token so I request a new one before each nudge, you might want to experiment a little here.
Once we have authenticated we can now send our nudge request.

I might have got a little carried away while testing…

I’ve written a quick Python script to automate everything (it uses the excellent requests HTTP library). You can download it from Github. Once you have it setup just add python brownie_points.py > /dev/null to CRON at your preferred interval and begin racking up those brownie points.
If you’re worried about your partner smelling a rat when you suddenly begin “thinking of them” on the hour every hour, get creative. Use CI? Add the script to Jenkins so it runs when you deploy or you could call the script every-time you have a coffee (via RFID).
BTW, Level Up is taking bookings now for new projects. Got an interesting project you think we could help with? Or just need some friendly Python/Django developers? Then drop me an email or tweet @aaronbassett
2 Notes/ Hide
-
thisislevelup posted this

