4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python で Domo のデータセットのデータをイクスポートする

Last updated at Posted at 2017-09-21

Domo の データを CSV に出力します。
データセットは、dataset_id で決めます。

アクセストークンを取得するプログラムは、こちらです。
Python で Domo の アクセストークンを取得する

# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	main_export_dataset.py
#
#					Sep/22/2017
#
# ------------------------------------------------------------------
import	sys
import	requests
#
from domo_config import domo_config_proc
from get_access_token import get_access_token_proc
from export_dataset import export_dataset_proc
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
config = domo_config_proc()
access_token = get_access_token_proc(config)
#
dataset_id="4e7a793f-21d1-4afb-8d87-915267f7cf8g"
#
sys.stderr.write("*** check *** ppp ***\n")
#
#
str_csv = export_dataset_proc(access_token,dataset_id)
#
print(str_csv)
#
sys.stderr.write("*** 終了 ***\n")
#
# ------------------------------------------------------------------
export_dataset.py
# -*- coding: utf-8 -*-
#
#	export_dataset.py
#
#					Sep/21/2017
#
# ------------------------------------------------------------------
import	sys
import	requests
#
# ------------------------------------------------------------------
def export_dataset_proc(access_token,dataset_id):
	sys.stderr.write("*** export_dataset_proc *** start ***\n")
	headers = {"Authorization": "Bearer " + access_token,
			"Accept": "text/csv"
		}
	params = {
		"includeHeader": "true",
		}
#
	url_datasets="https://api.domo.com/v1/datasets/" + dataset_id + "/data"
#
	try:
		rr=requests.get(url_datasets,params=params,headers=headers)
		print(rr.status_code)
		sys.stderr.write(str(rr.status_code) + "\n")
	except Exception as ee:
		sys.stderr.write(str(ee) + "\n")
#
	sys.stderr.write("*** export_dataset_proc *** end ***\n")
#
	return rr.text
# ------------------------------------------------------------------

API の仕様はこちら
Export data from DataSet

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?