Last active
February 10, 2019 13:27
-
-
Save cjohannsen81/bd4204a3461164e2d99ad38775f55abb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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