Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from pathlib import *
- import requests
- import zipfile
- import os
- from random import randint
- import shutil
- def search_in_log(PATH, zip_path=None):
- list_result = []
- print('Ищем .log...\n')
- paths = Path(PATH).glob('**/*.log')
- for path in paths:
- try:
- if zip_path is not None:
- print('.log in ZIP:', zip_path)
- print('.log:', path)
- with open(path, 'r', encoding='utf-8', errors='ignore') as file:
- str_l = file.read()
- parse_result = parse_hash_adr(str_l, path, zip_path)
- if parse_result[1] or parse_result[2]:
- list_result.append(parse_result)
- except Exception as Error:
- print('Ошибка открытия файла', Error)
- return list_result
- def search_in_zip(PATH):
- table_list = []
- print('Ищем ZIP...\n')
- zip_path = Path(PATH).glob('**/*.zip')
- if not os.path.isdir('temp'):
- os.mkdir('temp')
- for path in zip_path:
- name_dir = os.path.join('temp', str(randint(9999, 999999)))
- os.mkdir(name_dir)
- if zipfile.is_zipfile(path):
- print('ZIP:', str(path))
- try:
- with zipfile.ZipFile(path, 'r') as zip_f:
- for file in zip_f.infolist():
- if '.log' in str(file):
- zipfile.ZipFile.extract(zip_f, file, name_dir)
- table_list += search_in_log(name_dir, zip_path=path)
- except Exception as Error:
- print('Ошибка открытия ZIP', Error)
- else:
- print('Не корректный файл', path)
- shutil.rmtree(name_dir)
- shutil.rmtree('temp')
- return table_list
- def parse_hash_adr(str_fish, path, zip_path):
- hash = None
- addreses = []
- try:
- if str_fish.find('"KeyringController":{"vault":"') != -1:
- str_l = str_fish[
- str_fish.find('"KeyringController":{"vault":"') + 30:str_fish.find(',"MetaMetricsController"') - 2]
- hash = str_l.replace(r'\\', '')
- print('Хэш:', hash)
- else:
- print('Хэш не найден')
- except Exception as Error:
- print('Ошибка поиска хэша', Error)
- try:
- if str_fish.find('"cachedBalances":') != -1:
- str_fish_sr = str_fish[str_fish.find('"cachedBalances":') + 17:]
- sym = 0
- sr_end = 0
- for count, s in enumerate(str_fish_sr):
- if s == '{':
- sym += 1
- if s == '}':
- sym -= 1
- if sym == 0:
- sr_end = count
- break
- json_hash_adr = json.loads(str_fish_sr[:sr_end + 1])
- for value in json_hash_adr.values():
- if value:
- for k, v in value.items():
- if k not in addreses:
- addreses.append(k)
- print('Найден адрес:', k)
- else:
- print('Адреса не найдены')
- except Exception as Error:
- print('Ошибка поиска адресов', Error)
- if zip_path:
- list_hash_adr = [str(zip_path)[5:], hash, addreses]
- else:
- list_hash_adr = [str(path)[5:], hash, addreses]
- return list_hash_adr
- def check_balance(adr_l):
- adr_balance_dict = {}
- for adr in adr_l:
- adr_balance_dict.update({adr: None})
- try:
- for i in range(3):
- response = requests.get('https://openapi.debank.com/v1/user/total_balance?id=' + adr,
- params='accept: application/json')
- if response.status_code == 200:
- #print(response.json())
- if 'total_usd_value' in response.json():
- adr_balance_dict.update({adr: int(response.json()['total_usd_value'])})
- break
- elif response.status_code == 400:
- print('Ошибка проверки баланса, некорректный адрес')
- break
- except Exception as Err:
- print('Ошибка проверки баланса', Err)
- return adr_balance_dict
- def check(zip_checkbox, folder_checkbox, balance_checkbox, PATH):
- PATH = r'\\?\\' + str(PATH)
- result_list = []
- balance_dict = {}
- if zip_checkbox:
- result_list += search_in_zip(PATH)
- if folder_checkbox:
- result_list += search_in_log(PATH)
- if balance_checkbox and result_list:
- adress_list = []
- for item in result_list:
- try:
- if item[2]:
- for adress in item[2]:
- if adress not in adress_list:
- adress_list.append(adress)
- except Exception as Error:
- print('Ошибка проверки баланса', Error)
- balance_dict = check_balance(adress_list)
- if not result_list:
- print('Ничего не найдено')
- return result_list, balance_dict
- def save_results(list_table, path):
- if list_table:
- try:
- with open(path, 'w') as f:
- for row in list_table:
- f.write(str(row) + '\n')
- except Exception as Err:
- print('Ошибка сохранения', Err)
Advertisement
Add Comment
Please, Sign In to add comment