将数据集元数据从ckan导出到excel

ckanapi-exporter的Python项目详细描述


啊![构建状态](https://travis-ci.org/ckan/ckanapi-exporter.svg)(https://travis-ci.org/ckan/ckanapi-exporter)
[![覆盖状态](https://img.shields.io/covertalls/ckan/ckanapi-exporter.svg)(https://covertalls.io/r/ckan/ckanapi-exporter)
[![最新版本](https://img.shields.io/pypi/v/ckanapi-exporter.svg)(https://pypi.python.org/pypi/ckanapi-exporter/)
[![支持的Python版本](https://img.shields.io/pypi/pyversions/ckanapi-exporter.svg)](https://pypi.python.org/pypi/ckanapi-exporter/)
[![开发状态](https://img.shields.io/pypi/status/ckanapi-exporter.svg)(https://pypi.python.org/pypi/ckanapi-exporter/)
[![许可证](https://www.shishishields.io/pypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypypy比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比比liclic(licliclicliclicliclicliclicand and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and https https https://http http://www.shishishishishishishishishishiyeah.to be able CSV files.<<<<<<<<<><<<<<<<<<><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>----------<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>><<<<<<<<>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>org
--column "Title" --pattern'^title $> output.csv
`

这将在demo.ckan.org上的每个数据集中搜索与
[正则表达式](https://docs.python.org/2/howto/regex.html\35;regex-howto)匹配的字段
`` title$,并将值放入csv文件中名为"title"的
列("column"参数)。It'll create << `output.csvthe file something like this: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <tr >
<td >Demo Data for Open DOn the first day of SpenSpending Over Over The 500 </de &&>&&&&<&&&<&&&&&&&&&< &&&&&< &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&tr >
</table >

You can add as many columns as you want: just add a `--co列和每个列的
--pattern'参数。csv文件
中列的标题可以是您想要的任何内容-它不必与
ckan中字段的名称匹配。让我们添加第二列,标题为"权限",其中包含数据集中的
`license'title``字段:

``bash
ckanapi-exporter--url'https://demo.ckan.org'\
--column"title"--pattern
--column"权限"--pattern--license u title$>;output.csv br/>`column`
>
<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt/><;lt;br/><;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt </tr >API action通过使用"--params"
参数并传入格式化为字典的字符串,可以传入相关的查询参数。每个键:值对表示传递给api调用的查询。

RL'https://demo.ckan.org'
--参数{'fq':元数据创建:[2017-01-01-01t00:00:00:00:00z到2017-01-31t23:59:99.999z]}"
--column"title--pattern"^title$"
--column"rights"--pattern"^license"^title$">;输出.csv.csv
```








您可以对数据集中的值应用某些转换。
例如,让我们添加第三列,每个
数据集描述的前50个字符(ckan api中的"notes"字段):

``bash
ckanapi exporter--url'https://demo.ckan.org'\
--column"title"--pattern"^title$"\
--column"rights"--pattern"^license"^title$"\
--column"description"--pattern"^notes"$最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50>;最长50"td>;创意共享属性"<;td>;
<;td>;演示有关11/04/<;td>;
<;tr>;
<;tr>;
<;td>;1天内公开数据演示数据-花费超过500英镑<;td>;
<;td>;创意共享cczero<;td>;
<;td>;公开数据花费超过500英镑的数据<;td>;
<;tr;
<;lt;tr>;
<;td>;英国猫猫入室盗窃案;lt;td/><;lt;td>;英国公开政府许可证(ogl)<;td>;
<;td>;英国公开政府许可证(ogl)<;lt;td>;
<;lt;td>;猫入室盗窃案、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名、猫名等lt;td>;…<;/td>;
<;/t
<;
<;






<



>我们添加一列包含每个数据集资源格式的列:



``bash
ckanapi-ckanapi-ckanapi-ckanapi-ckanapi-ckanapi-ckanapi-ckanapi-ckanapi-exporter-url'https://demo.ckan.org'\
--列"title"--模式"^license-license-license-title$'''''
--"descripti"列"说明"





<是的打开--pattern'^notes$'--max length 50'
--列格式--pattern'^resources$'^format$'>;output.csv
````

这一次该模式有两个参数:`--pattern'^resources$'^format$'.
这意味着找到每个数据集的"resources"字段,然后找到每个资源的"format"字段。当一个数据集有多个资源
时,这些格式将被合并到单个
表单元格中的带引号的逗号分隔列表中。它会创建一个类似这样的csv文件:


<;lt;table>;
<;lt;tr>;
<;lt;th>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt>;gt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt>;
<;th>;lt;lt;th>;lt;lt;th>;lt;lt;lt;lt>;lt;lt;lt;lt>;lt;lt;lt;lt;lt;lt;lt>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt lt;td>;
<;td>;创建关于11月4日高管薪酬的演示信息
<;lt;td>;关于11月4日高管薪酬的演示信息;lt;td>;
<;td>;lt;td>;xlsx,csv<;td>;
<;lt;tr>;
<;tr>;
><;td>;关于1日公开数据的演示数据-花费500英镑以上;lt;td>;
<;lt;td>;关于1日公开数据的演示数据-花费500英镑以上;lt;td>;关于1日公开数据的演示数据-花费500英镑以上;lt;lt;td>;
>;
<;lt;lt;td>;关于创意共享cc是的花费500多英镑用于开放数据的支出超过500英镑;lt;lt;lt;td>;lt;lt;td>;cscscscscscscscscscscscscscscscscscscscscscscsv<;td>;
<;lt;tr>;
><;lt;tr>;
><;lt;lt;td>;
<;lt;td>;英国开放政府许可证(ogl)<;td>;
><;lt;td>;一份猫盗记录,列出猫的名字,列出猫的猫的名字,列出猫的名字,列出猫的英国开放政府许可证(uk<;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt>;日
<;lt;lt;lt;lt;td>;
<;lt;lt;lt;lt;lt>;lt;lt;lt;lt;lt>;
<;lt;lt;lt;lt;lt;lt>;lt;lt;lt;lt>;
<;lt;td>;
<;td>;<;lt;lt>;<;lt;td>;
<;lt;td>;
>;
<;lt;td>;
>;
>;
>;
>;
>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt ets有多个csv资源。
您可以添加`--deduplicATE`删除复制的列的选项离子:

``bash
ckanapi exporter--url'https://demo.ckan.org'\
--column"title"--pattern"^title$"\
--column"rights"--pattern"^license"^title$"\
--column"description"--pattern"^notes$"--最大长度50"
--column formats--pattern"^resources$"^f而对于"重复数据消除"来说,这是一个很有价值的解决方案;对于"输出"来说,这是一个很有价值的解决方案;对于
>
<;表>;
<;lt;tr>;
<;lt;lt;th>;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;lt;
<;td>;秒enior salary information<;td>;
<;td>;creative commons attribution<;td>;
<;td>;演示11/04/lt;td>;
<;td>;xlsx,csv<;td>;
<;tr>;
<;tr>;
<;td>;演示1 da中开放数据的数据y-花费超过500英镑<;/td>;
<;td>;Creative Commons CCZero<;/td>;
<;td>;为开放数据生成的花费超过500英镑的数据<;/td>;
<;td>;CSV<;/td>;
<;/tr>;
<;tr>;
<;td>;英国猫入室盗窃案<;/td>;
<;td>>;英国开放式政府许可证(OGL)<;td>;
<;td>;列出猫名的猫市民记录,<;td>;
<;td>;JPEG、CSV<;td>;
<;tr>;
<;tr>;
<;td>;…<;td>;
<;td>;…<;td>;…<;td>;…<;td>;
<;td>;…<;td>;
<;td>;…<;td>;
<;tr>;
<;table>;



数据集发布者与此列的命名不一致,
有时是"下一次更新",有时是"下一次更新","下一次更新日","下一次更新时间"等等。我们将使用一个正则表达式来匹配所有这些可能的名称,并将它们组合成一个单独的"下一次更新"co列:

``bash
ckanapi exporter--url'https://demo.ckan.org'\
--column"title"--pattern"^title$"\
--column"rights"--pattern"^license"^title$"\
--column"description"--pattern"^notes$"--最大长度50"
--column formats--pattern"^resources$"^格式$'--deduplicate\
--column"next update"--模式"^extras$"^下一次更新。*'--unique\
>;output.csv
````

e.我们期望每个数据集只有一个匹配的
额外的,所以我们添加了`--unique`参数,如果一个数据集有多个
与模式匹配的额外的
,那么这个参数将崩溃。

惯性导航与制导。若要区分大小写且不带
删除空白,请在列中添加"--区分大小写--删除false"。


我们还可以找到多个附加项并将它们组合到一个列中。
例如,假设我们的数据集有一个"contributor"附加项
(有时拼写为"contributor")。,有时是"贡献者")。有些数据集有多个名为"contributor 1"、"contributor 2"等的附加项。我们可以找到所有这些附加项,并将它们组合成一个单引号、逗号分隔的列表,其模式如下:



使用columns.json文件

这里有一个格式示例:

``json
{
"数据所有者":{
"模式":"^author$",
"唯一":true,
"区分大小写":true

"交付单位":{
"模式":"^extras$","^delivery unit$",
"唯一":true

"贡献者:{
"paTTERN":["^extras$","^contributor.*"]
},
"description":{
"pattern":"^notes$",
"unique":true,
"区分大小写":true,
"最大长度":255
},
"format":{
"pattern":["^resources$","^format$",
"区分大小写":true,
"重复数据消除":true
}
}
```


然后告诉ckanapi exporter从该文件中读取列选项,而不是在命令行上指定:

```bash
ckanapi exporter--url'https://demo.ckan.org'--columns.json>;output.csv
````

有关可用于demo.ckan.org的示例"columns.json"文件,
请参见[test_columns.json](ckan api_exporter/test_columns.json)。


ckanapi exporter是
[losser]周围的薄包装(https://github.com/ckan/losser),将其连接到ckan api。
有关更多文档过滤和转换选项的输入运行
`ckan api exporter--help`或读取losser的文档。



ython
import ckanapi_exporter.exporter as exporter
csv_string=exporter.export('https://demo.ckan.org','columns.json')
````

返回一个utf8编码的字符串。

s(相当于加载json后的columns.json
文件的内容)。



development
——


要安装进行开发,请创建并激活python虚拟环境
,然后执行:

``bash
git clone https://github.com/ckan/ckanapi exporter.git
cd ckanapi exporter
python setup.py develop
pip install-r dev requirements.txt
````

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将cassandra中的行数据转换为与列相关的嵌套json   java如何使用jcr XPath在jcr:content/@jcr:data中搜索?   java在使用openCV进行安卓开发时如何利用手机的广角镜头   java解析扩展了接口,结束了一个潜在的无限循环   位置服务的@Override方法中存在java Android应用程序错误   java本地线程的用途和需求是什么   具有左右子访问的java节点树遍历   java验证JsonWebToken签名   JUL日志处理程序中的java日志记录   嵌入式Java读取给定时间段的串行数据。   java有没有办法从多个URL获取多个图像?   java线程通过等待intent阻止自己发送intent   java Spring MVC解析多部分内容请求   java JPA/Hibernate静态元模型属性未填充NullPointerException   java格式错误的字符(需要引号,得到I)~正在处理   java为什么PrintWriter对象抛出FileNotFoundException?   java Neo4j未正确保存标签   java IE不加载图像