-2
我正在清理我們的Slack帳戶,並希望在刪除它們之前保存這些文件。附件是我從github獲得的腳本。有人可以給我一個片段,我可以添加到腳本,所以我可以告訴Python將文件保存在指定的文件夾(root_folder)。請提供您的善意幫助。將Slack文件保存在文件夾中
from slacker import *
import sys
import time
import os
from datetime import timedelta, datetime
root_folder = 'Z:\Slack_Files'
def main(token, weeks=4):
slack = Slacker(token)
# Get list of all files available for the user of the token
total = slack.files.list(count=1).body['paging']['total']
num_pages = int(total/1000.00 + 1)
print("{} files to be processed, across {} pages".format(total, num_pages))
# Get Data about files
files_to_save = []
ids = [] # For checking that the API doesn't return duplicate files
count = 1
for page in range(num_pages):
print ("Pulling page number {}".format(page + 1))
files = slack.files.list(count=1000, page=page+1).body['files']
for file in files:
print("Checking file number {}".format(count))
# Checking for duplicates
if file['id'] not in ids:
ids.append(file['id'])
if datetime.fromtimestamp(file['timestamp']) < datetime.now() - timedelta(weeks=weeks):
files_to_save.append(file)
print("File No. {} will be saved".format(count))
else:
print("File No. {} will not be saved".format(count))
count+=1
print("All files saved\nProceeding to save files")
print("{} files will be saved!".format(len(files_to_save)))
count = 1
for file in files_to_save:
print("Saving file {} of {} - {}".format(count, len(files_to_save), file["name"]))
print(file["name"])
count+=1
return count-1
是包含文件細節的API嗎? – Juggernaut
是你自己發佈的任何代碼,還是直接來自github?你是否要求我們在你自己沒有完成任何工作時爲你寫代碼?如果是這樣,這是該網站的主題。 –
是的,它包含我們Slack賬戶的詳細信息。我已經補充了它。它與github不完全相同。我只想告訴Python將文件保存在指定的文件夾中。當我運行這個腳本時,它會返回一個將被保存的文件列表,我只需要添加一個片段來保存文件夾中的文件。 –