Question

Python compare previous row from StoreClient

  • 27 July 2023
  • 1 reply
  • 27 views

Hello all - I’m quite new to using Zapier’s store and StoreClient but understand python at a mediate level. My use case is to alert of any new messages from external users (customers) within a five minute window per channel. I am trying to create a zap that is dynamic as we have an infinite combination of external channels at any one time. 

So far my zap is as follows:

  1. Gather all new messages
  2. Filter out any internal user messages
  3. Using Zap Store, set values for Channel Id and Ts Time
  4. Get Storage Secret
  5. Use Python to compare timestamps of current and most recent messages within a channel and return true if within five minutes of each other.

This is where I’d like to be able to compare the row prior for each channel. I would normally use pandas but I’m unsure if that’s overkill, but most importantly I’m not sure if/how StoreClient.get_many handles the values. It’s really unclear even when I return the data as output. Any tips in the right direction greatly appreciated!

EDIT: I found using https://store.zapier.com/api/records?secret=<your-secret> very helpful for viewing the format of the data. Back to tinkering on this, if anyone has ideas on how to solve let me know otherwise I’ll post my solution once I find it :)


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

I believe I’ve found my answer but will need to let it run to test. I was able to store the values as channel:ts pairs (channel is the channel ID, and ts is the epoch time) and then compare the ts stored to ts of the message for any given channel.

If the message is within 5 minutes return false (to be used by next filter step) and do nothing to the data. If greater or equal to 5 return true and update the given record’s ts.

 

import time

client = StoreClient(input.get('secret'))
data = client.get(input_data['channel'])

diff = (float(input_data['ts']) - float(data))/60
if diff >= 5:
client.set(input_data['channel'], input_data['ts'])
output = {'continue': 'true'}
else:
output = {'continue':'false'}