我想从某个松弛 channel 检索每天下午4点至4:30 pm粘贴的松弛消息。
Slack为 channel 提供了一个Web API,即https://api.slack.com/methods/channels.history
上面的API提供了2个属性,分别是latest
和oldest
,这意味着我可以提取这两个时间戳之间的消息。但是我的问题是这些是时间戳,我必须要求时间戳为:
latest 1459750060.000002 #end
oldest 1459750060.000002 #start
我想将2个数据作为简单的时间对象传递,即
latest_simple = 0430pm #end
oldest_simple = 0400pm #start
latest_real_format = convert_to_timestamp(latest_simple)
oldest_real_format = convert_to_timestamp(oldest_simple )
因此,如果我能够以某种方式获取时间戳,那么我将能够轻松地将make请求发送给API
payload = {'token': 'XXXXXXXx', 'channel': 'C0L8MGLMN' , 'latest': latest_real_format , 'oldest':oldest_real_format }
r = requests.get('https://slack.com/api/channels.history', params=payload)
我怎样才能做到这一点 ?
最佳答案
时间戳是UNIX纪元,以毫秒为单位。假设您使用的是Python,下面是示例如何将其转换为日期时间和返回日期的示例。正如评论中已经提到的那样,您需要在“简单时间戳记”中包括要为其检索消息的日期。
Convert string date to timestamp in Python
Convert microsecond timestamp to datetime in Python
关于timestamp - 如何将简单的24小时制转换为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401391/