Series Data Voyage Training Log

~1 min read

Making the News Collector Reusable

Collecting fintech news titles via the Naver search API, saving to MySQL and CSV, and organizing repeated code into functions and a module (myfunc) to turn a collection script into a reusable tool.

TrainingScrapingAPI

Structuring the Requirements First

This assignment had clear requirements. It was five steps: collect fintech news titles via the Naver API, save to MySQL, save to CSV, turn the code into functions, and modularize. Even the deliverables were fixed: the collection file, the DB module, and a result screenshot. I wrote the code with reuse in mind from the start.

Reviewing the Basics of requests

import requests
r = requests.get(url, params=payload, headers=headers)
print(r.status_code)   # 200 OK / 400, 500 error
response = r.json()
  • r.text is encoded as utf-8, so Korean renders well
  • r.content is the raw bytes the server sent, used for HTML parsing
  • r.json() auto-converts via the internal json module

The Naver API requires X-Naver-Client-Id and X-Naver-Client-Secret in the headers for auth. I learned that every API has its own conventions for this.

Functions, Then Modules

To avoid repeating the same logic, I wrapped collection and saving in functions and split shared functions into a separate file, myfunc.

import sys
sys.path.append("../../")
from myfunc import ...

Loading .env by explicit path (load_dotenv(path)) and keeping API keys out of the code carried directly over from earlier learning.

Takeaway

Key point

I felt the difference between a "write-once, throw-away script" and a "module." Once I wrapped things in functions and split them into files, I could pull the same tool back out for the next assignment, collecting Seoul real-estate transaction data. The functions and classes from Python basics became real tools here.