import requests | |
import csv | |
#Login using: curl -i -d '{"login_id":"EMAIL","password":"PASSWORD"}' https://mattermost-server.com/api/v4/users/login | |
#Copy the token | |
auth_token = raw_input("Please enter your auth token: ") | |
posts = raw_input("Please enter the filename to parse: ") | |
hed = {'Authorization': 'Bearer ' + auth_token} | |
def read_csv(): | |
reader_m = csv.reader(open(posts),delimiter=',') | |
for row_m in reader_m: | |
if len(row_m[19]) > 11: | |
fileid = row_m[19] | |
id = fileid[2:28] | |
get_file(id) | |
def get_file(id): | |
info_url = 'https://mattermost-server.com/api/v4/files/' + id + '/info' | |
response = requests.get(info_url, headers=hed) | |
info = response.json() | |
filename = info["name"] | |
file_url = 'https://mattermost-server.com/api/v4/files/' + id | |
response = requests.get(file_url, headers=hed) | |
open(filename, 'wb').write(response.content) | |
read_csv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment