0% found this document useful (0 votes)
36 views3 pages

Intelx API Search Script in Python

The document is a Python script that interacts with the Intelx API to search for information based on a provided ID. It includes error handling for various HTTP responses and allows users to save the search results to a specified file path. The script also features a user-friendly interface with colored text output and prompts for user input.

Uploaded by

binro01120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Intelx API Search Script in Python

The document is a Python script that interacts with the Intelx API to search for information based on a provided ID. It includes error handling for various HTTP responses and allows users to save the search results to a specified file path. The script also features a user-friendly interface with colored text output and prompts for user input.

Uploaded by

binro01120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import requests

import time
from bs4 import BeautifulSoup
from termcolor import colored
import os
import subprocess

if [Link] == 'nt':
[Link]('')

def print_blue_text(text):
print(colored(text, 'blue', attrs=['bold']))

class Intelx:
API_ROOT = '[Link]
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"

def __init__(self, api_key):


self.API_KEY = api_key

def search_intelx_by_id(self, did):


url = f"{self.API_ROOT}?did={did}"
headers = {
"User-Agent": self.USER_AGENT,
"x-key": self.API_KEY
}

try:
response = [Link](url, headers=headers)
response.raise_for_status()
except [Link] as errh:
if response.status_code == 400:
print("Requête incorrecte ou invalide.")
elif response.status_code == 401:
print("Authentification échouée.")
elif response.status_code == 403:
print("Accès refusé.")
elif response.status_code == 404:
print("ID non trouvé.")
elif response.status_code == 429:
print("Nombre maximal de requêtes autorisées dépassé. Attendez
avant de réessayer.")
elif response.status_code == 500:
print("Erreur interne sur le serveur. Contactez l'administrateur
pour plus d'informations.")
elif response.status_code == 503:
print("Serveur temporairement indisponible. Réessayez plus tard.")
else:
print("Erreur HTTP inconnue.")
return None
except [Link] as errc:
print("Erreur de connexion :", errc)
return None
except [Link] as errt:
print("Erreur de timeout :", errt)
return None
except [Link] as err:
print("Erreur de requête :", err)
return None

if response.status_code == 200:
return [Link]
else:
print("Erreur :", response.status_code)
return None

def main():
print_blue_text(r" /$$ /$$ /$$
")
[Link](0.1)
print_blue_text(r" | $$ | $$ | $$
")
[Link](0.1)
print_blue_text(r" /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ | $$$$$$$ /$$$$$$
/$$$$$$$ /$$$$$$ ")
[Link](0.1)
print_blue_text(r" /$$__ $$ |____ $$|_ $$_/ |____ $$| $$__ $$ |____ $
$ /$$_____/ /$$__ $$")
[Link](0.1)
print_blue_text(r"| $$ | $$ /$$$$$$$ | $$ /$$$$$$$| $$ \ $$ /$$$$$$$|
$$$$$$ | $$$$$$$$")
[Link](0.1)
print_blue_text(r"| $$ | $$ /$$__ $$ | $$ /$$ /$$__ $$| $$ | $$ /$$__ $
$ \____ $$| $$_____/")
[Link](0.1)
print_blue_text(r"| $$$$$$$| $$$$$$$ | $$$$/| $$$$$$$| $$$$$$$/| $$$$$$
$ /$$$$$$$/| $$$$$$$")
[Link](0.1)
print_blue_text(r" \_______/ \_______/ \___/ \_______/|_______/ \_______/|
_______/ \_______/")
[Link](0.1)
print_blue_text("Made by [Link]/database")

api_key = input("API key : ")


intelx_client = Intelx(api_key)

while True:
did = input("ID (did=...) de l'URL ou tapez 'exit' pour quitter : ")
if [Link]() == "exit":
break

print("\nRecherche en cours...\n")

result = intelx_client.search_intelx_by_id(did)

if result:
soup = BeautifulSoup(result, '[Link]')
paragraphs = soup.find_all('p')
for paragraph in paragraphs:
print([Link])

attempts = 0
while attempts < 3:
file_path = input("Entrez le chemin du fichier pour enregistrer le
résultat de la recherche : ")
if [Link](file_path):
with open(f"{file_path}\\{did}.txt", "w", encoding="utf-8") as
file:
[Link](result)
print(f"Résultat de la recherche enregistré dans {file_path}\\
{did}.txt")
break
else:
print("Chemin de fichier invalide. Veuillez entrer un chemin de
fichier valide.")
attempts += 1
else:
print("Erreur : trop de tentatives échouées. Passage à la suite.")
else:
print("Aucun résultat trouvé.")

if __name__ == "__main__":
main()

You might also like