Skip to content

Instantly share code, notes, and snippets.

@nrm176
Created March 18, 2019 08:39
Show Gist options
  • Save nrm176/2914214e1f6f5e3a2883bf5efde0d7e7 to your computer and use it in GitHub Desktop.
Save nrm176/2914214e1f6f5e3a2883bf5efde0d7e7 to your computer and use it in GitHub Desktop.
New EDINET API
import requests, zipfile, io
HEADERS = {
'User-Agent': 'My Sample Edinet API app',
}
def getDocumentList():
# 書式一覧API
# GET https://disclosure.edinet-fsa.go.jp/api/v1/documents.json
try:
response = requests.get(
url="https://disclosure.edinet-fsa.go.jp/api/v1/documents.json",
params={
"date": "2019-03-18",
"type": "2",
},
headers=HEADERS,
verify=False
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
if response.status_code == 200:
return response
except requests.exceptions.RequestException as e:
print('HTTP Request failed')
print(e)
def getDocumentByDocId(docId):
# 書類取得API
# GET https://disclosure.edinet-fsa.go.jp/api/v1/documents/S100FE9L
try:
response = requests.get(
url="https://disclosure.edinet-fsa.go.jp/api/v1/documents/%s" % docId,
params={
"type": "1",
},
headers=HEADERS,
verify=False
)
if response.status_code == 200:
return response
except requests.exceptions.RequestException:
print('HTTP Request failed')
raise
def download_xbrl(res, docId):
z = zipfile.ZipFile(io.BytesIO(res.content))
z.extractall('./%s' % docId)
def run():
# getDocumentList()
docId = 'S100FE9L'
res = getDocumentByDocId(docId)
download_xbrl(res, docId)
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment