I'm currently building an application in Python which receives real-time data through a websocket. Every second my application receives a "tick" from the websocket with data.
I want to look at this tick-data and check the timestamp (UNIX format). The application should ignore most of these ticks but every 6th hour it should run a specific method. (So, if the timestamp is 00:00, 06:00, 12:00 or 18:00 it should run a method.)
I know that timestamp % 3600
checks if it's a whole hour. I tried timestamp % (3600*6)
to check for every 6th hour. Unfortuantly this didn't work because it would also trigger false positives.
My question now is, how do i check if a timestamp is a 6th hour? (00:00, 06:00 ,12:00 or 18:00) Here's my current code:
tickertime = tickerdata['E']
if (tickertime % (3600*6) == 0):
run_this_method()
Preferably i'm looking for a simple lightweight solution which doesn't take too much complicated datetime conversions, formatting etc. (This because i receive a tick every second so the check should be super fast and efficient.)
I would love to hear if someone knows a smart solution to this. Thanks in advance!
Max