Python Forum
how to make this script work faster - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code Review (https://python-forum.io/forum-46.html)
+--- Thread: how to make this script work faster (/thread-25597.html)



how to make this script work faster - dsweb19778 - Apr-04-2020

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


RE: how to make this script work faster - keuninkske - Apr-05-2020

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