After you finished building solution on your computer or remote development server,
time to submit the code!
Below are the elements from code submission screen. You simply copy your code from
your machine into text area marked (1) and then submit it (2) via our platform. You will get immediate
feedback in the right columns (3) and (4).
Lets say the data challenge is to extract data from ecommerce site with product ids and pricing information.
Thus the schema may look like this:
product_id = integer (required)
price = float (required)
An example of very basic program (in Python) which just prints hardcoded values in required format looks like this:
import json
data = [
{‘product_id’: ‘iphone_10’, ‘price’: 119.99},
[‘product_id’: ‘iphone_11’, ‘price’: 159.99},
]
print(json.dumps(data))
This would be accepted by platform, but of course the idea that data is real and up to date.
Therefore your code rather should fetch HTML content, extract required data and structure in required format.
import json
import requests
response = requests.get(‘http://www.iphones.lt’)
# models and prices stored in HTML table
rg = re.compile('<tr><td>(.*?)<td><td>(.*?)</td></tr>’)
results = rg.findall(response.content)
data = []
for model_str, price_str in results:
data.append({
‘product_id’: model_str,
‘price’: float(price_str)
})
print(json.dumps(data))
This would be accepted by platform, but of course the idea that data is real and up to date.
Therefore your code rather should fetch HTML content, extract required data and structure in required format.
print(json.dumps(data))