Skip to content

Instantly share code, notes, and snippets.

@mcepl
Created December 2, 2013 23:52
Show Gist options
  • Save mcepl/7761322 to your computer and use it in GitHub Desktop.
Save mcepl/7761322 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import json
import sys
import io
import logging
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.INFO)
import requests
inf = io.open(sys.argv[1])
db = json.load(inf)
for att in db['attachments']:
filename = att['filename']
issue_no = att['issue']
with io.open(att['path']) as f:
file_content = f.read()
data_dict = {
'description': 'attachment for the BitBucket issue #%d' % issue_no,
'public': True,
'files': {
filename: {
'content': file_content
}
}
}
req = requests.post(url='https://api.github.com/gists',
data=json.dumps(data_dict),
headers={
'Content-Type': 'application/json'
})
logging.debug('req = %s', req)
logging.debug('req.text = %s', req.text)
response_data = json.loads(req.text)
print("Issue %d for attachment %s has Gist URL %s" %
(issue_no, filename, response_data['html_url']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment