def post(content, token=None, username=None, public=False, debug=False):
'''
Post a gist on GitHub.
'''
random = hashlib.sha1(os.urandom(16)).hexdigest()
username = getuser() if username is None else username
now = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
description = ('{hash} (twitter-message-bus); from {host} by {user} '
'at {time} UTC.').format(host=getfqdn(), user=username,
time=now, hash=random)
payload = json.dumps({
'files': {
'message': {
'content': content if content is not None else ''
}
},
'public': public,
'description': description
})
response = github(http='post', uri='gists', token=token, payload=payload,
debug=debug)
return (response['id'], random) if 'id' in response else (None, None)
评论列表
文章目录