Skip to content

Instantly share code, notes, and snippets.

@kaiomagalhaes
Last active September 20, 2024 16:09
Show Gist options
  • Save kaiomagalhaes/e804eaab2c3a3ac3ca1473e72a06975b to your computer and use it in GitHub Desktop.
Save kaiomagalhaes/e804eaab2c3a3ac3ca1473e72a06975b to your computer and use it in GitHub Desktop.
Python Backend Engineer live coding

Exercise Title: News Aggregator with Data Submission

Objective:

Create a small application (it can be an API or a single file) that fetches the latest news articles on a user-specified topic and then submits selected article data to another API endpoint.

Requirements:

API Integration - Fetching Data:

NewsAPI: Use the NewsAPI to fetch news articles. An API key will be provided by the interviewer.

User/Program Input: Allow the user or another program to input a topic or keyword (e.g., "technology", "health", "sports").

Data Retrieval: Fetch the latest news articles related to the input topic using the /v2/everything endpoint.

Data Processing:

Display a list of fetched news articles with their titles, sources, and publication dates. Prepare the first 5 results from the list for submission.

API Integration - Submitting Data:

JSONPlaceholder API: Use the JSONPlaceholder API to submit data.

Data Submission:

For each selected article, submit a new post to the JSONPlaceholder API using a POST request to /posts.Data Mapping:

Title: Map the article's title to the title field.
Body: Map the article's description or content to the body field.
UserId: Generate a random id with low chances of collision

Display the response from the JSONPlaceholder API for each submitted article to confirm successful submission.

Error Handling:

Handle errors such as network issues, invalid API responses, or submission failures. Provide clear feedback to the user in case of errors.

Optional Enhancements (if time permits):

Pagination: Implement pagination for displaying large numbers of articles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment