Reformat file

pull/3/head
Tejasvi Nareddy 6 years ago
parent 8abeaac017
commit 8ed7a39b86

@ -2,9 +2,10 @@ import requests
import json import json
import os import os
def write_to_file(url, fname): def write_to_file(url, fname):
with open(fname, "a") as f: with open(fname, "a") as f:
f.write(url+"\n") f.write(url + "\n")
def main(): def main():
@ -22,14 +23,17 @@ def main():
username = input("\033[92;1m[\033[37;1m?\033[92;1m]\033[92;1m Input Username: \033[0m") username = input("\033[92;1m[\033[37;1m?\033[92;1m]\033[92;1m Input Username: \033[0m")
print() print()
fname = username+".txt" fname = username + ".txt"
if os.path.isfile(fname): if os.path.isfile(fname):
os.remove(fname) os.remove(fname)
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Removing previous file:\033[1;37m {}\033[0m".format(fname)) print(
"\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Removing previous file:\033[1;37m {}\033[0m".format(fname))
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Checking username\033[0m\033[1;37m {}\033[0m\033[1;92m on: \033[0m".format(username)) print(
"\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Checking username\033[0m\033[1;37m {}\033[0m\033[1;92m on: "
"\033[0m".format(
username))
raw = open("data.json", "r") raw = open("data.json", "r")
data = json.load(raw) data = json.load(raw)
@ -43,38 +47,38 @@ def main():
for social_network in data: for social_network in data:
url = data.get(social_network).get("url").format(username) url = data.get(social_network).get("url").format(username)
error_type = data.get(social_network).get("errorType") error_type = data.get(social_network).get("errorType")
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
if error_type == "message": if error_type == "message":
error = data.get(social_network).get("errorMsg") error = data.get(social_network).get("errorMsg")
if not error in r.text: if not error in r.text:
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
write_to_file(url, fname) write_to_file(url, fname)
else: else:
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
elif error_type == "status_code": elif error_type == "status_code":
if not r.status_code == 404: if not r.status_code == 404:
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
write_to_file(url, fname) write_to_file(url, fname)
else: else:
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
elif error_type == "response_url": elif error_type == "response_url":
error = data.get(social_network).get("errorMsgInUrl") error = data.get(social_network).get("errorMsgInUrl")
if not error in r.url: if not error in r.url:
print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url) print("\033[37;1m[\033[92;1m+\033[37;1m]\033[92;1m {}:\033[0m".format(social_network), url)
write_to_file(url, fname) write_to_file(url, fname)
else: else:
print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network)) print("\033[37;1m[\033[91;1m-\033[37;1m]\033[92;1m {}:\033[93;1m Not Found!".format(social_network))
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Saved: \033[37;1m{}\033[0m".format(username + ".txt"))
print("\033[1;92m[\033[0m\033[1;77m*\033[0m\033[1;92m] Saved: \033[37;1m{}\033[0m".format(username+".txt")) main()
main()

Loading…
Cancel
Save