mirror of
https://github.com/yaroslaff/antifraud2gis.git
synced 2026-04-28 03:30:52 +00:00
resolve company title by reviews if needed
This commit is contained in:
parent
83f55460d5
commit
44477b69d9
4 changed files with 50 additions and 14 deletions
|
|
@ -270,7 +270,11 @@ def do_provider(args, cl: CompanyList):
|
|||
|
||||
def lmdb_dump(args):
|
||||
|
||||
lmdb_path = args.args[0]
|
||||
try:
|
||||
lmdb_path = args.args[0]
|
||||
except IndexError:
|
||||
lmdb_path = settings.lmdb_user_storage.as_posix()
|
||||
|
||||
print("Dump", lmdb_path)
|
||||
|
||||
env = lmdb.open(lmdb_path, readonly=True)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from .const import DATAFORMAT_VERSION, SLEEPTIME, WSS_THRESHOLD, LOAD_NREVIEWS,
|
|||
from .user import User, get_user
|
||||
from .review import Review
|
||||
from .session import session
|
||||
from .exceptions import AFNoCompany, AFNoTitle, AFCompanyError
|
||||
from .exceptions import AFNoCompany, AFNoTitle, AFCompanyError, AFCompanyNotFound
|
||||
from .aliases import resolve_alias
|
||||
from .statistics import statistics
|
||||
from .aliases import aliases, resolve_alias
|
||||
|
|
@ -81,7 +81,11 @@ class Company:
|
|||
self.relations = None
|
||||
|
||||
if self.title is None:
|
||||
self.update_title()
|
||||
try:
|
||||
self.update_title()
|
||||
except AFCompanyNotFound as e:
|
||||
# resolve title by reviews
|
||||
self.update_title_by_reviews()
|
||||
|
||||
|
||||
|
||||
|
|
@ -127,7 +131,6 @@ class Company:
|
|||
if version != DATAFORMAT_VERSION:
|
||||
logger.debug(f"version mismatch {version} != {DATAFORMAT_VERSION} for {self.object_id}")
|
||||
return False
|
||||
|
||||
self.title = _basic['title']
|
||||
self.alias = _basic['alias']
|
||||
self.remark = _basic['remark']
|
||||
|
|
@ -141,12 +144,13 @@ class Company:
|
|||
self.branch_rating_2gis = _basic.get('branch_rating_2gis', None)
|
||||
self.trusted = _basic.get('trusted', None)
|
||||
self.detections = _basic.get('detections', list())
|
||||
|
||||
if not self.title:
|
||||
# logger.debug(f"no title for {self.object_id}")
|
||||
pass
|
||||
self.loaded_from_disk = True
|
||||
return bool(self.title)
|
||||
else:
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -408,7 +412,32 @@ class Company:
|
|||
user = get_user(uid)
|
||||
return Review(r, user=user)
|
||||
|
||||
def update_title_by_reviews(self):
|
||||
self.load_reviews()
|
||||
self.load_users()
|
||||
return
|
||||
|
||||
for r in self._reviews:
|
||||
upid = r['user']['public_id']
|
||||
if upid is None:
|
||||
continue
|
||||
|
||||
user = get_user(upid)
|
||||
user.load()
|
||||
ci = user.get_company_info(self.object_id)
|
||||
if ci is None:
|
||||
# print(f"no company info for me {self.object_id}, process next user")
|
||||
continue
|
||||
else:
|
||||
print("QQQQQQQQQQQQQQQQ")
|
||||
print_json(data=ci)
|
||||
|
||||
|
||||
|
||||
|
||||
def load_basic_from_network(self):
|
||||
# print(f"ZZZZZZ company load basic from network: {self.object_id}")
|
||||
# print("".join(traceback.format_stack(limit=10)))
|
||||
|
||||
# print("load_basic", self.object_id)
|
||||
# print(self.title, self.address, "err:",self.error)
|
||||
|
|
@ -448,15 +477,13 @@ class Company:
|
|||
data = json.loads(jdata)
|
||||
return data['name'], data['address']
|
||||
else:
|
||||
return f'_magic:{object_id}', 'Narnia'
|
||||
raise AFCompanyNotFound(f'Company {object_id} not found in LMDB')
|
||||
|
||||
|
||||
def update_title(self):
|
||||
""" set self.title/address from user's reviews """
|
||||
self.title, self.address = Company.resolve_oid(self.object_id)
|
||||
|
||||
|
||||
|
||||
def delete(self):
|
||||
# delete all files about company
|
||||
if self.reviews_path.exists():
|
||||
|
|
|
|||
|
|
@ -16,4 +16,8 @@ class AFNoTitle(AFException):
|
|||
|
||||
class AFCompanyError(AFException):
|
||||
# constructor will throw it if company has error
|
||||
pass
|
||||
|
||||
class AFCompanyNotFound(AFException):
|
||||
# company not found in LMDB
|
||||
pass
|
||||
|
|
@ -42,6 +42,7 @@ def retry(max_attempts=3, delay=1):
|
|||
|
||||
class User:
|
||||
def __init__(self, public_id):
|
||||
|
||||
self.public_id = public_id
|
||||
self.reviews_path = settings.user_storage / (public_id + '-reviews.json.gz')
|
||||
self._reviews = list()
|
||||
|
|
@ -100,9 +101,9 @@ class User:
|
|||
print(f"Error loading user {self.public_id}: {e}")
|
||||
time.sleep(5)
|
||||
|
||||
def lmdb_save(self, txn = None):
|
||||
|
||||
def lmdb_save(self, txn = None):
|
||||
""" """
|
||||
|
||||
def save_txn():
|
||||
txn.put(b'user:' + self.public_id.encode(), json.dumps(reviews).encode())
|
||||
|
||||
|
|
@ -168,11 +169,11 @@ class User:
|
|||
def get_company_info(self, oid):
|
||||
self.load()
|
||||
for r in self.reviews():
|
||||
print("qqq")
|
||||
print(type(r))
|
||||
print(r)
|
||||
if r.oid == oid:
|
||||
return r._data['object']
|
||||
print_json(data = r._data)
|
||||
if 'object' in r._data:
|
||||
return r._data['object']
|
||||
|
||||
|
||||
def reviews(self):
|
||||
self.load()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue