forked from Imgur/imgurpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.py
More file actions
executable file
·47 lines (35 loc) · 1.21 KB
/
upload.py
File metadata and controls
executable file
·47 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
'''
Here's how you upload an image. For this example, put the cutest picture
of a kitten you can find in this script's folder and name it 'Kitten.jpg'
For more details about images and the API see here:
https://api.imgur.com/endpoints/image
'''
# Pull authentication from the auth example (see auth.py)
from auth import authenticate
from datetime import datetime
album = None # You can also enter an album ID here
image_path = 'Kitten.jpg'
def upload_kitten(client):
'''
Upload a picture of a kitten. We don't ship one, so get creative!
'''
# Here's the metadata for the upload. All of these are optional, including
# this config dict itself.
config = {
'album': album,
'name': 'Catastrophe!',
'title': 'Catastrophe!',
'description': 'Cute kitten being cute on {0}'.format(datetime.now())
}
print("Uploading image... ")
image = client.upload_from_path(image_path, config=config, anon=False)
print("Done")
print()
return image
# If you want to run this as a standalone script
if __name__ == "__main__":
client = authenticate()
image = upload_kitten(client)
print("Image was posted! Go check your images you sexy beast!")
print("You can find it here: {0}".format(image['link']))