Python Forum
how to make this script work faster
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make this script work faster
#1
def main():

    # Email Filter
    # By DsWeb19778

    gmail, yahoo, hotmail, outlook, mailru, web = "@gmail", "@yahoo", "@hotmail", "@outlook", "@mail.ru", "@web."

    print("[+] FILTER EMAILS by [DSWEB19778]")

    myFile = input("[+] MAILLIST FILE >> ")

    mode = "r"
    open_me = open(myFile, mode, encoding="utf8")
    read_me = open_me.readlines()

    for mails in read_me:

        def save_to_file(nameFile, x, msg):
            kl = open(nameFile, 'a+', encoding="utf8")
            kl.write(x+"\n")
            kl.close()
            print(msg)

        email = mails.strip()
        email = mails.lower()

        if (gmail in email):
            save_to_file("gmail.txt", email, "[+] Saved "+email)
        elif (yahoo in email):
            save_to_file("yahoo.txt", email, "[+] Saved "+email)
        elif (hotmail in email):
            save_to_file("hotmail.txt", email, "[+] Saved "+email)
        elif (outlook in email):
            save_to_file("outlook.txt", email, "[+] Saved "+email)
        elif (mailru in email):
            save_to_file("mailru.txt", email, "[+] Saved "+email)
        elif (web in email):
            save_to_file("web.txt", email, "[+] Saved "+email)
        else:
            save_to_file("others.txt", email, "[-] Uknown : "+email)

    print(""" 
--> FINAL Processing Rzlt : 
===========================================
[+] GMAIL : """+str(len(list(open("gmail.txt", encoding="utf8"))))+"""
[+] YAHOO : """+str(len(list(open("yahoo.txt", encoding="utf8"))))+"""
[+] HOTMAIL : """+str(len(list(open("hotmail.txt", encoding="utf8"))))+"""
[+] OUTLOOK : """+str(len(list(open("outlook.txt", encoding="utf8"))))+"""
[+] MAIL.RU : """+str(len(list(open("mailru.txt", encoding="utf8"))))+"""
[+] @WEB : """+str(len(list(open("web.txt", encoding="utf8"))))+"""
[+] Others EMAILS : """+str(len(list(open("others.txt", encoding="utf8"))))+"""
[TOTAL EMAIL] >> """+str(len(list(open(myFile, encoding="utf8"))))+"""
--- ENJOY ....
============================================
        """)


if __name__ == "__main__":
    main()
How to make this script more faster i just complet coding but i need some tricks to make it fast
Reply
#2
hello,

never compared the speed, but it would be nicer to read them all into a list

then you can sort the list
sorting python lists
and you can count what is in this list
you can count how many gmails there are in that one list

now that i am thinking about it, you do not even need to sort them

outputting them afterwards from the list should also be faster than outputting one by one to your file system
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020