-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavg_photos.py
More file actions
140 lines (133 loc) · 3.67 KB
/
Copy pathavg_photos.py
File metadata and controls
140 lines (133 loc) · 3.67 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
from pathlib import Path
import click
from photomanip.averager import Averager, ConstructMetadata
from photomanip.uploader import FlickrUploader
@click.command()
@click.option(
"-i",
"--image_path",
help="path of the directory of images you'd like to process",
required=True,
type=click.STRING
)
@click.option(
"-o",
"--output_path",
help="path where averages should be placed",
required=True,
type=click.STRING
)
@click.option(
"-c",
"--combination_method",
help="""either 'crop' (all images are cropped to smallest dimension) \
or 'pad' (all images are padded to largest dimension) \
or 'resize' (images are resized to the same dimension as the largest image \
WARNING: this option is very slow and uses a large amount of memory!).""",
show_default=True,
required=True,
type=click.Choice(["crop", "pad", "resize"], case_sensitive=False),
default="resize"
)
@click.option(
"-t",
"--grouping_tag",
help="""setting this option will search IPTC keywords for a keyword \
beginning with the specified string. it will then strip the \
specified string from the tag and attempt to convert the rest \
of the keyword to a date. that date will then be used for \
grouping""",
show_default=True,
required=False,
type=click.STRING,
default=None
)
@click.option(
"-a",
"--author",
help="""specifies the author of the generated images.""",
show_default=True,
required=False,
type=click.STRING,
default="andrew catellier"
)
@click.option(
"-f",
"--flickr_set_id",
help="""upload the averages that are generated to the \
specified flickr set.""",
show_default=True,
required=False,
type=click.STRING,
default=None
)
@click.option(
"-k",
"--cache",
help="""keep a length 2 cache of previously generated monthly and \
yearly averages. depending on image size, cache may use a significant \
amount of storage space (500 MB - 1.5 GB), but greatly decreases \
processing time when generating averages with many images.""",
show_default=True,
required=False,
type=click.BOOL,
default=True
)
@click.option(
"-p",
"--progressive",
help="""for monthly and yerly averages, generate averages \
for each successive day. this allows one to see how the average images \
accumulate information/data over time.""",
show_default=True,
required=False,
type=click.BOOL,
default=True
)
def main(
image_path,
output_path,
combination_method,
grouping_tag,
author,
flickr_set_id,
cache,
progressive
):
"""
Main function to parse commandline arguments and start the averaging
function.
"""
metadata_generator = ConstructMetadata(
author,
"all rights reserved"
)
photo_averager = Averager(
Path(image_path),
Path(output_path),
metadata_generator,
grouping_tag=grouping_tag,
comb_method=combination_method
)
if cache:
cwd = os.getcwd()
default_cache_path = Path(cwd) / '.avg_cache'
default_cache_path.mkdir(exist_ok=True)
month_cache = default_cache_path / "monthly"
year_cache = default_cache_path / "yearly"
else:
month_cache = None
year_cache = None
# dailies
daily_average_list = photo_averager.average_by_day()
if flickr_set_id:
flickr_uploader = FlickrUploader("./config.yaml")
for fname in daily_average_list:
flickr_uploader.upload(fname, flickr_set_id)
# monthlies
photo_averager.average_by_month(month_cache, progressive)
# yearly
photo_averager.average_by_year(year_cache, progressive)
if __name__ == "__main__":
main()