Skip to content

Instantly share code, notes, and snippets.

@cjohannsen81
Last active February 10, 2019 13:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cjohannsen81/bd4204a3461164e2d99ad38775f55abb to your computer and use it in GitHub Desktop.
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