My journey to making a TWITTER BOT with PYTHON/SELENIUM and showing you how to do it

Grimasaur

Junior Member
Joined
Apr 8, 2016
Messages
191
Reaction score
100
Making a twitter bot and showing how i do it


Hello guys, i will make the bot using python + selenium ,i already have experience in coding but mostly in java where i have used selenium before but i want to learn python so i will use python.
im not an expert coding but not a newbie i have my general knowlenge of coding but i have to apply that specifically to python.

I start this journey just to make myself focus and finish this bot since im a person who usually gives up on things , and that its something that i dislike so i want to change it and i will start making this bot.
I will put the features i want to include or new features that i think later , it will be nice if you guys tell me what you would like the bot to have so i may put it too.
right now the bot can do this:
btw some features may seem obvious but are part of the bot , on the next post i will explain some parts more deeply or some of the functions the bot has or uses that the user wont see , like how the functions interact with themselves etc.

Features will be on green
To do will be on yellow
Know bugs will be on red
Finished today will be on blue
New functions added will be on orange
Bugs eliminated will be just deleted

  • login (obvious)
  • follow people
    • follow people based on keywords
    • follow people between time intervals
    • follow a certain number of people each interval
  • unfollow
    • unfollow people based on the time you followed them
    • unfollow people between time invervals
    • unfollow a certain number of people each interval
  • delete tweet
    • delete a certain number of tweets ( can also delete them all)
      • gets stuck when there is a retweet
  • tweet
    • schedule tweets for a certain time
  • get followers number
  • get following number
  • get tweet number
  • use proxy (only tested with public proxy)
  • retweet
  • fav
  • retweet based on keyword
  • fav based on keyword
  • reply to people
    • reply people that tweeted certain words (example "how do i do x thing" reply "you can use x program")
  • post picture
  • send dm
    • send dm when people follow you
  • copy tweets from accounts
  • copy pictures from accounts
i hope its clear enought, all the critics are welcome.
btw if someone its curious i was mostly inspired reading @apex1 journey and my idea is to code this bot and start to sell it,

Right now im coding the unfollowing function , still basic since the core of the bot isnt even started right now im just doing some basic functions that later will be modified for example some functions now require the attribute of the name of the account to simplify some things to do but later i will store the name of the account as an attribute of the class so all functions can access it, the unfollowing function now is as follows
(its on pseudocode so anyone can understand it)

unfollow(name):
if ( the url isnt "twitter"+name+"/following")
go to ("twitter"+name+"/following")​
personlist = driver.find_elements(people to unfollow)
for person in personlist:
wait until the unfollow button its visible #just in case it isnt visible to eliminate bugs
click the unfollow button​

now i want to make that you unfollow people based on some interval of people that the program gives you and also you unfollow a certain amount of people , example
you set unfollow time interval to betweet 10 to 20 sec and unfollow amount to 2 to 5
so an example will be 13 secconds delay 3 people unfollowed then you get 16 seccond delay 2 people unfollowed , i think you get it guys.
so to code it we will have to pass that attributes to the function

unfollow(name,min time,max time,min people,max people):

now we get a random number between the interval , on python i use the function randrange(min,max)
so it will be

time=randrange(min time,max time)
people=randrange(min peolpe,max people)

now from our old method we edit a few things, we want our list of people to be the size of the people that we want to unfollow this time (this will change later you will see maybe other day)
so on python its easy

personlist = driver.find_elements(people to unfollow)[:people]

with [:X] you get the X first elements of a list , but on our method this may get us some problems since maybe there isnt enought people so we will add some scroll down method until we get enought people
(later this will be determined also by the number of people you are following so we dont get stuck if we want to unfollow 10 people and we only follow 1)

personlist = driver.find_elements(people to unfollow)
while(tamaño personlist < people):
scroll down
personlist = driver.find_elements(people to unfollow)​
personlist = personlist[:people]

now we get our list of persons to unfollow , and for the timing interval we just have to put a sleep

sleep(time)

and we will end with something like this

unfollow(name,min time,max time,min people,max people):
time=randrange(min time,max time)
people=randrange(min peolpe,max people)
if ( the url isnt "twitter"+name+"/following")
go to ("twitter"+name+"/following")​
personlist = driver.find_elements(people to unfollow)
while(tamaño personlist < people):
scroll down
personlist = driver.find_elements(people to unfollow)​
personlist = personlist[:people]
for person in personlist:
wait until the unfollow button its visible #just in case it isnt visible to eliminate bugs
click the unfollow button​
sleep(time)​
I hope you guys find this usefull , see you on the next post! btw i dont know how much frequently i will post , but atleast once a week but anyway i will be there answering you guys on comenting how to do things better see you!
 
Wishing you the best of luck. NEVER GIVE UP!

 
Btw is there anyway to change the tittle? i think that putting anything more informative would be better like "[JOURNEY] making a twitter bot python + selenium" or something like that
 
@Grimasaur thanks for the shout out :) I'm following your journey. You should set a firm deadline for what date you will finish your bot.

Did you decide what kind of GUI are you going to be using?

All the best my friend.
 
Twitter bans fast and detect Bot Behaviour - Make a Bot for Google plus, that would be useful!
 
@Grimasaur thanks for the shout out :) I'm following your journey. You should set a firm deadline for what date you will finish your bot.

Did you decide what kind of GUI are you going to be using?

All the best my friend.

im right now testing some gui , i passed on pyqt5 since their free licensing isnt free of comercial use so im checking tkinter that its already in python for making guis and i may go with that since it seems similar to the way of making guis in java

Twitter bans fast and detect Bot Behaviour - Make a Bot for Google plus, that would be useful!

im making this bot mostly as a way of learning python and improving with it , after i finish it i can try to make a google plus bot , i actually havent seen any google plus bots do people really want/need them?
 
Hello guys this is the updated bot features

Features will be on green
To do will be on yellow
Know bugs will be on red
Finished today will be on blue
New functions added will be on orange
Bugs eliminated will be just deleted

  • login (obvious)
  • follow people
    • follow people based on keywords
    • follow people between time intervals
    • follow a certain number of people each interval
  • unfollow
    • unfollow people based on the time you followed them
    • unfollow people between time invervals
    • unfollow a certain number of people each interval
  • delete tweet
    • delete a certain number of tweets ( can also delete them all)
      • gets stuck when there is a retweet
  • tweet
    • schedule tweets for a certain time
  • get followers number
  • get following number
  • get tweet number
  • use proxy (only tested with public proxy)
  • retweet
    • retweet based on keyword
  • fav
    • fav based on keyword
  • reply to people
    • reply people that tweeted certain words (example "how do i do x thing" reply "you can use x program")
  • post picture
  • send dm
    • send dm when people follow you
  • copy tweets from accounts
  • copy pictures from accounts
I have made the bot able to retweet ,fav and reply to tweets it was pretty simple so nothing much to explain i will put an example in pseudocode
Code:
def reply(reply):
     tweet = look for a tweet
     driver.find( the reply button ) and click it
     wait until the window of reply its visible
     driver.find( the reply box).send_keys( reply)
     driver.find( the button to send it).click()
     waint until the window of reply isnt visible

what ive been doing mostly was mess around with some methods to make guis on python and i think that i will stick to tkinter, but honestly gui arent really my thing im much better just coding what the software has to do instead of coding a gui that doesnt look like trash XD
i will mostly mess with making an early gui and i will finish some more functions in the meantime
 
With your journey bro that's a nice one coming from you, don't give up know it you can get that you want if you don't give up
 
nice programming skills
keep up the good work.
where u visit on web to clear ur bottleneck?
 
nice programming skills
keep up the good work.
where u visit on web to clear ur bottleneck?

I dont understand exactly what you mean , but if you mean how i debug my code i use the debuger but also just observing the bot running lets me see if there is some problem with it.
also i print some parts to see whats going on like when i was doing the follow people function my bot was returning the names of the people that he was going to follow or the ones that i was allready following
for example i will see something like

"following: username1"
"allready followed: username123123"

but if i run the bot again i will see

"already followed: username1"
"already followed: username123123"

or things like that
 
Hello guys , i have been relaxing this week since it was my birthday etc but i will post my progress anyway , ive been working on my gui only researching and looking for information since im really bad making guis hahaha i will say that it takes me maybe 5 times the time to make a simple gui than to make a simple scrip but here is my progress.

RYpRZENyTGW9X5nknUApWw.jpg


have in mind that its temporal but its kinda like the early design that it comes to my mind.
you will have a section on the left where you can see your accounts , proxy etc , then on the right there is a section to add new accounts or modify the ones you already have.
behind that you will find the options panel wich checkbox for every option ,for example you want the account to follow then you click the checkbox and fill the entrys.
When you click on an account their details will go to the right panel for example.
y_5NqrmUSyyUQorQb4cXqw.jpg

so there you could modify the name or whatever.
My plan right now its to finish all the methods on the right box and made them work in the gui and then add a few necesary things like store info on a txt file or whatever and be able to read from other txt files too like for example
import your proxy list or account list.

thats my progress so far right now i hope you guys like it more updates will come soon hopefully after i get a kinda working bot!
 
Don't you dare give up. You are on to something. I want to see you succeed.
 
This looks very interesting. All the best to you on this journey and never give up. :)
 
Hello guys a little update today,im still mostly coding the gui since its the hardest thing to do for me.
some new important features added are
be able to store information about the accounts (name , pass , proxy ,........)
load that information on start.
update followers and following number every time you log in to the account
multithreading(needs to be applied on a lot of parts still)
we could say that right now the bot with the gui "works" but only to follow people and the gui needs a lot of improvements
ive also done a little improvements to the follow method since its the one im using to test the gui

Features will be on green
To do will be on yellow
Know bugs will be on red
Finished today will be on blue
New functions added will be on orange
Bugs eliminated will be just deleted

  • login (obvious)
  • follow people
    • follow people based on keywords
    • follow people between time intervals
    • follow a certain number of people each interval
    • maximun daily follows
  • unfollow
    • unfollow people based on the time you followed them
    • unfollow people between time invervals
    • unfollow a certain number of people each interval
  • delete tweet
    • delete a certain number of tweets ( can also delete them all)
      • gets stuck when there is a retweet (simplest way to solve this will be deleting the retweet but i will make a more complex way)
  • tweet
    • schedule tweets for a certain time
  • get followers number
  • get following number
  • get tweet number
  • use proxy (only tested with public proxy)
  • retweet
    • retweet based on keyword
  • fav
    • fav based on keyword
  • reply to people
    • reply people that tweeted certain words (example "how do i do x thing" reply "you can use x program")
  • post picture
  • send dm
    • send dm when people follow you
  • copy tweets from accounts
  • copy pictures from accounts
Thats all for now , will post more updates when there is more noticiable changes
 
I think i have finished the basics of the gui i have something a little usable right now
so i will now try to develop the bot 20% gui 40% functions 40% bot general improvements ( optimization debuggin etc)

this is the gui now
NZaUNvYuTHGUunZiQBS0HA.jpg

the name password and proxy will automatically get displayed when you click an account on the right
the modify button will save the name pass and proxy to the account selected
inser will create a new account with the things inside the boxes of name etc
the options for the methods wont come unless you click the load options button
update selected and update all buttons will do what they say (they only update the options not the name or pass wif you changed them)
this is what the gui looks with some data in it
f4DEAd2TQSGUD5LX2AQs9g.jpg


Now i have some dilema im not sure how i will develop the start method for multiple accounts?
i have some ideas
  • 1 account per thread and they will do the actions linear example: if you have 4 threads it will run 4 accounts at a time and they will follow first then unfollow then retweet etc as all methods are put in the gui
  • only 1 account at a time but multiple threads to do everything at once (you will be following unfollowing retweeting etc )
  • more than one account at a time and they do everything at once splitting their task example : 1 account has follow and retweet and other has follow unfollow retweet adnt reply so acc 1 consumes 2 threads and acc 2 consumes 4 threads so if your cpu has 8 cores you have 2 cores left and you will fill those cores as you free them
  • the most cool idea that i thought was that you have 1 account but when the bot has to wait you do other things for example you follow people but you have to wait 30 sec to follow more people so you go to other account and do things until the 30 sec are over (that will be hard to do i think but pretty cool)
tell me your ideas guys!
i think that now that i have some kind of gui i will be working 20% on more gui , 40% more methods for the bot 40% fixing and optimization of things already made
hope to get another update soon!
 
Back
Top