Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
07c2ce2
Secure requests were tried to implement. Configuration files paths we…
quasiyoke Jun 8, 2015
2879523
Mechanize and pycurl dependencies were replaced by Requests dependency.
quasiyoke Jun 9, 2015
cfdc85d
Unicode console output troubles were fixed.
quasiyoke Jun 9, 2015
48c4279
Instagram private API was used to like media.
quasiyoke Jun 10, 2015
58014a0
Stateful like scheduler was implemented.
quasiyoke Jun 10, 2015
7c2fac4
README.md was updated. Requirements were put at requirements.txt
quasiyoke Jun 10, 2015
3a431e1
Repo link was fixed at README.md
quasiyoke Jun 10, 2015
b06c927
Login was fixed. Logging was slightly improved.
quasiyoke Jan 15, 2016
84761b0
Complete refactoring.
quasiyoke Feb 18, 2016
40d999f
Bot installation works properly.
quasiyoke Feb 18, 2016
f395b9e
UserService is working.
quasiyoke Feb 19, 2016
4e29c6a
FollowingService is working.
quasiyoke Feb 20, 2016
9e7c91f
LikeService is working.
quasiyoke Feb 22, 2016
7d508d8
UserService was fixed. ClientResponseError handling was added, minor …
quasiyoke Feb 23, 2016
5bdb5bd
Minor fixes at README.md and UserService
quasiyoke Feb 24, 2016
e278a1b
PyMySQL was added to requirements.
quasiyoke Feb 24, 2016
c5ec1c9
Log files were added to .gitignore
quasiyoke Feb 24, 2016
50f5d54
Logging into file was described at README.md
quasiyoke Feb 24, 2016
4d7876f
Delays after unsuccessful requests were added.
quasiyoke Feb 24, 2016
7e410b4
Bumped version number to 0.2.1.
quasiyoke Feb 24, 2016
7cb2220
Amount of logging was reduced in case of 5XX errors.
quasiyoke Feb 24, 2016
979513f
Closing connection in case of bad response was fixed.
quasiyoke Feb 24, 2016
aa2f57d
Virtualenv was added to .gitignore.
quasiyoke May 31, 2016
8058c6d
Websta.me was replaced by tags exploration inside Instagram
quasiyoke May 31, 2016
54fdc58
Bumped version number to 0.2.2.
quasiyoke May 31, 2016
9628453
PEP8 was applied to the sources.
quasiyoke Aug 27, 2016
202762f
Python 3.5: `@asyncio.coroutine` -> `async def`, `yield from` -> `awa…
quasiyoke Aug 27, 2016
d0b751f
We don't need `client_id` to fetch users followed by us anymore.
quasiyoke Aug 27, 2016
1a71078
"unfollow" command was added.
quasiyoke Aug 27, 2016
e6430f8
We don't need Instagram API to fetch followers anymore.
quasiyoke Aug 27, 2016
00cb976
Bumped version number to 0.3.0.
quasiyoke Aug 27, 2016
e2f9db7
Merge branch 'dev'
quasiyoke Aug 27, 2016
9f0e58f
Unexpected Instagram data handling was added to `Client.get_some_foll…
quasiyoke Aug 28, 2016
6981dac
Bumped version number to 0.3.1.
quasiyoke Aug 28, 2016
4451328
Merge branch 'dev'
quasiyoke Aug 28, 2016
44121c1
Adding a docker compose file so that we can quickly spin up a databas…
Feb 25, 2017
20c50d4
fixed pep8 linter issue
Feb 25, 2017
e82c369
Updating get_some_followers to perform pagination
Feb 25, 2017
05de32f
Merge pull request #1 from alairock/master
quasiyoke Mar 2, 2017
5b52e28
Bumped version number to 0.3.2.
quasiyoke Mar 10, 2017
ed4cee2
`User`'s and `UserService`'s code was slightly enhanced.
quasiyoke Mar 10, 2017
ccb727b
Now the bot skips users that are failing to be unfollowed.
quasiyoke Mar 10, 2017
8d2d04e
We should use == operator for [Peewee queries](http://docs.peewee-orm…
quasiyoke Mar 10, 2017
e1715e9
`Client.get_following_page` was fixed.
quasiyoke Mar 11, 2017
12a2301
Bumping version number to 0.3.3.
quasiyoke Mar 11, 2017
27e1750
Merge branch 'dev'
quasiyoke Mar 11, 2017
3a01b66
Media is being fetched using authorised session now.
quasiyoke Mar 18, 2017
b3e5456
Merge branch 'dev'
quasiyoke Mar 18, 2017
77b7a66
Bumping version number to 0.3.5. Error response about temporary block…
quasiyoke Mar 31, 2017
d8947ce
Merge branch 'dev'
quasiyoke Mar 31, 2017
1e5aa0b
Logging was extended in case of temporary block.
quasiyoke Apr 9, 2017
4209f4b
Version number was bumped to 0.4.0. Dockerfile was added.
quasiyoke Jul 13, 2017
2d4135d
Merge branch 'dev'
quasiyoke Jul 13, 2017
57d3043
fix get media by hashtag search
velimir Jan 13, 2018
f6c8306
Merge pull request #2 from velimir0xff/fix-get-hashtag
quasiyoke Jan 13, 2018
5426f5c
Version number was bumped to 0.4.1
quasiyoke Jan 13, 2018
de707d7
Merge branch 'dev'
quasiyoke Jan 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.pyc

# Configuration
conf*.yml
conf*.yaml

# Logging
*.log
log.log.*

#virtualenv
/bin/
/include/
/lib/
/pip-selfcheck.json
/share/
instabotenv/
db_data/

13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.6
MAINTAINER Pyotr Ermishkin <quasiyoke@gmail.com>

COPY instabot /instabot/
COPY docker-entrypoint.sh /
COPY instabot_runner.py /
COPY requirements.txt /

VOLUME /configuration

RUN pip install -r requirements.txt

CMD ["/docker-entrypoint.sh"]
109 changes: 0 additions & 109 deletions InstaBot.py

This file was deleted.

9 changes: 0 additions & 9 deletions PycURL Download.md

This file was deleted.

128 changes: 82 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,97 @@
InstaBot
========
# InstaBot

NOTE BIG UPDATE ON FUCTIONALITY; PLEASE UPDATE YOUR WORKING COPY AND FOLLOW NEW INSTRUCTIONS!
Instagram bot written in Python 3 that cycles through specified hashtags and automatically likes pictures with those hashtags to get more followers. The bot also follows people and unfollows them after specified period of time. Unfollowed people are saved in DB to prevent following them again. To find new people to follow it uses list of followers of people you have followed.

A simple Instagram bot that pulls trending top 100 hashtags and auto likes pictures with those hashtags to get more followers.
During installation process it saves people followed by you as "followed long time ago" and unfollows them at the first start.

Developed in Python and built with the mechanize library
The bot doesn't use Instagram API so all credentials you need are your login and password.

STILL IN DEVELOPMENT, CONTRIBUTIONS ARE WELCOME
## Deployment

##Requirements

1. Python is installed (Tested with version 2.6.8)
2. mechanize library is installed [Mechanize download!](http://wwwsearch.sourceforge.net/mechanize/download.html) V0.2.5
3. PyYAML libray is installed [PyYAML download!](pyyaml.org/wiki/PyYAML) V3.11
4. Authenticated your instagram account on [websta.me](http://websta.me/)
5. PycURL library installed [PycURL download!](http://pycurl.sourceforge.net/) V7.19.5
6. Registered a client for your account on [instagram](http://instagram.com/developer/clients/manage/)

##Setup
Clone this repository:
```
git clone https://github.com/marclave/InstaBot.git
```sh
docker network create \
--subnet=172.21.0.0/24 \
instabot
docker run \
--name=instabot-mysql \
--net=instabot \
--ip=172.21.0.2 \
--env="MYSQL_ROOT_PASSWORD=ZEbMKcFQppk8m8PR3b" \
--env="MYSQL_DATABASE=instabot" \
--env="MYSQL_USER=instabot" \
--env="MYSQL_PASSWORD=KbWj0Eua78YGLNLf3K" \
--volume=`pwd`/lib:/var/lib/mysql \
--detach \
mysql:5.7
docker build --tag=instabot .
```
Follow install instructions for PycURL: [instructions](PycURL Download.md)

Go to [instagram clients](http://instagram.com/developer/clients/manage/)
Register your account for a developers client
Retrieve your CLIENT SECRET and USER ID token under "Manage Clients"
To retrieve your access token, go to [instagram api console](http://instagram.com/developer/api-console/)
Run a query involving your USER ID and grab your access token from the request
Create MySQL DB:

Note: Ensure likes are part of the access scope [enable likes scope](https://instagram.com/oauth/authorize/?client_id=INSERT_CLIENTID&redirect_uri=INSERT_REDIRECTURI&response_type=code&scope=likes+basic)
```sql
CREATE DATABASE IF NOT EXISTS instagram CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER instabot@localhost IDENTIFIED BY 'GT8H!b]5,9}A7';
GRANT ALL ON instagram.* TO instabot@localhost;
```

Create `configuration.yml` file containing your credentials, e.g.:

Modify the profile to include your information, example:
```
CREDENTIALS:
ACCESS_TOKEN: "USER_ACCESS_TOKEN"
CLIENT_SECRET: "USER_CLIENT_SECRET"
MAXLIKES: 1000 <- If you dont want a max, input NO_MAX
PERHASHTAG: 10 <- If you dont want a max, input NO_MAX
TOP: 1 <- To use the top hashtags on Websta.me use a 1
IP: "USER_IP_ADDRESS" <- run ipconfig or ifconfig to grab your ip address
```yaml
credentials:
username: "your_username"
password: "eKeFB2;AW6fS}z"
db:
host: "172.21.0.2"
name: "instabot"
user: "instabot"
password: "KbWj0Eua78YGLNLf3K"
following_hours: 120
hashtags:
- I
- люблю
- Python
instagram:
limit_sleep_time_coefficient: 1.3
limit_sleep_time_min: 30
success_sleep_time_coefficient: 0.5
success_sleep_time_max: 6
success_sleep_time_min: 4
logging:
version: 1
formatters:
simple:
class: logging.Formatter
format: "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
loggers:
instabot:
level: DEBUG
root:
level: DEBUG
handlers:
- console
users_to_follow_cache_size: 300
```
Note: If you do not put a 1 in the value of TOP then the program will look for a text file
called hashtags.txt.

The format for this file is to have each hashtag seperated by line, example:
Where:

```
I
Love
Python
```
* `following_hours` — how long users will stay followed.
* `hashtags` — list of hashtags to get photos to like. Optional. By default bot won't like anything.
* `logging` — logging setup as described in [this howto](https://docs.python.org/3/howto/logging.html).
* `users_to_follow_cache_size` — how much users should be fetched for following. The cache is being filled in once a minute. Optional. By default bot won't follow anybody.

Then run:
```
python InstaBot.py
Now you may run the bot:

```sh
docker run \
--name=instabot \
--net=instabot \
--ip=172.21.0.10 \
--volume=`pwd`/configuration:/configuration \
--detach \
instabot
```
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mysql:
image: mysql
ports:
- "3306:3306"
expose:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=instabotisgrate
- MYSQL_DATABASE=instagram
- MYSQL_USER=instabot
- MYSQL_PASSWORD=GT8H!b]5,9}A7
volumes:
- ./db_data:/var/lib/mysql
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

/instabot_runner.py install /configuration/configuration.yml
/instabot_runner.py /configuration/configuration.yml
3 changes: 0 additions & 3 deletions hashtags.txt

This file was deleted.

5 changes: 5 additions & 0 deletions instabot/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'''instabot.__main__: executed when instabot directory is called as script.'''

from .instabot import main

main()
49 changes: 49 additions & 0 deletions instabot/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import logging
import sys
import yaml

LOGGER = logging.getLogger('instabot.configuration')


class Configuration:
def __init__(self, filename):
try:
with open(filename, 'r') as f:
configuration = yaml.safe_load(f)
except (IOError, OSError, ValueError) as e:
sys.exit('Can\'t obtain configuration: {}'.format(e))
try:
self.db_host = configuration['db']['host']
self.db_name = configuration['db']['name']
self.db_user = configuration['db']['user']
self.db_password = configuration['db']['password']
self.following_hours = configuration['following_hours']
self.instagram_limit_sleep_time_coefficient = \
configuration['instagram']['limit_sleep_time_coefficient']
self.instagram_limit_sleep_time_min = \
configuration['instagram']['limit_sleep_time_min']
self.instagram_success_sleep_time_coefficient = \
configuration['instagram']['success_sleep_time_coefficient']
self.instagram_success_sleep_time_max = \
configuration['instagram']['success_sleep_time_max']
self.instagram_success_sleep_time_min = \
configuration['instagram']['success_sleep_time_min']
self.instagram_username = configuration['credentials']['username']
self.instagram_password = configuration['credentials']['password']
self.logging = configuration['logging']
except (KeyError, TypeError) as e:
sys.exit(
'Configuration is not fully specified. {} is missed.'
.format(e),
)
self.hashtags = configuration.get('hashtags', [])
self.users_to_follow_cache_size = configuration.get(
'users_to_follow_cache_size',
0,
)
try:
self.following_hours = int(self.following_hours)
self.users_to_follow_cache_size = \
int(self.users_to_follow_cache_size)
except ValueError as e:
sys.exit('Some integer value is specified wrong: {}'.format(e))
Loading