mail = poplib.POP3_SSL(EMAIL_HOST) print(mail.getwelcome()) print(mail.user(EMAIL_USER_NAME)) print(mail.pass_(EMAIL_PASSWORD)) print(mail.stat()) print(mail.list())
if mail.stat()[1] > 0: print("You have new mail.") else: print("No new mail.")
numMessages = len(mail.list()[1]) for i in range(numMessages): for j in mail.retr(i+1)[1]: msg = email.message_from_string(str(j, 'utf-8')) payload = msg.get_payload() url = re.search("(?Phttps?://[^\s'\"]+)", payload) if url is not None: vurl = url.group("url") print(vurl) print("Downloading to: ", DOWNLOAD_FORMAT) call(["youtube-dl", "--max-downloads","1", "-o", DOWNLOAD_FORMAT, vurl]) mail.dele(i+1)[1]
Not bad except youtubedl is itself a python library you can just import it instead of using call
Caleb Evans
I always laugh when I see python code because of the design of range. The script is too trivial, there's nothing to say about it.
Caleb Gray
actually good python. noyce.
Camden Thomas
> using import
Kayden Davis
remove spacing, and put it all on 1 line so it executes fazter
Anthony Campbell
alternative?
Brayden Garcia
apt-get dpkg brew
Caleb Barnes
print("You have new mail." if mail.stat()[1] > 0 else "No new mail.")
for x, i in enumerate(mail.list()[1])):
import poplib,email,re,os
Lucas Stewart
word!
Cameron Sanders
why is it trivial?
Jeremiah Lee
Make your code more readable:
replace any larger than one/two word with a variable (used like a constant) which describes what it's doing or needed for
If referring to a "magic" index, replace it with a constant named something like new_mail_index
make all of your regex patterns referenced by a variable which describes what they do
Though i and j are suitable for loops, you should consider naming what they are iterating over rather than just giving them a random undescriptive single letter
Essentially, that main problem with your code is readability. You should refrain from having "magic" inline values, and instead refer to them by descriptive variables/constants. Additionally make sure all variables are descriptive to what they are used for, even if only used for a loop
Robert Young
w a t
Joseph Rodriguez
so user should pretend he's making youtube-poop downloaders for a big company that has 'koding style standards'?
>A. first and foremost, you must kode with klossy.
Andrew Cox
t. middle management shitter
Brandon Ortiz
Sure, if this is a one off "I just need this thing for a one time use" it's fine as is. But, having readable code (using whatever standards you fucking want) is great because if you ever need to revisit your code for some reason, or need something random to show a potential employer, you don't need to dig through documentation or reverse engineer it to understand it
Levi Foster
import just goes to the first result it can find. You never know what package you're getting. apt-get and others have verified sources.