Hello all, Blu3 here. I haven’t posted in awhile but that’s been because I’ve been trapped by a python. In this case it’s the coding language. In this post I’ll show my first python prank I designed to get my friends with. All the pranks made in PythonPranks will work in python 3.
This could potentially mess up someone’s day, just keep that in mind.
I’m still very amateur in python, if you know how to optimize any of these feel free to contact us! I would really appreciate the help.
Alright now down to the fun stuff. My first trip into the jaws of python was not really that scary, I had heard you could e-mail with it so I wanted to give it a shot. For this script I used gmail as the server host. So this will ONLY work with gmail sender addresses.
import smtplib import random # Set the variables recipient = input("Enter the recipient's email: ") TO = recipient SUBJECT = 'Daily Cat Fact' #Randomizer rand = ['example fact 1', 'example fact 2'] var = random.choice(rand) # The text in the e-mail TEXT = var # Credentials gmail_sender = input('Please enter your email: ') gmail_passwd = input('Please enter your password: ') # Create connection to g-mail server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo server.login(gmail_sender, gmail_passwd) # Generate the email BODY = '\r\n'.join([ 'To: %s' % TO, 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT ]) try: server.sendmail(gmail_sender, [TO], BODY) print ('email sent using ' + var) except: print ('error sending email') # Disconnect server.quit()
The facts for the code I had to provide are a little dull so here is a little hastebin link that Crushfield kindly provided that has 255 cat facts!
First off you need to make a text document called ImportFact.txt, inside this paste all of those cat facts (or whatever else you want). Adding all those cat facts by hand into the code is a little annoying so instead I, predictably, made another script to print out all those facts into one list. Here it is:
import time f = open("ImportFact.txt", "r") mylist =  for fact in f: mylist.append(fact) print (mylist) time.sleep(5)
This will open up that text document you made and print out the entire list. You may want to extend the time sleep at the bottom because that’s what allows you to obtain your list. After you copy it all replace the examples in the line that says “rand = [‘example fact 1’, ‘example fact 2’]” with your list in the main emailer.py.
Don’t name this python file email.py. It messes with python severely. Just take my word for it.
That’s it everyone! As always,
Have a nice day and thank you for your time.