Repository: marclave/InstaBot Branch: master Commit: b20c21fa4094 Files: 6 Total size: 5.8 KB Directory structure: gitextract_5mg3o5vr/ ├── InstaBot.py ├── PycURL Download.md ├── README.md ├── hashtags.txt ├── profile.yml └── requirements.txt ================================================ FILE CONTENTS ================================================ ================================================ FILE: InstaBot.py ================================================ import mechanize, yaml, re, time, sys, pycurl, hmac, urllib from hashlib import sha256 WEBSTA_URL = "http://websta.me/" WEBSTA_HASHTAG = WEBSTA_URL + "hot" INSTAGRAM_API = "https://api.instagram.com/v1/media/" USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11' # Function to encode the string with the IP and ID of the picture then like it def encodeAndRequest(id): c = pycurl.Curl() signature = hmac.new(str(profile['CREDENTIALS']['CLIENT_SECRET']), profile['IP'], sha256).hexdigest() header = '|'.join([profile['IP'], signature]) header = ["X-Insta-Forwarded-For: " + header] url = INSTAGRAM_API + id + "/likes" c.setopt(c.URL, url) c.setopt(c.POSTFIELDS, "access_token=" + str(profile['CREDENTIALS']['ACCESS_TOKEN'])) c.setopt(pycurl.HTTPHEADER, header) c.perform() response = str(c.getinfo(c.HTTP_CODE)) c.close() return response # Function to parse the Top HashTag page and get the current top hashtags def getTopHashTags(br): br.open(WEBSTA_HASHTAG) topHashtags = re.findall('\"\>#(.*)\<\/a\>\<\/strong\>', br.response().read()) return topHashtags # Function to read the hashtags from a users file if not wanting to parse the top 100 def getHashtagsFromFile(): #your list of hashtags hashtags = [] filename = 'hashtags.txt' #Hashtag file input f = open(filename) #strips newline character hashtags = [unicode(line.strip(), 'utf-8') for line in open(filename)] f.close() return hashtags # Function to like hashtages def like(br, hashtags): likes = 0 for hashtag in hashtags: hashtaglikes = 0 media_id = [] response = br.open(WEBSTA_URL +"tag/" + urllib.quote(hashtag.encode('utf-8'))) print u"Liking #%s" % hashtag media_id = re.findall("span class=\"like_count_(.*)\"", response.read()) for id in media_id: if profile['MAXLIKES'] == "NO_MAX": pass elif likes >= int(profile['MAXLIKES']): print "You have reached MAX_LIKES(" + str(profile['MAXLIKES']) + ")" print u"This # is currently %s" % hashtag sys.exit() break if profile['PERHASHTAG'] == "NO_MAX": pass elif hashtaglikes >= int(profile['PERHASHTAG']): print "REACHED MAX_LIKES PER HASHTAG" print "MOVING ONTO NEXT HASHTAG" hashtaglikes = 0 break response = encodeAndRequest(id) if bool(re.search("200", response)): print " YOU LIKED " + str(id) likes += 1 hashtaglikes += 1 time.sleep(profile['SLEEPTIME']) else: print "SOMETHING WENT WRONG" print response print "SLEEPING FOR 60 seconds" print "CURRENTLY LIKED " + str(likes) + " photos" time.sleep(60) print "YOU LIKED " + str(likes) + " photos" if __name__ == "__main__": print "=================================" print " InstaBot " print " Developed by Marc Laventure " print "=================================" print "" profile = yaml.safe_load(open("profile.yml", "r")) br = mechanize.Browser() br.set_handle_robots(False) br.set_handle_equiv(False) br.addheaders = [('User-Agent', USER_AGENT), ('Accept', '*/*')] if profile['TOP'] == 1: hashtags = getTopHashTags(br) else: hashtags = getHashtagsFromFile() like(br, hashtags) ================================================ FILE: PycURL Download.md ================================================ [Download PycURL](http://pycurl.sourceforge.net/) Run ``` tar -xvf pycurl-7.19.5.tar.gz cd pycurl-7.19.5/ sudo python setup.py install ``` ================================================ FILE: README.md ================================================ InstaBot ======== NOTE BIG UPDATE ON FUCTIONALITY; PLEASE UPDATE YOUR WORKING COPY AND FOLLOW NEW INSTRUCTIONS! A simple Instagram bot that pulls trending top 100 hashtags and auto likes pictures with those hashtags to get more followers. Developed in Python and built with the mechanize library STILL IN DEVELOPMENT, CONTRIBUTIONS ARE WELCOME ##Setup Clone this repository: ``` git clone https://github.com/marclave/InstaBot.git ``` run the following command to install the required libraries: ``` sudo pip install -r requirements.txt ``` 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 get your access token: use the "Client ID" and "Redirect URL" from the previous step and go to this address on your browser: ``` https://instagram.com/oauth/authorize/?client_id=INSERT_CLIENTID&redirect_uri=INSERT_REDIRECTURI&response_type=token ``` You would get redirected to your redirect url with your access token: ``` http://REDIRECT.URL/#access_token=YOUR_ACCESS_TOKEN_IS_HERE ``` now do the same thing with the following URL to authenticate likes on this Client ID: ``` https://instagram.com/oauth/authorize/?client_id=INSERT_CLIENTID&redirect_uri=INSERT_REDIRECTURI&response_type=code&scope=likes+basic ``` 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 ``` 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 separated by line, example: ``` I Love Python ``` Then run: ``` python InstaBot.py ``` ================================================ FILE: hashtags.txt ================================================ I Love Python ================================================ FILE: profile.yml ================================================ CREDENTIALS: ACCESS_TOKEN: USER_ACCESS_TOKEN CLIENT_SECRET: "USER_CLIENT_SECRET" SLEEPTIME: 1 MAXLIKES: 10 PERHASHTAG: 2 TOP: 1 IP: "USER_IP_ADDRESS" ================================================ FILE: requirements.txt ================================================ mechanize PyYAML pycurl