Skip to content

Commit 55d387d

Browse files
committed
Some changes, nothing interesting ))
Improved unfollow on cleanup, utf-8 encoding in file header, script work time on logout. Thanks for @rjmayott and @samosad and @ictek05
1 parent 7012cf4 commit 55d387d

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## InstaBot
2-
InstaBot v 1.0.1
2+
InstaBot v 1.0.1
33

44
Works without the new Instagram [api][1](the new review process)
55
Username and password stored local. Written in Python
66

7-
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=UM6L3YJENAQZ6&lc=US&item_name=InstaBot%2epy&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" title="Buy me a beer"><img src="http://www.mikkonen.info/polaroid_gallery/images/paypal_beer.png"></a>
7+
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=UM6L3YJENAQZ6&lc=US&item_name=InstaBot%2epy&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" title="Buy me a beer"><img src="https://img.shields.io/badge/Donate-PayPal-green.svg"></a>
88

99
## Requirements
1010
`Python2.7` minimum
@@ -115,13 +115,13 @@ Log mod: `log_mod=0` log to console, `log_mod=1` log to file, `log_mod=2` no log
115115
```python
116116
log_mod = 0
117117
```
118-
unfollow_break_min / unfollow_break_max: These define the randomly selected amount of time in seconds that it will pause between unfollows on a break.
118+
unfollow_break_min / unfollow_break_max: These define the randomly selected amount of time in seconds that it will pause between unfollows on a break.
119119
Example:
120120
```
121121
unfollow_break_min = 15
122-
unfollow_break_max = 30
122+
unfollow_break_max = 30
123123
```
124-
This will cause a delay of anywhere between 15 to 30 seconds between every unfollow.
124+
This will cause a delay of anywhere between 15 to 30 seconds between every unfollow.
125125
####6) Logout from exist session:
126126
```python
127127
bot.logout()
@@ -160,7 +160,7 @@ bot.like_all_exist_media(4)
160160

161161
2) Install Python lib `requests`. Run command `pip3 install requests` if you use `Python 3`, or type `pip install requests` if you use `Python 2`.
162162

163-
3) Download ZIP and extract
163+
3) Download ZIP and extract
164164

165165
4) Modify example.py to your pleasing
166166

example.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
from instabot import InstaBot
25

36
bot = InstaBot(login="my_username", password="my_password",
@@ -10,7 +13,6 @@
1013
unfollow_per_day=150,
1114
unfollow_break_min=15,
1215
unfollow_break_max=30,
13-
log_mod=0
14-
)
16+
log_mod=0)
1517

16-
bot.new_auto_mod()
18+
bot.new_auto_mod()

instabot.py

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
import requests
25
import random
36
import time
@@ -81,9 +84,10 @@ def __init__(self, login, password,
8184
tag_list=['cat', 'car', 'dog'],
8285
max_like_for_one_tag = 5,
8386
unfollow_break_min=15,
84-
unfollow_break_max=30,
87+
unfollow_break_max=30,
8588
log_mod = 0):
8689

90+
self.bot_start = datetime.datetime.now()
8791
self.unfollow_break_min = unfollow_break_min
8892
self.unfollow_break_max = unfollow_break_max
8993
self.time_in_day = 24*60*60
@@ -121,6 +125,10 @@ def __init__(self, login, password,
121125
self.log_mod = log_mod
122126

123127
self.s = requests.Session()
128+
# if you need proxy make something like this:
129+
# self.s.proxies = {"https" : "http://proxyip:proxyport"}
130+
# by @ageorgios
131+
124132
# convert login to lower
125133
self.user_login = login.lower()
126134
self.user_password = password
@@ -142,14 +150,13 @@ def cleanup (self):
142150
for f in self.bot_follow_list:
143151
log_string = "Trying to unfollow: %s" % (f[0])
144152
self.write_log(log_string)
145-
self.unfollow(f[0])
153+
self.unfollow_on_cleanup(f[0])
146154
sleeptime = random.randint(self.unfollow_break_min, self.unfollow_break_max)
147155
log_string = "Pausing for %i seconds... %i of %i" % (sleeptime, self.unfollow_counter, self.follow_counter)
148-
self.write_log(log_string)
149-
time.sleep(sleeptime)
156+
self.write_log(log_string)
157+
time.sleep(sleeptime)
150158
self.bot_follow_list.remove(f)
151159

152-
153160
# Logout
154161
if (self.login_status):
155162
self.logout()
@@ -200,6 +207,9 @@ def logout(self):
200207
(self.like_counter, self.follow_counter,
201208
self.unfollow_counter, self.comments_counter)
202209
self.write_log(log_string)
210+
work_time = datetime.datetime.now() - self.bot_start
211+
log_string = 'Bot work time: %s' %(work_time)
212+
self.write_log(log_string)
203213

204214
try:
205215
logout_post = {'csrfmiddlewaretoken' : self.csrftoken}
@@ -358,6 +368,21 @@ def follow(self, user_id):
358368

359369
def unfollow(self, user_id):
360370
""" Send http request to unfollow """
371+
if (self.login_status):
372+
url_unfollow = self.url_unfollow % (user_id)
373+
try:
374+
unfollow = self.s.post(url_unfollow)
375+
if unfollow.status_code == 200:
376+
self.unfollow_counter += 1
377+
log_string = "Unfollow: %s #%i." % (user_id, self.unfollow_counter)
378+
self.write_log(log_string)
379+
return unfollow
380+
except:
381+
self.write_log("Exept on unfollow!")
382+
return False
383+
384+
def unfollow_on_cleanup(self, user_id):
385+
""" Unfollow on cleanup by @rjmayott """
361386
if (self.login_status):
362387
url_unfollow = self.url_unfollow % (user_id)
363388
try:
@@ -383,7 +408,7 @@ def unfollow(self, user_id):
383408
return unfollow
384409
except:
385410
log_string = "Except on unfollow... Looks like a network error"
386-
self.write_log(log_string)
411+
self.write_log(log_string)
387412
return False
388413

389414
def auto_mod(self):

userinfo.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
import requests
25
import json
36

0 commit comments

Comments
 (0)