Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #-*-coding:utf8;-*-
- #qpy:2
- #qpy:console
- #
- # A (very ugly) script to grab all Images from (PUBLIC) Instagram for a collection of users and send a pushbullet notification.
- # On subsequent runs it will only download new images so can be scheduled under crontab to monitor and rip many accounts
- # This script will automatically create sub-folders for each of the collection of (Public) users in the "people" list.
- # but does require the initial save path to exist.
- #
- # Written by Jamie Fuller 2017, more on https://www.jamiefuller.com
- #
- import urllib2
- import socket
- import sys
- import string
- import os
- from os.path import basename
- ## the list below should be populated with the people you wish to download. (WARNING, the jamiepfuller account contains some NSFW material)
- people=["jamiepfuller","artduino","discovering_mechatronics"]
- ## the variable below controls the save path, please ensure this exists and is writable.
- savepath="/home/pi/Instagram/"
- summary=""
- for p in people:
- if not os.path.exists(savepath+p):
- os.makedirs(savepath+p)
- count=0
- noteof=0
- cursor=""
- while noteof==0:
- url = 'https://www.instagram.com/%s/%s' % (p,cursor)
- print url
- request=urllib2.Request(url)
- try:
- usock = urllib2.urlopen(request)
- except urllib2.HTTPError as e:
- error_message = e.read()
- print error_message
- else:
- try:
- data = usock.read()
- except:
- print "\n\n\nerror!!!!"
- else:
- if data.find('"has_next_page": true')>0:
- cursor='?max_id=%s' % data[data.find('end_cursor')+14:data.find('"',data.find('end_cursor')+14)]
- else:
- noteof=1
- usock.close()
- arr=data.split('display_src')
- ars=iter(arr)
- next(ars)
- for a in ars:
- if (a.find(".jpg")>0):
- url2=a[4:a.find(".jpg")] + ".jpg"
- file_name=basename(url2)
- if os.path.isfile(savepath+p+"/"+file_name) :
- print "skipping: %s" % file_name
- noteof=1
- break
- else:
- print "%d, Downloading: %s" % (count+1,file_name)
- request=urllib2.Request(url2)
- try:
- usock = urllib2.urlopen(request, timeout=10)
- except urllib2.HTTPError as e:
- error_message = e.read()
- print error_message
- except socket.timeout as e:
- print type(e)
- else:
- f = open(savepath+p+"/"+file_name, 'wb')
- try:
- data2 = usock.read()
- except urllib2.HTTPError as e:
- error_message = e.read()
- print error_message
- except socket.timeout as e:
- print type(e)
- else:
- usock.close()
- f.write(data2)
- f.close()
- count=count+1
- if (count>0): summary="%s\n%d new image(s) for %s" % (summary,count,p)
- if summary<>"":
- print summary
- #remember to add your own details for pushbullet below.
- call="curl -u YOURACCESSTOKENGOESHERE: https://api.pushbullet.com/v2/pushes -d type=note -d title='Instagram updates' -d body='%s' -d device_iden=YOURDEVICEIDGOESHERE" % summary
- response=os.system(call + " > /dev/null")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement