API到数据库? [英] API to Database?

查看:151
本文介绍了API到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请假定我对我将要提及的任何事情一无所知,因为我确实不知道.

Please presume that I do not know anything about any of the things I will be mentioning because I really do not.

大多数OpenData网站都可以以.csv或.json格式(示例API ).

Most OpenData sites have the possibility of exporting the presented file either in for example .csv or .json formats (Example). They also always have an API tab (Example API).

我认为使用API​​意味着如果更新数据,您将收到更改,而将其导出为.csv则意味着内容将不再更改.

I presume using the API would mean that if the data is updated you would receive the change whereas exporting it as .csv would mean the content will not be changed anymore.

我的问题是:导出.csv文件时,如何使用此API代码显示相同的表.

My questions is: how does one use this API code to display the same table one would get when exporting a .csv file.

您将使用数据库提取此信息吗?什么样的数据库以及如何将API链接到数据库?

Would you use a database to extract this information? What kind of database and how do you link the API to the database?

推荐答案

我认为使用API​​意味着如果更新了数据, 将会收到更改,而将其导出为.csv则意味着 内容将不再更改.

I presume using the API would mean that if the data is updated you would receive the change whereas exporting it as .csv would mean the content will not be changed anymore.

从某种意义上说,您是正确的,如果您将csv下载到计算机上,则该csv文件将不再更新.
您会调用一个API-在这种情况下,您可以调用该API,说嘿,您在xxx上拥有最新数据吗?",然后您将得到有关所要求内容的最新信息.不过,这并不意味着该站点将在有新更新时通知您-您将不得不继续调用API(每小时,每天等)以查看是否有任何更改.

You are correct in the sense that, if you download the csv to your computer, that csv file won't be updated any more.
An API is something you would call - in this case, you can call the API, saying "Hey, do you have the latest data on xxx?", and you will be given back the latest information about what you have asked. This does not mean though, that this site will notify you when there's a new update - you will have to keep calling the API (every hour, every day etc) to see if there are any changes.

我的问题是:如何使用此API代码显示相同的内容 表在导出.csv文件时会得到.

My questions is: how does one use this API code to display the same table one would get when exporting a .csv file.

您将:

  1. 从服务器代码或云服务中调用API
  2. 让服务器代码或云服务解密(或解析")响应
  3. 使用解密后的响应创建由HTML制成的表格,或将其放入数据库中

您将使用数据库提取此信息吗?什么样的 数据库,以及如何将API链接到数据库?

Would you use a database to extract this information? What kind of database and how do you link the API to the database?

尽管数据库可以将最终数据放入其中,但您不一定需要数据库来提取信息.
您首先需要某种方式来调用REST API".有很多方法可以做到这一点-使用Shell脚本,使用Python,使用Excel VBA等.
我知道这很难想象,所以这是第1步的示例,您可以在其中检索信息.
尝试在Chrome浏览器的地址栏中放入下面的URL(取自您展示给我们的网站),然后按Enter http://opendata.brussels.be/api/records/1.0/search/?dataset = associations-clubs-sportifs

You wouldn't necessarily need a database to extract information, although a database would be nice to place the final data inside.
You would first need some sort of way to "call the REST API". There are many ways to do this - using Shell Script, using Python, using Excel VBA etc.
I understand this is hard to visualize, so here is an example of step 1, where you can retrieve information.
Try placing in the below URL (taken from the site you showed us) in your address bar of your Chrome browser, and hit enter http://opendata.brussels.be/api/records/1.0/search/?dataset=associations-clubs-sportifs

看看它如何给很多文本加上许多括号和逗号?您基本上已经要求该站点向您提供一些数据,这就是他们所提供的响应(不同的浏览器的工作方式有所不同-IE要求您将响应下载为.json文件).您基本上已经调用了API.

See how it gives back a lot of text with many brackets and commas? You've basically asked the site to give you some data, and this is the response they gave back (different browsers work differently - IE asks you to download the response as a .json file). You've basically called an API.

要更清晰地查看此数据,请打开Chrome浏览器的开发人员工具,然后输入以下JavaScript代码

To see this data more cleanly, open your developer tools of your Chrome browser, and enter the following JavaScript code

var url = 'http://opendata.brussels.be/api/records/1.0/search/?dataset=associations-clubs-sportifs';

var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function() {
    if (xhr.status === 200) {
        // success
        console.log(JSON.parse(xhr.responseText));
    } else {
        // error
        console.log(JSON.parse(xhr.responseText));
    }
};
xhr.send();

当您按Enter键时,将返回一个响应,指出对象".如果单击箭头,您会发现这是我们刚刚看到的数据的更清晰的版本-更具可读性.

When you hit enter, a response will come back, stating "Object". If you click through the arrows, you can see this is a cleaner version of the data we just saw - more human readable.

在这种情况下,我使用JavaScript检索数据,但是您可以使用所需的任何代码.您可以继续使用JavaScript解密数据,对其进行处理并将其推送到数据库中.

In this case, I used JavaScript to retrieve the data, but you can use whatever code you want. You could proceed to use JavaScript to decipher the data, manipulate it, and push it into a database.

kintone 是一个在线云数据库,您可以在其中对其进行自定义以运行JavaScript代码并将其存储为数据存储在他们的数据库中,因此您将可以在线存储数据,如下图所示.这只是您可以使用的数据库的一个示例.

kintone is an online cloud database where you can customize it to run JavaScript codes, and have it store the data in their database, so you'll have the data stored online like in the below image. This is just one example of a database you can use.

还有其他云服务可以使您将不同服务的API端点相互连接,例如IFTTT和Zapier,但是我不确定它们是否与开放数据连接.

There are other cloud services which allow you to connect API end points of different services with each other, like IFTTT and Zapier, but I'm not sure if they connect with open data.

这篇关于API到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆