Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 18 image_type = ['jpg', 'jpeg', 'png', 'gif']
- 19
- 20 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)
- 21
- 22
- 23 timeTillUserReset = imgur_client.credits['UserReset']#Grabs the time the user quota will reset in Unix Epoch
- 24 timeString = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(float(timeTillUserReset)))#Formats the Unix Epoch to something readable
- 25 print ('User Limit: ' + str(imgur_client.credits['UserLimit']))#Print the Total credits that can be allocated.
- 26 print ('User Remaining: ' + str(imgur_client.credits['UserRemaining']))#Print Total credits available.
- 27 print ('User Reset: ' + str(timeString)) #Timestamp for when the credits will be reset.
- 28 print ('User Client Limit: ' + str(imgur_client.credits['ClientLimit'])) #Total credits that can be allocated for the application in a day.
- 29 print ('User Client Remaining: ' + str(imgur_client.credits['ClientRemaining'])) #Total credits remaining for the application in a day.
- 30
- 31 item_count = 0
- 32 #p=0
- 33 #for p in range(1, 1000):
- 34 #for p in range(100, -1, -1):
- 35 p=0
- 36 while True:
- 37 p += 1
- 38 time.sleep(3)
- 39 try:
- 40 search = imgur_client.gallery_search('horse', window='all', sort='viral', page=p)
- 41 for i in range(0, len(search)):
- 42 item_count +=1
- 43 print(search[i].comment_count)
- 44 if not search[i].is_album:
- 45 print(search[i].type)
- 46 print('{0}: {1}'.format("page number is", p))
- 47 if search[i].comment_count > 10 and not search[i].is_album:
- 48 if search[i].type[6:] in image_type:
- 49 count = 0
- 50 try:
- 51 image_file = urllib2.urlopen(search[i].link, timeout = 5)
- 52 image_file_name = 'images/'+ search[i].id+'.'+search[i].type[6:]
- 53 output_image = open(image_file_name, 'wb')
- 54 output_image.write(image_file.read())
- 55 for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
- 56 if count <= 10:
- 57 count += 1
- 58 output_image.close()
- 59 except urllib2.URLError as e:
- 60 print(e)
- 61 continue
- 62 except socket.timeout as e:
- 63 print(e)
- 64 continue
- 65 except socket.error as e:
- 66 print(e.status_code)
- 67 print(e.error_code)
- 68 continue
- 69 except ImgurClientError as e:
- 70 print(e.status_code)
- 71 print(e.error_message)
- --------------------------------------
- image/jpeg
- page number is: 22
- /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
- InsecurePlatformWarning
- 4
- image/gif
- page number is: 22
- 5
- image/jpeg
- page number is: 22
- 9
- page number is: 22
- 13
- image/gif
- page number is: 22
- /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
- InsecurePlatformWarning
- Traceback (most recent call last):
- File "download.py", line 55, in <module>
- for post in imgur_client.gallery_item_comments(search[i].id, sort='best'):
- File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 564, in gallery_item_comments
- response = self.make_request('GET', 'gallery/%s/comments/%s' % (item_id, sort))
- File "/usr/local/lib/python2.7/dist-packages/imgurpython/client.py", line 153, in make_request
- raise ImgurClientRateLimitError()
- imgurpython.helpers.error.ImgurClientRateLimitError: Rate-limit exceeded!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement