我想从某个松弛通道检索每天下午4点至4:30 pm粘贴的松弛消息。Slack为频道提供Web API,如https://api.slack.com/methods/channels.history
上面的API提供了2个属性latest
&oldest
,这意味着我可以提取这2个时间戳之间的消息。但是我的问题是这些是时间戳,我必须要求时间戳为:
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,下面是示例如何将其转换为日期时间和返回日期的示例。正如评论中已经提到的那样,您需要在“简单时间戳记”中包括要为其检索消息的日期。
从日期/时间到时间戳:在Python中将字符串日期转换为时间戳
从时间戳到日期/提示:在Python中将微秒时间戳转换为日期时间
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句