49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import sys
|
|
import os
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
|
|
|
|
import lib.custom_logger as get_logger
|
|
logger = get_logger.get_logger(level=10)
|
|
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
from providers.tools.api_news_api_org import ApiNewsAPIOrg
|
|
|
|
|
|
def example_news():
|
|
api = ApiNewsAPIOrg()
|
|
res = api.get_news(
|
|
query="technology", # カテゴリを指定,
|
|
from_date="2025-09-10",
|
|
)
|
|
for article in res["articles"]:
|
|
# print(article)
|
|
logger.info(f"Title: {article['title']} URL: {article['link']}\ndescription: {article['description']}")
|
|
|
|
|
|
def example_headline():
|
|
api = ApiNewsAPIOrg()
|
|
res = api.get_headline_news(
|
|
query= None,
|
|
country= "jp",
|
|
category= None,
|
|
)
|
|
for article in res["articles"]:
|
|
# print(article)
|
|
logger.info(f"Title: {article['title']} URL: {article['link']}\ndescription: {article['description']}")
|
|
|
|
|
|
def example_source():
|
|
api = ApiNewsAPIOrg()
|
|
res = api.get_sources(
|
|
category=None,
|
|
language="ja",
|
|
country=None,
|
|
)
|
|
for source in res["sources"]:
|
|
# print(article)
|
|
logger.info(f"Name: {source['name']} URL: {source['url']}\ndescription: {source['description']}")
|
|
|
|
example_source()
|