Api_запрос_datanewton_суд
Api Запрос на datanewton.ru судебные дела. Нужен ключ. =>Результат в файлы json и Excel, но Excel кривоватuser_2065311
python
2 years ago
3.6 kB
10
Indexable
import requests
import pandas as pd
import clipboard
import json
# Функция для получения ИНН из файла или буфера обмена
def get_inns():
source = input("Введите 'file' для загрузки ИНН из файла или 'clipboard' для использования буфера обмена: ")
if source.lower() == 'file':
file_path = input("Введите путь к файлу: ")
with open(file_path, 'r') as file:
inns = file.read().splitlines()
elif source.lower() == 'clipboard':
inns = clipboard.paste().splitlines()
else:
print("Неверный ввод. Попробуйте снова.")
return get_inns()
return inns
# Функция для отправки GET-запроса к API для получения сведений о судебных делах
def get_arbitration_cases(api_key, inns, page_num=1, page_limit=1000, company_role="ALL", dispute="CIVIL_LAW_DISPUTES", status="CLOSE", start_date="2000-01-01", end_date="2023-01-01", year=2021, need_document=False):
url = "https://api.datanewton.ru/v1/arbitrationCases"
responses = []
for inn in inns:
params = {
"key": "КЛЮЧ API",
"inn": inn,
"page_num": page_num,
"page_limit": page_limit,
"company_role": company_role,
"dispute": dispute,
"status": status,
"start_date": start_date,
"end_date": end_date,
"year": year,
"need_document": need_document
}
response = requests.get(url, params=params)
if response.status_code == 200:
responses.append(response.json())
else:
print(f"Ошибка при отправке запроса для ИНН {inn}: {response.status_code}")
return responses
# Функция для сохранения ответа в файл JSON
def save_to_json(data):
file_name = 'outputSUD.json'
with open(file_name, 'w') as json_file:
json.dump(data, json_file, ensure_ascii=False, indent=4)
print(f"Данные сохранены в файл {file_name}")
# Функция для сохранения ответа в Excel
def save_to_excel(responses):
all_data = pd.DataFrame()
for data in responses:
if 'data' in data:
df = pd.json_normalize(data['data'])
for col in ['respondents', 'plaintiffs', 'third_parties', 'interested_persons', 'creditors', 'applicants', 'others']:
if col in df:
df[col] = df[col].apply(lambda x: json.dumps(x) if isinstance(x, list) else x)
else:
df = pd.DataFrame(columns=['id', 'first_number', 'date_start', 'date_update', 'currency', 'sum', 'dispute', 'status', 'case_id', 'instances', 'instance_count', 'year', 'year_and_month', 'respondents', 'plaintiffs', 'third_parties', 'interested_persons', 'creditors', 'applicants', 'others', 'documents', 'kad_arbitr_link'])
all_data = pd.concat([all_data, df], ignore_index=True)
file_name = 'outputSUD.xlsx'
all_data.to_excel(file_name, index=False)
print(f"Данные сохранены в файл {file_name}")
# Главная функция
def main():
inns = get_inns()
if inns:
api_key = "КЛЮЧ API" # Замените на ваш API-ключ
response_data = get_arbitration_cases(api_key, inns)
save_to_excel(response_data)
save_to_json(response_data)
if __name__ == "__main__":
main()
Editor is loading...
Leave a Comment