4seo
August 8, 2021
Массовая проверка доменов на занятость и автоматическая регистрация
import re import requests import time f = open('1.txt') domain_name = f.readline() api_key = "6ac329b820cbaa7ac52a6" count = 0 with open("registered_domains.txt", "w", encoding='utf-8') as registered_domains: pass with open("expensive_domains.txt", "w", encoding='utf-8') as expensive_domains: pass def registered_or_expensive(file_write_name, file_delete_name, price, answer): with open(file_write_name, "a") as file: file.write(f'{domain_name} {price} {str(domain_price)}\n') print(answer) with open(file_delete_name, "r+") as my_file: new_f = my_file.readlines() my_file.seek(0) for line in new_f: if domain_name not in line: my_file.write(line) my_file.truncate() while count < 100: time.sleep(10) if len(domain_name) < 1: f.close() f = open('1.txt') domain_name = f.readline() count += 1 if len(domain_name) < 1: f.close() print("Файл пустой") break else: domain_name = re.sub("^\s+|\n|\r|\s+quot;, '', domain_name) # print(domain_name) response_url = f'https://www.namesilo.com/api/checkRegisterAvailability \ ?version=1&type=xml&key={api_key}&domains={domain_name}' response = requests.post(response_url).text a = response.split() try: if "unavailable" in a[2]: print(f"Домен {domain_name} занят") elif "available" in a[2]: print("Домен свободен") domain_price = float(re.sub(r'[^0-9.]+', r'', str(a[3]))) print(domain_name, domain_price) if domain_price < 10: print("Пробую купить доменное имя") print(f'Домен стоит: {str(domain_price)} USD') # покупка buydomain = requests.post(f"https://www.namesilo.com/api/ \ registerDomain?version=1&type=xml&key={api_key}&domain={str \ (domain_name)}&years=1&private=1&auto_renew=1/?rid=d3b8778js") print(buydomain.text) no_money_answer = "Sorry, you do not have enough available \ NameSilo account funds for this transaction." success_answer = "Your domain registration was successfully \processed." if no_money_answer in buydomain.text: print("Покупка не удалась, пополните свой балланс") elif success_answer in buydomain.text: registered_or_expensive("registered_domains.txt", \ "1.txt", "куплен по цене", "Домен зарегистрирован и \сохранен в файл registered_domains.txt") else: print("Регистрация неуспешна") else: print(f'Домен стоит дороже: {str(domain_price)} USD') registered_or_expensive("expensive_domains.txt", "1.txt", \ "стоит", "Домен перемешен в файл expensive_domains.txt") except: print("Неизвестная ошибка") finally: print("______________________________") domain_name = f.readline() f.close()
Данный код взят на сайте - https://4python.pythonanywhere.com/checker4registration.html