I have a Python class which takes an url in parameter and launches a crawler on a news website.
Once the creation of the object is finished, the object is stored in a Elasticsearch cluster.
I want to create a method that takes in input the Elasticsearch document, and creates an object from it.
class NewsArticle():
def __init__(self, url):
self.url = url
# Launch a crawler and fill in the other fields like author, date, ect ...
@classmethod
def from_elasticsearch(cls, elasticsearch_article):
document = elasticsearch_article['_source']
obj = cls(document['url'])
obj.url = document['url']
obj.author = document['author']
.
.
.
The problem is, when I'm calling...
# response is my document from elasticsearch
res = NewsArticle.from_elasticsearch(response)
...the method __init__
will be called and will launch my crawler. Is there anyway that it doesn't launch my crawler or call the init method?