-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.py
82 lines (70 loc) · 2.19 KB
/
upload.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/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
import os
album = None # You can also enter an album ID here
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': '',
'title': '',
'description': ''
}
rootdir = "/home/matt/Desktop/melissa-pics-1"
for subdir, dirs, files in os.walk(rootdir):
print("Uploading image... ")
for file in files:
#print os.path.join(subdir, file)
filepath = subdir + os.sep + file
if filepath.endswith(".jpg"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
elif filepath.endswith(".jpeg"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
elif filepath.endswith(".png"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
elif filepath.endswith(".JPG"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
elif filepath.endswith(".JPEG"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
elif filepath.endswith(".PNG"):
print (filepath)
image = client.upload_from_path(filepath, config=config, anon=False)
print("Done")
continue
else:
print("not a picture")
continue
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")
print("You can find it here: {0}".format(image['link']))