добавил from_dict
This commit is contained in:
@@ -17,6 +17,10 @@ class BlogArticle:
|
|||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {'title': self.title, 'text':self.text}
|
return {'title': self.title, 'text':self.text}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls,d):
|
||||||
|
BlogArticle(d['title'],d['text'])
|
||||||
|
|
||||||
def scan(i):
|
def scan(i):
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36'
|
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36'
|
||||||
@@ -33,8 +37,9 @@ def scan(i):
|
|||||||
BlogArticle(par[0].text,par[1].text)
|
BlogArticle(par[0].text,par[1].text)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
for i in range(3):
|
BlogArticle.from_dict({'title':'Заголовок','text':'Текст статьи'})
|
||||||
scan(i)
|
#for i in range(3):
|
||||||
|
#scan(i)
|
||||||
print(BlogArticle.count())
|
print(BlogArticle.count())
|
||||||
for i in range(5):
|
for i in range(1):
|
||||||
print(BlogArticle.ls[i].to_dict())
|
print(BlogArticle.ls[i].to_dict())
|
||||||
|
|||||||
Reference in New Issue
Block a user