Middle — Senior
Requesting a million addresses
livecode
Task condition
- Given an array of 1,000,000 URLs, each returning a set of
item_id. - For each obtained
item_id, requests need to be made to three separate services:service1,service2, andservice3. - Responses from these services are processed by the
business_logicfunction, which forms the final result. - All obtained results are collected into the final list.
from typing import List
# Sample input data:
# format: url, request_data
requests_samples = [
('http://some-service/getItems/', {'user_id': 100}),
('http://some-service/getItems/', {'user_id': 101}),
...
]
# Services to query
service_1_url = 'http://service1/fillItems/'
service_2_url = 'http://service2/scoreItems/'
service_3_url = 'http://service3/logItems/'
# Function to process service responses
def business_logic(service1_response, service2_response, service3_response):
# This function does not make network calls, only processes responses
# Assume it is already implemented
return {}
# Workflow:
# 1. Get item_ids from each request to 'some-service/getItems'
# 2. For each item_id, send independent requests to service_1_url, service_2_url, service_3_url
# 3. Process results through business_logic
# 4. Collect all results into the final list
def gather_data(requests: List[tuple]) -> List[dict]:
# YOUR CODE HERE
pass