-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflickr-upload.py
95 lines (86 loc) · 2.68 KB
/
flickr-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
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Tool for uploading files to flickr"""
import flickr
import argparse
import sys
import os
# /home/media/photos/FIS Phone/DCIM/100APPLE
# /home/media/photos/Wedding/Benny/HiRes
# /home/media/photos/2012-04
# /home/media/photos/2016
# /home/media/photos/Camera
# /home/media/photos/FisherPriceRafael
# /home/media/photos/CybershotH9
# /home/media/photos/Cybershot
# ~media/photos/Digimax*
# ~media/photos/Karin\ SD\ Card\ 20170625/
# /home/media/photos/R
# ~media/photos/CybershotKarin
# home/media/photos/Happy2015
# ~media/photos/cool
# ~media/photos/K
# ~media/photos/B
# home/media/photos/RafaelVideos
# ~media/photos/Belgium
# ~media/photos/Israel/
# /home/media/photos/Mathcamp
# /home/media/photos/Nawleans
# /home/media/photos/p
# ~media/photos/Donostia
# ~media/photos/other
# ~media/photos/Cambridge
# ~media/photos/s
# ~media/photos/r~
# GC2004
SUPPORTED_EXTENSIONS = (
'.jpg', '.jpeg', '.mp4', '.3gp', '.gif', '.mpg', '.avi', '.wmv', '.png',
'.m4v', '.mov', '.bmp'
)
def main():
"""Get the file names from the command line and upload them"""
parser = get_parser()
args = parser.parse_args()
if args.version:
print_version(parser)
return 0
photo_file_names = args.photo_file_names
if not photo_file_names:
print('{}: list of files is missing!'.format(parser.prog))
return 26
for file_name in photo_file_names:
if not os.path.isfile(file_name):
print('{}: No such file!'.format(file_name))
return 29
lower = file_name.lower()
for supported_extension in SUPPORTED_EXTENSIONS:
if lower.endswith(supported_extension):
break
else:
print(
'{}: Only these extensions are supported: {}'.format(
file_name, ' '.join(SUPPORTED_EXTENSIONS)
)
)
return 41
return flickr.upload_photos(photo_file_names, args.photoset_id)
def print_version(parser):
"""Get all the versions and print them out"""
for module_name in (
'certifi', 'chardet', 'idna', 'oauthlib', 'requests',
'requests_oauthlib', 'urllib3'
):
print(
'{} {}'.format(
module_name, __import__(module_name).__version__
)
)
print('{} {}'.format(parser.prog, flickr.__version__))
def get_parser():
"""Parse the command line arguments"""
parser = argparse.ArgumentParser(description='Upload to Flickr.')
parser.add_argument(
'photo_file_names', nargs='*', help='list of files to upload'
)
parser.add_argument('--version', action='store_true')
parser.add_argument('--photoset-id')
return parser
sys.exit(main())