Skip to content

Commit bd44776

Browse files
committed
Updated. job_compassplus/mysite_compassplus_com/get_profile_info_from_web/db.py. Added "prev_name" field in "Person"
1 parent fcca36d commit bd44776

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

  • job_compassplus/mysite_compassplus_com/get_profile_info_from_web

job_compassplus/mysite_compassplus_com/get_profile_info_from_web/db.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Person(BaseModel):
117117
create_date = DateField(default=date.today)
118118
last_check_date = DateField(default=date.today)
119119
is_active = BooleanField(default=None, null=True)
120+
prev_name = TextField(default=None, null=True)
120121

121122
class Meta:
122123
indexes = (
@@ -131,9 +132,23 @@ def get_last_by_name(cls, name: str) -> Optional["Person"]:
131132

132133
@classmethod
133134
def get_all(cls, name: str) -> list["Person"]:
134-
return list(
135-
cls.select().where(cls.name == name).order_by(cls.id.desc())
136-
)
135+
prev_names: set[str] = set()
136+
137+
persons: set[Person] = set()
138+
for p in cls.select().where(cls.name == name):
139+
persons.add(p)
140+
141+
if p.prev_name:
142+
prev_names.add(p.prev_name)
143+
144+
for prev_name in prev_names:
145+
if prev_name in persons:
146+
continue
147+
148+
for p in Person.get_all(prev_name):
149+
persons.add(p)
150+
151+
return sorted(persons, key=lambda p: p.id, reverse=True)
137152

138153
@classmethod
139154
def get_all_name(cls) -> list[str]:
@@ -161,3 +176,15 @@ def get_all_name(cls) -> list[str]:
161176
print(f"Total: {len(persons)}")
162177
print(f"Active: {len([p for p in persons if p.is_active])}")
163178
print(f"Non active: {len([p for p in persons if not p.is_active])}")
179+
180+
# Поиск людей с одинаковой картинкой в профиле
181+
# from collections import defaultdict
182+
# img_by_persons: defaultdict[bytes, set[str]] = defaultdict(set)
183+
#
184+
# for p in Person:
185+
# img_by_persons[p.img].add(p.name)
186+
#
187+
# for img, persons in sorted(img_by_persons.items(), key=lambda x: len(x[1]), reverse=True):
188+
# if len(persons) > 1:
189+
# print(len(persons), persons)
190+
#
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
__author__ = "ipetrash"
5+
6+
7+
# SOURCE: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations
8+
9+
10+
from playhouse.migrate import SqliteDatabase, SqliteMigrator, migrate
11+
from db import TextField, DB_FILE_NAME, Person
12+
13+
14+
db = SqliteDatabase(DB_FILE_NAME)
15+
migrator = SqliteMigrator(db)
16+
17+
18+
with db.atomic():
19+
migrate(
20+
migrator.add_column(
21+
Person._meta.table_name,
22+
"prev_name",
23+
TextField(default=None, null=True),
24+
),
25+
)

0 commit comments

Comments
 (0)