python 删除Slack中直到昨天上传的所有图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 删除Slack中直到昨天上传的所有图像相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python
"""Delete all images in Slack that were uploaded until yesterday"""
import requests
import datetime
import sys
TOKEN = 'Put your Slack auth token here'
SLACK_API = 'https://slack.com/api'
yesterday = datetime.date.today() - datetime.timedelta(days=1)
yesterday_ts = yesterday.strftime('%s')
def get_files(page=1):
return requests.get('%s/%s' % (SLACK_API, '/files.list'),
params={'token': TOKEN, 'ts_to': yesterday_ts}).json()
page = 1
files = get_files(page)
if not files['ok']:
print "ERROR: ", files['error']
sys.exit(1)
print 'Deleting %d images uploaded until %s' % (
files['paging']['total'], yesterday.strftime('%d/%m/%Y'))
total_pages = files['paging']['pages']
for page in xrange(1, total_pages):
print 'Deleting page %d/%d' % (page, total_pages)
files = get_files(page)
for f in files['files']:
resp = requests.get('%s/%s' % (SLACK_API, '/files.delete'),
params={'token': TOKEN, 'file': f['id']})
print 'Deleted %s' % f['id']
print 'Done!'
以上是关于python 删除Slack中直到昨天上传的所有图像的主要内容,如果未能解决你的问题,请参考以下文章
Slack 清理频道中的所有消息(~8K)
ruby 这个Ruby脚本将批量删除超过30天的所有Slack文件。只需从https://api.slack.com/web#authentication添加您的API令牌即可
ruby 这个Ruby脚本将批量删除超过30天的所有Slack文件。只需从https://api.slack.com/web#authentication添加您的API令牌即可
slack api : 上传到 slack 频道的文件
通过 Slack 交互按钮上传图片
Slack 上传文档