简体   繁体   English

通过 REST API 获取数据以及如何将其存储在 mysql 数据库中?

[英]Getting data through REST API and how to store it mysql database?

I just got the data through REST API and wanted to save it in mysql database.我刚刚通过 REST API 获取数据,并想将其保存在 mysql 数据库中。 As I'm a beginner, just looking a way to save the data into my sql database.由于我是初学者,只是在寻找一种将数据保存到我的 sql 数据库中的方法。 Could you guys please suggest me some tutorial/library/example.你们能给我推荐一些教程/库/示例吗? That would be great help.那将是很大的帮助。 Thanks.谢谢。 And if I'm against the stackoverflow terms and condition, I'm really sorry that.如果我反对 stackoverflow 的条款和条件,我真的很抱歉。 But I need really help on this topic.但我真的需要关于这个话题的帮助。

**from entsoe import EntsoePandasClient
import pandas as pd

client = EntsoePandasClient(api_key='api-key')

start = pd.Timestamp('20171201', tz='Europe/Brussels')
end = pd.Timestamp('20180101', tz='Europe/Brussels')
country_code = 'BE'  # Belgium

# methods that return Pandas Series
client.query_day_ahead_prices(country_code, start=start,end=end)
client.query_load(country_code, start=start,end=end)
client.query_load_forecast(country_code, start=start,end=end)
client.query_generation_forecast(country_code, start=start,end=end)

# methods that return Pandas DataFrames
client.query_wind_and_solar_forecast(country_code, start=start,end=end, psr_type=None)
client.query_generation(country_code, start=start,end=end, psr_type=None)
client.query_installed_generation_capacity(country_code, start=start,end=end, psr_type=None)
client.query_crossborder_flows('DE', 'DK', start=start,end=end)
client.query_imbalance_prices(country_code, start=start,end=end, psr_type=None)
client.query_unavailability_of_generation_units(country_code, start=start,end=end, docstatus=None)
#client.query_withdrawn_unavailability_of_generation_units('DE', start=start,end=end)

ts = client.query_day_ahead_prices(country_code, start=start, end=end)
print(ts)**

Using to_sql function provided by pandas all u need is to pass a connection object created with the SQLAlchemy library :使用to_sql提供的to_sql函数,您只需要传递一个使用SQLAlchemy库创建的连接对象:

from sqlalchemy import create_engine
engine = create_engine("mysql+pymysql://root:pass@localhost/mydb")

df.to_sql('table_name_for_df', con=engine, if_exists='append', flavor='mysql')
# check if the data has been sent
engine.execute("SELECT * FROM table_name_for_df").fetchall()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SCRAPY:如何将数据存储到Mysql数据库中 - SCRAPY: how to store data into Mysql database 如何通过python将数据存储在MySQL数据库中 - How to store data in MySQL database via python 如何在我的数据库中搜索以及如何在python上存储解析后的数据 - How to search through my database and how to store there parsed data on python 如何使用Python在MySQL数据库中存储API响应? - How to store API respond in MySQL database using Python? 如何减少通过REST API发送的数据的延迟 - How to reduce latency of data sent through a REST api 如何使用 flask 应用程序中的 MySQL 将用户输入的数据存储在我的数据库中。 我收到一个错误 - How to store data in my database from a user Input using MySQL in flask app. I am getting an Error 如何将html数据存储在mysql数据库中? - How do I store html data in a mysql database? 通过REST API请求从一台服务器向另一台服务器发布数据库中POST数据的正确方法? - Correct way to POST data in database through REST API request from one server to another? 无法从Django Rest API到AngularJS获取数据 - Not getting data from Django rest api to AngularJS 在没有数据库Django的情况下将数据传输到REST API - Transfering data to REST API without a database django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM