Your Lotto numbers in python

I have written a little script which generate number for your next lotto ticket.
Schedule it in the crontab to get your number each day you do need it.

Some variables would required to be set, such as email address and your password.
This script is using gmail’s account only.

Use the upload file instead of copy and paste 🙂

Download script

#!/usr/bin/python

import random
import smtplib
import time
import os, sys
from pathlib import Path


# SOME VARIABLE FOR THE EMAIL NOTIFICATION

fromaddr = "YOUR EMAIL"
toaddr = "YOUR EMAIL"
passfrom = "YOURPASSWORD"

# TIME TO GET INTO THE FILE
timestr = time.strftime(" %d-%m-%Y-%Hh%M")


# CHECKS IF FILE IS ALREADY PRESENT

my_file = Path("numbers")
if my_file.is_file():
        os.remove("numbers")

f = open( 'numbers', 'a' )
f.write('' + '\n')
f.write('' + '\n')
f.write('' + '\n')
f.write('Dear,' + '\n')
f.write('Find below your next Lotto:' + '\n')
f.write( 'Date:' +timestr + '\n' )
f.write("\n")

for i in range(1,4):

strings = i
list = []
i = 0
while i < 5:

n = random.sample(xrange(1,50), 1)
list.append (n)
i += 1

str1 = ','.join(map(str, list))
s = str1.replace("[", "")
s = s.replace("]", "")

# GENERATE THE SECOND BUNCH

list1 = []
j = 0
while j < 2:

m = random.sample(xrange(1,10), 1)
#m = random.randint(1, 10)
list1.append (m)
j += 1

str2 = ','.join(map(str, list1))
str2 = str2.replace("[", "")
str2 = str2.replace("]", "")

# WRITING ALL TO FILE

f.write("%s - %s - %s\n" % (strings, s, str2 ) )
f.close()

f = open( 'numbers', 'a' )
f.write('Your best team</p' + '\n')
f.write('' + '\n')
f.write('
' + '\n')
f.write('' + '\n')
f.close()

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Your next lotto numbers"
with open('numbers', 'r') as myfile:
    body=myfile.read().replace(',', '  ')


# REMOVING PLAIN TEXT - KEEP ONLY HTML

part1 = MIMEText(body, 'html', 'html')
msg.attach(part1)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()

server.login(fromaddr, passfrom)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)

print "MESSAGE SENT"
server.quit()

Leave a Reply

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