Saturday, July 6, 2013

How to send messages to billions of users on facebook with one simple script

 Although title looks good,but due to facebook's spam preventing algorithm this message will be sent to other folder[rarely people will see them],but if the user is a friend of your's then you can send message directly



#usr/bin/env/python
"""
This script can get the user data from facebook.com.
This is written for better understanding of python 
Modules required:BeautifulSoup
Author:Ajay Kumar Medepalli
Blog:http://pythonnotesbyajay.blogspot.in/
"""
import smtplib
import email
from email.MIMEMultipart import MIMEMultipart
from email.parser import Parser
from email.MIMEText import MIMEText
import urllib2
from BeautifulSoup import BeautifulSoup
import time
import random

user_name_array=[]
def get_fb_username(id):
    try:
        url=urllib2.urlopen('https://graph.facebook.com/'+str(id)).read()
        soup = BeautifulSoup(url)
        all_attr=soup.prettify()
        print all_attr
        gend=all_attr.find("gender")
        if(all_attr[gend+9] == 'm'):
            gender='male'
        elif (all_attr[gend+9] == 'f'):
            gender = 'female'
        else:
            gender="The user didn't specify any gender"
        if all_attr.find('username') != -1:
            start_quote=all_attr.find('username')+10
            end_quote=all_attr.find('"',start_quote+1)
            user_name=all_attr[start_quote:end_quote+1].strip('"')+'@facebook.com'

            user_name_array.append(user_name)
            print "username ==>"+'\t'+user_name +'\t'+ "gender ==>"+"\t"+gender
            print "\n"
        
    except urllib2.HTTPError:
        pass


    

for i in range(124896015,124896016,1):
#for i in range(startvalue,stopvalue,stepvalue):
    get_fb_username(i+1)
print user_name_array

def send_mail():
    random_text=["hi","hello","Nice to meet you","How are you","wassup","hi!!!",'just wanted to say hi']
    server = smtplib.SMTP()
    server.connect('smtp.gmail.com', 587) # for eg. host = 'smtp.gmail.com', port = 587
    server.ehlo()
    server.starttls()
    server.login('username@gmail.com', 'password')
    #replace this with u r gmail id
    #password ==> ur gmail password
    fromaddr ='username@gmail.com'

    for i in range(len(user_name_array)-1):

        msg = email.MIMEMultipart.MIMEMultipart()
        msg['From'] = fromaddr
        msg['To'] = user_name_array[i]
        msg['Subject'] = 'hi'
        
        msg.attach(MIMEText(random_text[random.randint(0,len(random_text)-1)]))
        #msg.attach(MIMEText('put some custom message.', 'plain')) 
        server.sendmail(fromaddr,user_name_array[i],msg.as_string())
    server.quit()  
send_mail()

But you need to make few changes
1.change the numbers in the range function,if you've a fast computer then you can start all the way from 4 to 5000000 (Mark zuckerberg has id =4)
2.change the user@gmail.com,password with your details
3.Edit the message you want to send aswell
How to use this??
pip install BeautifulSoup ==>Download this module
a.copy and paste this script somewhere on u rcomputer
b.cd somewhere
c.python scriptname.py



Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.

No comments:

Post a Comment