[
  {
    "path": "InstaBot.py",
    "content": "import mechanize, yaml, re, time, sys, pycurl, hmac, urllib\nfrom hashlib import sha256\n\nWEBSTA_URL = \"http://websta.me/\"\nWEBSTA_HASHTAG = WEBSTA_URL + \"hot\"\n\nINSTAGRAM_API = \"https://api.instagram.com/v1/media/\"\nUSER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'\n\n# Function to encode the string with the IP and ID of the picture then like it\ndef encodeAndRequest(id):\n\tc = pycurl.Curl()\n\tsignature = hmac.new(str(profile['CREDENTIALS']['CLIENT_SECRET']), profile['IP'], sha256).hexdigest()\n\theader = '|'.join([profile['IP'], signature])\n\theader = [\"X-Insta-Forwarded-For: \" + header]\n\n\turl = INSTAGRAM_API + id + \"/likes\"\n\tc.setopt(c.URL, url)\n\tc.setopt(c.POSTFIELDS, \"access_token=\" + str(profile['CREDENTIALS']['ACCESS_TOKEN']))\n\tc.setopt(pycurl.HTTPHEADER, header)\n\tc.perform()\n\n\tresponse = str(c.getinfo(c.HTTP_CODE))\n\tc.close()\n\t\n\treturn response\n\n# Function to parse the Top HashTag page and get the current top hashtags\ndef getTopHashTags(br):\n\tbr.open(WEBSTA_HASHTAG)\n\ttopHashtags = re.findall('\\\"\\>#(.*)\\<\\/a\\>\\<\\/strong\\>', br.response().read())\n\treturn topHashtags\n\t\n# Function to read the hashtags from a users file if not wanting to parse the top 100\ndef getHashtagsFromFile():\n    #your list of hashtags\n    hashtags = []\n    filename = 'hashtags.txt'\n    #Hashtag file input\n    f = open(filename)\n    #strips newline character\n    hashtags = [unicode(line.strip(), 'utf-8') for line in open(filename)]\n    f.close()\n    return hashtags\n\t\n# Function to like hashtages\ndef like(br, hashtags):\n    likes = 0\n\n    for hashtag in hashtags:\n        hashtaglikes = 0\n        media_id = []\n        response = br.open(WEBSTA_URL +\"tag/\" + urllib.quote(hashtag.encode('utf-8')))\n        print u\"Liking #%s\" % hashtag\n        media_id = re.findall(\"span class=\\\"like_count_(.*)\\\"\", response.read())\n\n        for id in media_id:\n\n            if profile['MAXLIKES'] == \"NO_MAX\":\n                pass\n            elif likes >= int(profile['MAXLIKES']):\n                print \"You have reached MAX_LIKES(\" + str(profile['MAXLIKES']) + \")\"\n                print u\"This # is currently %s\" % hashtag\n                sys.exit()\n                break\n\n            if profile['PERHASHTAG'] == \"NO_MAX\":\n                pass\n            elif hashtaglikes >= int(profile['PERHASHTAG']):\n                print \"REACHED MAX_LIKES PER HASHTAG\"\n                print \"MOVING ONTO NEXT HASHTAG\"\n                hashtaglikes = 0\n                break\n\n            response = encodeAndRequest(id)\n\n            if bool(re.search(\"200\", response)):\n                print \" YOU LIKED \" + str(id)\n                likes += 1\n                hashtaglikes += 1\n                time.sleep(profile['SLEEPTIME'])\n            else:\n                print \"SOMETHING WENT WRONG\"\n                print response\n                print \"SLEEPING FOR 60 seconds\"\n                print \"CURRENTLY LIKED \" + str(likes) + \" photos\"\n                time.sleep(60)\n\n    print \"YOU LIKED \" + str(likes) + \" photos\"\n\nif __name__ == \"__main__\":\n\n\tprint \"=================================\"\n\tprint \"            InstaBot             \"\n\tprint \"    Developed by Marc Laventure  \"\n\tprint \"=================================\"\n\tprint \"\"\n\n\tprofile = yaml.safe_load(open(\"profile.yml\", \"r\"))\t\n\tbr = mechanize.Browser()\n\tbr.set_handle_robots(False)\n\tbr.set_handle_equiv(False)\n\tbr.addheaders = [('User-Agent', USER_AGENT), ('Accept', '*/*')] \n\n\tif profile['TOP'] == 1:\n\t\thashtags = getTopHashTags(br)\n\telse:\n\t\thashtags = getHashtagsFromFile()\n\tlike(br, hashtags)\n"
  },
  {
    "path": "PycURL Download.md",
    "content": "[Download PycURL](http://pycurl.sourceforge.net/)\n\nRun\n\n```\ntar -xvf pycurl-7.19.5.tar.gz\ncd pycurl-7.19.5/\nsudo python setup.py install\n```\n"
  },
  {
    "path": "README.md",
    "content": "InstaBot\n========\n\nNOTE BIG UPDATE ON FUCTIONALITY; PLEASE UPDATE YOUR WORKING COPY AND FOLLOW NEW INSTRUCTIONS!\n\nA simple Instagram bot that pulls trending top 100 hashtags and auto likes pictures with those hashtags to get more followers.\n\nDeveloped in Python and built with the mechanize library\n\nSTILL IN DEVELOPMENT, CONTRIBUTIONS ARE WELCOME\n\n##Setup\nClone this repository:\n```\ngit clone https://github.com/marclave/InstaBot.git\n```\nrun the following command to install the required libraries:\n```\nsudo pip install -r requirements.txt\n```\n\nGo to [instagram clients](http://instagram.com/developer/clients/manage/)\nRegister your account for a developers client\nRetrieve your CLIENT SECRET and USER ID token under \"Manage Clients\"\n\nTo get your access token:\n\nuse the \"Client ID\" and \"Redirect URL\" from the previous step and go to this address on your browser:\n```\nhttps://instagram.com/oauth/authorize/?client_id=INSERT_CLIENTID&amp;redirect_uri=INSERT_REDIRECTURI&amp;response_type=token\n```\nYou would get redirected to your redirect url with your access token:\n```\nhttp://REDIRECT.URL/#access_token=YOUR_ACCESS_TOKEN_IS_HERE\n```\nnow do the same thing with the following URL to authenticate likes on this Client ID:\n```\nhttps://instagram.com/oauth/authorize/?client_id=INSERT_CLIENTID&redirect_uri=INSERT_REDIRECTURI&response_type=code&scope=likes+basic\n```\n\n\nModify the profile to include your information, example:\n```\nCREDENTIALS:\n  ACCESS_TOKEN: \"USER_ACCESS_TOKEN\"\n  CLIENT_SECRET: \"USER_CLIENT_SECRET\"\nMAXLIKES: 1000 <- If you dont want a max, input NO_MAX\nPERHASHTAG: 10 <- If you dont want a max, input NO_MAX\nTOP: 1 <- To use the top hashtags on Websta.me use a 1\nIP: \"USER_IP_ADDRESS\" <- run ipconfig or ifconfig to grab your ip address\n```\nNote: If you do not put a 1 in the value of TOP then the program will look for a text file\ncalled hashtags.txt.\n\nThe format for this file is to have each hashtag separated by line, example:\n\n```\nI\nLove\nPython\n```\n\nThen run:\n```\npython InstaBot.py\n```\n"
  },
  {
    "path": "hashtags.txt",
    "content": "I\nLove\nPython"
  },
  {
    "path": "profile.yml",
    "content": "CREDENTIALS:\n  ACCESS_TOKEN: USER_ACCESS_TOKEN\n  CLIENT_SECRET: \"USER_CLIENT_SECRET\"\nSLEEPTIME: 1\nMAXLIKES: 10\nPERHASHTAG: 2\nTOP: 1\nIP: \"USER_IP_ADDRESS\"\n"
  },
  {
    "path": "requirements.txt",
    "content": "mechanize\nPyYAML\npycurl\n"
  }
]