Automating with IFTTT Maker

A few months ago I decided to work part-time and semi-remote instead of working full-time, and I quickly discovered that manually tracking working hours and manually inputting them in a different system was definitely NOT the way to go. I, much as any other lazy developer, don’t like uninteresting time-consuming tasks, so I decided to go ahead and see how much I can automate all of this with IFTTT.

I’ve used IFTTT for a while, so I feel quite comfortable with its simplicity. After some looking around I found Maker, which basically allows you to connect to anything which can make/receive HTTP requests.

Automating The Report

At first I had to code a way to report my hours, and since the service used by this company does not have any API, I just had to wing it with replaying some HTTP requests and figuring out the right parameters.

I ended up with something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def login(self):
res = self.session.post(urljoin(SITE_URL, 'punch2.php'),
data={
'comp': self.company,
'name': self.employee,
'pw': self.password
}, allow_redirects=False)
self.ix_employee = \
parse_html(res.text).find('input', {'id': 'ixemplee'})['value']
return True
def punch(self, option, remark=''):
res = self.session.post(urljoin(SITE_URL, 'punch3.php'),
data={
'comp': self.company,
'name': self.employee,
'remark': remark,
'B1': option,
'ix': self.ix_employee,
'ts': '',
'allowremarks': 1,
'msgfound': 0,
'thetask': 0,
'teamleader': 0,
'tflag': ''
})
if res.status_code != 200:
raise TimeWatchError(res.text)
return True
def punch_in(self, remark=''):
return self.punch(PUNCH_IN, remark)
def punch_out(self, remark=''):
return self.punch(PUNCH_OUT, remark)

Not the most beautiful piece of code, but it seems to get the job done quite nicely.

Creating an endpoint for IFTTT’s webhook

For this one I wanted to go with something free with minimal overhead, so seems like heroku it was.

Setting up an endpoint wasn’t much trouble at all, a few lines and a requirements.txt is all it really takes:

1
2
3
4
5
6
7
8
9
10
@app.route('/log', methods=['POST'])
def log():
params = request.get_json(force=True)
main.main(params['company'], params['employee'], params['pw'], params['action'])
return 'OK'
@app.errorhandler(404)
def page_not_found(error):
"""Custom 404 page."""
return '<html><head><title>Go away</title></head></html>'

Really can’t imagine it getting simpler than this. :)

Configuring the triggers

Well, the first scenario of working from remote was easy, and no setup was really needed. All I had to do was just setup a login script for my VPN connection, which asks me if I want to clock-in or clock-out when I close the session, and just curl my heroku endpoint to clock it. (This way I never have to remember this myself).

The next step was to make sure I don’t have to manually log my hours at the office either. Since I’ve already setup an API endpoint, all that was left was to get IFTTT to call it when I enter or leave the office.

It’s just as simple as setting the API call together with any trigger you want:

IFTTT Maker configuration

The Best Part

  • This was a fun and cool opportunity to try out some new things like heroku or Maker.
  • The entire coding process probably took as long as the time it takes me to track and manage my hours during an average month, therefore, it definitely saves me time.

The Code

If you’re interested in the rest of the code or trying for yourself, have a look a the project on GitHub.

Share0 Comments