_nekit_710 • Instagram profile
1,068 Followers, 23 Following, 1 Posts - See Instagram photos and videos from @_nekit_710
www.instagram.com
Следуйте инструкциям в видео ниже, чтобы узнать, как установить наш сайт как веб-приложение на главный экран вашего устройства.
Примечание: Эта функция может быть недоступна в некоторых браузерах.
Дисклеймер: Все данные, предоставленные в данной статье, взяты из открытых источников, не призывают к действию и являются только лишь данными для ознакомления, и изучения механизмов используемых технологий.
from mod.data_normalize import fio_normalize, phone_normalize, email_normalize, bdate_normalize, other_check
from mod.data_normalize import fio_normalize, phone_normalize, email_normalize, bdate_normalize, other_check
def check_csv_row(item_dict: dict, heads_list: list, heads: list, row: list) -> list:
"""Обработка строк полученных из csv."""
items = dict()
for key in item_dict:
match key:
case "fio":
items.update({"fio": fio_normalize(item_dict.get(key)).strip()}) if item_dict.get(key) \
else items.update({"fio": ""})
case "uname":
if item_dict.get(key):
if "http" in item_dict.get(key) or len(item_dict.get(key)) > 50:
items.update({"uname": ""})
items.update({"uname": item_dict.get(key).strip().encode().decode()})
else:
items.update({"uname": ""})
case "phone":
items.update({"phone": phone_normalize(item_dict.get("phone")).strip()}) if item_dict.get(key) \
else items.update({"phone": ""})
case "bdate":
items.update({"bdate": bdate_normalize(item_dict.get(key))}) if item_dict.get(key) \
else items.update({"bdate": ""})
case "email":
items.update({"email": email_normalize(item_dict.get(key)).strip()}) if item_dict.get(key) \
else items.update({"email": ""})
case "snils":
items.update({"snils": "".join(x for x in item_dict.get(key) if x.isdecimal())}) if item_dict.get(key) \
else items.update({"snils": ""})
case "inn":
items.update({"inn": "".join(x for x in item_dict.get("inn") if x.isdecimal())}) if item_dict.get(key) \
else items.update({"inn": ""})
case "address":
if item_dict.get(key):
items.update({"address": item_dict.get(key).strip().replace("'", "").replace('"', '')})
elif item_dict.get(key) == "":
temp_addr = []
for ky in item_dict:
if item_dict.get(ky) and ky == "house":
temp_addr.append(f"д. {item_dict.get(ky)}")
elif item_dict.get(ky) and ky == "build":
temp_addr.append(f"стр. {item_dict.get(ky)}")
elif item_dict.get(ky) and ky == "corp":
temp_addr.append(f"корп. {item_dict.get(ky)}")
elif item_dict.get(ky) and ky == "office":
temp_addr.append(f"офф. {item_dict.get(ky)}")
elif item_dict.get(ky) and ky == "kv":
temp_addr.append(f"кв. {item_dict.get(ky)}")
elif item_dict.get(ky) and ky in ["zip", "country", "region", "m_obr", "rayon",
"city", "street", "area"]:
temp_addr.append(item_dict.get(ky))
items.update({"address": ", ".join(temp_addr)}) if temp_addr else items.update({"address": ""})
case "passport":
if item_dict.get(key):
items.update({"document": item_dict.get(key)})
elif item_dict.get(key) == "":
doc = []
for k in item_dict:
if item_dict.get(k) and k == "pass_sn":
doc.append(f'Док. с/н: {item_dict.get(k).strip()}')
if item_dict.get(k) and k == "pass_dout":
doc.append(f'Дата выдачи: {item_dict.get(k).strip()}')
if item_dict.get(k) and k == "pass_iss":
doc.append(f'Выдан: {item_dict.get(k).strip()}')
if item_dict.get(k) and k == "pass_kp":
doc.append(f'Код подр.: {item_dict.get(k).strip()}')
items.update({"document": ", ".join(doc)}) if doc else items.update({"document": ""})
"""social account"""
if key in ["vk_id", "ok_id", "fb_id", "lj_id", "tg_id", "insta_id", "mailru_id", "yandex_id",
"google_id", "x_id", "skype"]:
soc = item_dict.get(key).replace("'", "") if item_dict.get(key) else ""
items.update({key: soc})
continue
"""other items"""
other = other_check(heads_list, heads, row).strip()
return [items.get("fio"), items.get("uname"), items.get("bdate"), items.get("phone"), items.get("email"),
items.get("inn"), items.get("snils"), items.get("document"), items.get("address"),
items.get("vk_id", ""), items.get("ok_id", ""), items.get("fb_id", ""), items.get("lj_id", ""),
items.get("tg_id", ""), items.get("insta_id", ""), items.get("mailru_id", ""), items.get("yandex_id", ""),
items.get("google_id", ""), items.get("x_id", ""), items.get("skype", ""), other]
import csv
import time
from pathlib import Path
from mod.check_csv_row import check_csv_row
from mod.data_normalize import count_val
csv.field_size_limit(2147483647)
row_list = ["fio", "uname", "bdate", "phone", "email", "inn", "snils", "document", "address", "vk_id", "ok_id",
"fb_id", "lj_id", "tg_id", "insta_id", "mailru_id", "yandex_id", "google_id", "x_id", "skype", "other"]
data_list = [row_list]
cnt = 0
count = 0
def save_data(file: Path) -> None:
global cnt, count
(Path(file).parent / "conv").mkdir(exist_ok=True)
name_file = Path(file).name.removesuffix(Path(file).suffix)
with open(Path(file).parent / "conv" / f"{name_file}_{cnt}.csv", mode="w", encoding='utf-8',
newline='') as w_file:
file_writer = csv.writer(w_file, delimiter=";")
file_writer.writerows(data_list)
count += len(data_list)
print(f"\n{'-'*25}\nsave: {count}\n{'-'*25}")
data_list.clear()
data_list.append(row_list)
cnt += 1
def read_files(file: Path, cnt_line: int) -> None:
global data_list, cnt, count
heads_list = ["fio", "uname", "bdate", "phone", "email", "address", "zip", "country", "region", "area", "rayon",
"m_obr", "city", "street", "house", "corp", "build", "office", "floor", "kv", "pass_sn", "pass_iss",
"passport", "pass_dout", "pass_kp", "snils", "inn", "vk_id", "ok_id", "fb_id", "lj_id", "tg_id",
"insta_id", "mailru_id", "yandex_id", "google_id", "x_id", "skype"]
heads = []
with open(file, "r", encoding="utf-8") as cs:
for nm, row in enumerate(csv.reader(cs, delimiter="|")):
"""creating a dictionary of column values"""
item_dict = {}
try:
if nm == 0:
heads.extend([x.strip() for x in row])
continue
for item in heads_list:
if item in heads:
item_dict.update({item: row[heads.index(item)].strip()})
else:
item_dict.update({item: ""})
except IndexError as e:
print(f"\nПроверьте csv на ошибки: {e}")
exit()
"""text processing"""
items_list = check_csv_row(item_dict, heads_list, heads, row)
"""check the number of values in the list"""
if not count_val(items_list):
continue
print("\r\033[K", end="")
print(f"\r{nm}/{cnt_line} | {items_list[0]} | {items_list[1]} | {items_list[3]}", end="")
"""adding a list to the save list"""
data_list.append(items_list)
"""check the number of objects in the list, save, clear"""
if len(data_list) == 100001:
save_data(file)
if 1 < len(data_list) < 100001:
save_data(file)
cnt = 0
def main() -> None:
try:
path = input("path folder: >>> ")
if not Path(path).exists() or not path or not Path(path).is_dir():
exit(0)
tm = time.monotonic()
files = [x for x in Path(path).iterdir() if Path(x).is_file() and Path(x).suffix in [".csv", ".CSV"]]
if len(files) < 1:
exit(0)
for nn, file in enumerate(files):
cnt_line = sum(1 for _ in open(file, "rb"))
print(f"\n{nn + 1}/{len(files)} | {Path(file).name} | Lines: {cnt_line}\n{'*' * 35}")
read_files(file, cnt_line)
# Path(file).unlink()
ch_time = (f'All check {len(files)} complete | {(int(time.monotonic() - tm) // 3600)} h. '
f'{(int(time.monotonic() - tm) % 3600) // 60} m. {float(time.monotonic() - tm) % 60:.2f} s.')
lnt = len(ch_time)
print(f'\n{"-" * lnt}\n{ch_time}\n{"-" * lnt}')
except KeyboardInterrupt:
exit()
import csv
import time
from pathlib import Path
from mod.check_csv_row import check_csv_row
from mod.data_normalize import count_val
csv.field_size_limit(2147483647)
row_list = ["fio", "uname", "bdate", "phone", "email", "inn", "snils", "document", "address", "vk_id", "ok_id",
"fb_id", "lj_id", "tg_id", "insta_id", "mailru_id", "yandex_id", "google_id", "x_id", "skype", "other"]
data_list = [row_list]
cnt = 0
count = 0
def save_data(file: Path) -> None:
global cnt, count
(Path(file).parent / "conv").mkdir(exist_ok=True)
name_file = Path(file).name.removesuffix(Path(file).suffix)
with open(Path(file).parent / "conv" / f"{name_file}_{cnt}.csv", mode="w", encoding='utf-8',
newline='') as w_file:
file_writer = csv.writer(w_file, delimiter=";")
file_writer.writerows(data_list)
count += len(data_list)
print(f"\n{'-'*25}\nsave: {count}\n{'-'*25}")
data_list.clear()
data_list.append(row_list)
cnt += 1
def read_files(file: Path, cnt_line: int) -> None:
global data_list, cnt, count
heads_list = ["fio", "uname", "bdate", "phone", "email", "address", "zip", "country", "region", "area", "rayon",
"m_obr", "city", "street", "house", "corp", "build", "office", "floor", "kv", "pass_sn", "pass_iss",
"passport", "pass_dout", "pass_kp", "snils", "inn", "vk_id", "ok_id", "fb_id", "lj_id", "tg_id",
"insta_id", "mailru_id", "yandex_id", "google_id", "x_id", "skype"]
heads = []
with open(file, "r", encoding="utf-8") as cs:
for nm, row in enumerate(csv.reader(cs, delimiter="|")):
"""creating a dictionary of column values"""
item_dict = {}
try:
if nm == 0:
heads.extend([x.strip() for x in row])
continue
for item in heads_list:
if item in heads:
item_dict.update({item: row[heads.index(item)].strip()})
else:
item_dict.update({item: ""})
except IndexError as e:
print(f"\nПроверьте csv на ошибки: {e}")
exit()
"""text processing"""
items_list = check_csv_row(item_dict, heads_list, heads, row)
"""check the number of values in the list"""
if not count_val(items_list):
continue
print("\r\033[K", end="")
print(f"\r{nm}/{cnt_line} | {items_list[0]} | {items_list[1]} | {items_list[3]}", end="")
"""adding a list to the save list"""
data_list.append(items_list)
"""check the number of objects in the list, save, clear"""
if len(data_list) == 100001:
save_data(file)
if 1 < len(data_list) < 100001:
save_data(file)
cnt = 0
def main() -> None:
try:
path = input("path folder: >>> ")
if not Path(path).exists() or not path or not Path(path).is_dir():
exit(0)
tm = time.monotonic()
files = [x for x in Path(path).iterdir() if Path(x).is_file() and Path(x).suffix in [".csv", ".CSV"]]
if len(files) < 1:
exit(0)
for nn, file in enumerate(files):
cnt_line = sum(1 for _ in open(file, "rb"))
print(f"\n{nn + 1}/{len(files)} | {Path(file).name} | Lines: {cnt_line}\n{'*' * 35}")
read_files(file, cnt_line)
# Path(file).unlink()
ch_time = (f'All check {len(files)} complete | {(int(time.monotonic() - tm) // 3600)} h. '
f'{(int(time.monotonic() - tm) % 3600) // 60} m. {float(time.monotonic() - tm) % 60:.2f} s.')
lnt = len(ch_time)
print(f'\n{"-" * lnt}\n{ch_time}\n{"-" * lnt}')
except KeyboardInterrupt:
exit()
if __name__ == "__main__":
main()
Статья читается полностью. Тезисы со ссылками на разделы появятся позже.
www.instagram.com
![]()
_nekit_710 • Instagram profile
1,068 Followers, 23 Following, 1 Posts - See Instagram photos and videos from @_nekit_710www.instagram.com
Комментарии
2