What I am doing:
- Get data from data source (could be from API or scraping) in form of a dictionary
- Clean/manipulate some of the fields
- Combine fields from data source dictionary into new dictionaries that represent objects
- Save the created dictionaries into database
Is there a pythonic way to do this? I am wondering about the whole process but I'll give some guiding questions:
- What classes should I have?
- What methods/classes should the cleaning of fields from the data source to objects be in?
- What methods/classes should the combining/mapping of fields from the data source to objects be in?
If the method is different in scraping vs. api, please explain how and why
Here is an example:
API returns:
{data: {
name: "<b>asd</b>",
story: "tame",
story2: "adjet"
}
}
What you want to do:
- Clean name
- Create a name_story object
- Set name_story.name = dict['data']['name']
- Set name_story.story = dict['data']['story'] + dict['data']['story2']
- Save name_story to database
(and consider that there could be multiple objects to create and multiple incoming data sources)
How would you structure this process? An interface of all classes/methods would be enough for me without any explanation.