PythonPrank #1

Intermediate: dl dl dl

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.

Quick Disclaimers:
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.

Part 1:

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'

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('', 587)
server.login(gmail_sender, gmail_passwd)

# Generate the email
BODY = '\r\n'.join([
        'To: %s' % TO,
        'From: %s' % gmail_sender,
        'Subject: %s' % SUBJECT,
    server.sendmail(gmail_sender, [TO], BODY)
    print ('email sent using ' + var)
    print ('error sending email')

# Disconnect

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!

Part 2:

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:
print (mylist)


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


Side Note:

Don’t name this python file It messes with python severely. Just take my word for it.


You’re Done!

That’s it everyone! As always,
Have a nice day and thank you for your time.

Leave a Reply

Your email address will not be published. Required fields are marked *