I want to retrieve slack messages pasted between 4 pm to 4:30 pm daily from a certain slack channel. Slack provides a Web API for a channel as https://api.slack.com/methods/channels.history
The above API provides 2 attributes as latest
& oldest
, this means i can extract the messages between these 2 timestamps. But my problem is that these are time stamp and i have to make a request for timestamp as:
latest 1459750060.000002 #end
oldest 1459750060.000002 #start
I want to pass the 2 data as simple time objects i.e
latest_simple = 0430pm #end
oldest_simple = 0400pm #start
latest_real_format = convert_to_timestamp(latest_simple)
oldest_real_format = convert_to_timestamp(oldest_simple )
so if somehow i am able to get the timestamp , then i will easily be able to send make request to API as
payload = {'token': 'XXXXXXXx', 'channel': 'C0L8MGLMN' , 'latest': latest_real_format , 'oldest':oldest_real_format }
r = requests.get('https://slack.com/api/channels.history', params=payload)
How can i do this ?
The timestamps are UNIX epoch in milliseconds. Assuming you are using Python here are examples how to convert it to datetime and back. As already mentioned in the comments you need to include the date in your "simple timestamp" for which you want to retrieve the messages for.
From date/time to timestamp: Convert string date to timestamp in Python
From timestamp to date/timp: Convert microsecond timestamp to datetime in Python