insert ip_country info to links_to_validate table
This commit is contained in:
+20
-2
@@ -284,19 +284,35 @@ class MongoDbManager:
|
|||||||
collection.find_one_and_update({'_id': id}, {"$set": {"url_validated": state, "validated_at": validated_at}},
|
collection.find_one_and_update({'_id': id}, {"$set": {"url_validated": state, "validated_at": validated_at}},
|
||||||
upsert=False)
|
upsert=False)
|
||||||
|
|
||||||
def save_links_to_validate(self, link: str, mail_address: str):
|
def get_all_contacts_to_book(self) -> list:
|
||||||
|
_collection_name = CONTACT_LIST_TO_BOOK
|
||||||
|
_cursor = self.db[_collection_name]
|
||||||
|
_all_contact_list = []
|
||||||
|
for document in _cursor.find():
|
||||||
|
_all_contact_list.append(ContactPojo.from_firestore_dict(document))
|
||||||
|
return _all_contact_list
|
||||||
|
|
||||||
|
def save_links_to_validate(self, link: str, mail_address: str, _all_contact_list: list):
|
||||||
collection_to_use = self.db[LINKS_TO_VALIDATE]
|
collection_to_use = self.db[LINKS_TO_VALIDATE]
|
||||||
updated_at = time.strftime("%H:%M:%S", time.localtime())
|
updated_at = time.strftime("%H:%M:%S", time.localtime())
|
||||||
|
_ip_country = "FR"
|
||||||
|
# find ip_country info
|
||||||
|
for _contact in _all_contact_list:
|
||||||
|
if _contact.mail == mail_address:
|
||||||
|
_ip_country = _contact.ip_country
|
||||||
|
|
||||||
if len(mail_address) > 0:
|
if len(mail_address) > 0:
|
||||||
collection_to_use.replace_one(filter={'_id': mail_address, }, replacement={
|
collection_to_use.replace_one(filter={'_id': mail_address, }, replacement={
|
||||||
u'url': link,
|
u'url': link,
|
||||||
u'email': mail_address,
|
u'email': mail_address,
|
||||||
|
u'ip_country': _ip_country,
|
||||||
"updated_at": updated_at
|
"updated_at": updated_at
|
||||||
},
|
},
|
||||||
upsert=True)
|
upsert=True)
|
||||||
else:
|
else:
|
||||||
collection_to_use.replace_one(filter={'_id': link, }, replacement={
|
collection_to_use.replace_one(filter={'_id': link, }, replacement={
|
||||||
u'url': link,
|
u'url': link,
|
||||||
|
u'ip_country': _ip_country,
|
||||||
"updated_at": updated_at
|
"updated_at": updated_at
|
||||||
},
|
},
|
||||||
upsert=True)
|
upsert=True)
|
||||||
@@ -306,7 +322,9 @@ MONGO_STORE_MANAGER = MongoDbManager()
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db_manager = MongoDbManager()
|
db_manager = MongoDbManager()
|
||||||
print(db_manager.get_code_for_email("singleton_teri1991@aol.com"))
|
for c in db_manager.get_all_contacts_to_book():
|
||||||
|
print(c)
|
||||||
|
# print(db_manager.get_code_for_email("singleton_teri1991@aol.com"))
|
||||||
# black_list = db_manager.get_blacklist_contacts()
|
# black_list = db_manager.get_blacklist_contacts()
|
||||||
# for contact in black_list:
|
# for contact in black_list:
|
||||||
# print(contact)
|
# print(contact)
|
||||||
|
|||||||
@@ -255,7 +255,8 @@ def read_mails():
|
|||||||
if need_to_check_email(mail.mail, successful_items):
|
if need_to_check_email(mail.mail, successful_items):
|
||||||
mail_reader = MailReader(mail.mail, mail.password)
|
mail_reader = MailReader(mail.mail, mail.password)
|
||||||
executor.submit(mail_reader.read_emails, mails_messages)
|
executor.submit(mail_reader.read_emails, mails_messages)
|
||||||
|
# get ip_country info
|
||||||
|
_all_contact_list = MONGO_STORE_MANAGER.get_all_contacts_to_book()
|
||||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||||
for mail in mails_messages:
|
for mail in mails_messages:
|
||||||
# if mail.isImapClient:
|
# if mail.isImapClient:
|
||||||
@@ -269,7 +270,7 @@ def read_mails():
|
|||||||
# else:
|
# else:
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
if need_to_valid_url(url, successful_items):
|
if need_to_valid_url(url, successful_items):
|
||||||
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address)
|
MONGO_STORE_MANAGER.save_links_to_validate(url, mail.to_address, _all_contact_list)
|
||||||
# url_validator = LinkValidator(url)
|
# url_validator = LinkValidator(url)
|
||||||
print("need to validate url: " + url)
|
print("need to validate url: " + url)
|
||||||
# executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False)
|
# executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False)
|
||||||
|
|||||||
@@ -11,15 +11,17 @@ class ContactPojo:
|
|||||||
first_name: str
|
first_name: str
|
||||||
mail: str
|
mail: str
|
||||||
note: str
|
note: str
|
||||||
|
ip_country: str
|
||||||
|
|
||||||
def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str):
|
def __init__(self, phone_number: str, passport_number: str, last_name: str, first_name: str, mail: str,
|
||||||
|
ip_country="FR"):
|
||||||
self.phone = str(phone_number).replace(".0", "")
|
self.phone = str(phone_number).replace(".0", "")
|
||||||
self.passport = passport_number
|
self.passport = passport_number
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
self.mail = mail
|
self.mail = mail
|
||||||
self.note = ""
|
self.note = ""
|
||||||
self.ip_country = "FR"
|
self.ip_country = ip_country
|
||||||
|
|
||||||
def to_firestore_dict(self):
|
def to_firestore_dict(self):
|
||||||
dest = {
|
dest = {
|
||||||
@@ -30,7 +32,6 @@ class ContactPojo:
|
|||||||
u'mail': self.mail,
|
u'mail': self.mail,
|
||||||
u'ip_country': self.ip_country
|
u'ip_country': self.ip_country
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest
|
return dest
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -41,13 +42,15 @@ class ContactPojo:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_firestore_dict(source):
|
def from_firestore_dict(source):
|
||||||
ccid = source['ccid']
|
|
||||||
phone = source['phone']
|
phone = source['phone']
|
||||||
position = source['position']
|
|
||||||
passport = source['passport']
|
passport = source['passport']
|
||||||
email = source['mail']
|
email = source['mail']
|
||||||
last_name = source['last_name']
|
last_name = source['last_name']
|
||||||
first_name = source['first_name']
|
first_name = source['first_name']
|
||||||
|
ip_country = "FR"
|
||||||
|
if source.get('ip_country'):
|
||||||
|
ip_country = source['ip_country']
|
||||||
result = ContactPojo(phone_number=phone, passport_number=passport, mail=email,
|
result = ContactPojo(phone_number=phone, passport_number=passport, mail=email,
|
||||||
last_name=last_name, first_name=first_name)
|
last_name=last_name, first_name=first_name)
|
||||||
|
result.ip_country = ip_country
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user