Commit 932e223c authored by Krisjanis Rijnieks's avatar Krisjanis Rijnieks 🔥

Port upload_sizes to P3

parent 3186030f
Pipeline #134441 passed with stage
in 30 seconds
......@@ -5,18 +5,16 @@ import requests
import urllib
import os
try:
TOKEN = os.environ['TOKEN']
TOKEN = os.environ['TOKEN']
except:
print 'Please set the TOKEN env var with your Gitlab personal token'
print('Please set the TOKEN env var with your Gitlab personal token')
sys.exit(1)
def site_project():
path = 'academany/fabacademy/2019/site'
encoded = urllib.quote_plus(path)
# print encoded
response = requests.get('https://gitlab.fabcloud.org/api/v4/projects/%s?statistics=true&private_token=%s' % (encoded,TOKEN))
encoded = urllib.parse.quote_plus(path)
response = requests.get('https://gitlab.fabcloud.org/api/v4/projects/{}?statistics=true&private_token={}'.format(encoded, TOKEN))
data = response.json()
return data
......@@ -27,32 +25,29 @@ def upload_file(project_id, filename, fileContents):
}
data = {
"branch": "master",
"author_email": "fiore.basile@gmail.com",
"author_name": "Fiore Basile",
"commit_message": "Updating file sizes",
"content": fileContents
"branch": "master",
"author_email": "fiore.basile@gmail.com",
"author_name": "Fiore Basile",
"commit_message": "Updating file sizes",
"content": fileContents
}
url = 'https://gitlab.fabcloud.org/api/v4/projects/%s/repository/files/%s' % (project_id, filename)
print url
response = requests.put(url,
data=json.dumps(data), headers=headers)
url = 'https://gitlab.fabcloud.org/api/v4/projects/{}/repository/files/{}'.format(project_id, filename)
print(url)
response = requests.put(url, data=json.dumps(data), headers=headers)
return response
if __name__ == '__main__':
project = site_project()
project_id = project['id']
content = open('./sizes.md', 'r').read()
print 'Read sizes.md - %d bytes' % len(content)
print 'Uploading file sizes.md'
data = upload_file(project_id, 'sizes.md', content)
if data and data.status_code == 200:
print 'Uploading done'
sys.exit(0)
else:
print data.status_code
print data.text
print data.reason
sys.exit(1)
project = site_project()
project_id = project['id']
content = open('./sizes.md', 'r').read()
print('Read sizes.md - %d bytes' % len(content))
print('Uploading file sizes.md')
data = upload_file(project_id, 'sizes.md', content)
if data and data.status_code == 200:
print('Uploading done')
sys.exit(0)
else:
print(data.status_code)
print(data.text)
print(data.reason)
sys.exit(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment