Skip to content

Instantly share code, notes, and snippets.

@tomoh1r
Last active Aug 29, 2015
Embed
What would you like to do?
redmine から json でデータを取得

Redmine からデータを JSON で取得する。

issue_number, url, username, password は適宜

#! /usr/bin/env python
# -*- coding: utf-8 -*-
if __name__ == '__main__':
import sys
import json
import urllib2
url = 'https://auth.example.com/'
username = 'as-you-like'
password = 'as-you-like'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
opener.open(url)
urllib2.install_opener(opener)
res = json.loads(urllib2.urlopen(urllib2.Request('{}issues/{}.json'.format(url, int(sys.argv[1])))).read())
print(res['issue'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment