Skip to content

Commit b0fe7e9

Browse files
committed
f-strings instead of old-style str.format()
1 parent c71e8ab commit b0fe7e9

File tree

8 files changed

+37
-50
lines changed

8 files changed

+37
-50
lines changed

src/flickrhistory/basicflickrhistorydownloader.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,10 @@ def report_progress(self):
9999
photo_count, _, profile_count, _ = self._statistics
100100
print(
101101
(
102-
"Downloaded metadata for {photos: 6d} photos "
103-
+ "and {profiles: 4d} user profiles "
104-
+ "using {workers:d} workers, "
105-
+ "{todo:d} time slots to cover"
106-
).format(
107-
photos=photo_count,
108-
profiles=profile_count,
109-
workers=(threading.active_count() - self.NUM_MANAGERS),
110-
todo=len(self._todo_deque),
102+
f"Downloaded metadata for {photo_count: 6d} photos "
103+
f"and {profile_count: 4d} user profiles "
104+
f"using {(threading.active_count() - self.NUM_MANAGERS)} workers, "
105+
f"{len(self._todo_deque)} time slots to cover"
111106
),
112107
file=sys.stderr,
113108
end=self.STATUS_UPDATE_LINE_END,
@@ -131,9 +126,7 @@ def summarise_overall_progress(self):
131126
"""
132127
photo_count, _, profile_count, _ = self._statistics
133128
print(
134-
("Downloaded {photos:d} photos " + "and {profiles:d} user profiles").format(
135-
photos=photo_count, profiles=profile_count
136-
),
129+
f"Downloaded {photo_count} photos and {profile_count} user profiles",
137130
file=sys.stderr,
138131
)
139132

src/flickrhistory/cache.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, cache=None, cache_file_basename=None):
4646
or os.environ.get("XDG_CACHE_HOME")
4747
or os.path.join(os.environ["HOME"], ".cache")
4848
),
49-
"{:s}.yml".format(cache_file_basename),
49+
f"{cache_file_basename}.yml",
5050
)
5151
)
5252

@@ -63,9 +63,7 @@ def _load_cache(self):
6363
pass
6464

6565
if cache == {}:
66-
warnings.warn(
67-
"No cache found in file {}, starting empty".format(self._cache_file)
68-
)
66+
warnings.warn(f"No cache found in file {self._cache_file}, starting empty")
6967

7068
return cache
7169

@@ -77,7 +75,7 @@ def _save_cache(self):
7775
Dumper=YamlNoAliasDumper,
7876
)
7977
except PermissionError:
80-
warnings.warn("Could not write cache to {}".format(self._cache_file))
78+
warnings.warn(f"Could not write cache to {self._cache_file}")
8179

8280
def __getitem__(self, pos):
8381
"""Retrieve a cache entry."""

src/flickrhistory/cacheupdaterthread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636
newly_downloaded = self._done_queue.get(timeout=0.1)
3737
with Cache() as cache:
3838
cache["already downloaded"] += newly_downloaded
39-
self.status = "added {}".format(newly_downloaded)
39+
self.status = f"added {newly_downloaded}"
4040
except queue.Empty:
4141
if self.shutdown.is_set():
4242
break

src/flickrhistory/config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ def _load_config(self, config_files, config_files_basename):
6161
config_files_basename = self.__module__.split(".")[0]
6262

6363
config_files = [
64-
"/etc/{:s}.yml".format(config_files_basename),
64+
f"/etc/{config_files_basename}.yml",
6565
os.path.abspath(
6666
os.path.join(
6767
(
6868
os.environ.get("APPDATA")
6969
or os.environ.get("XDG_CONFIG_HOME")
7070
or os.path.join(os.environ["HOME"], ".config")
7171
),
72-
"{:s}.yml".format(config_files_basename),
72+
f"{config_files_basename}.yml",
7373
)
7474
),
7575
]
@@ -81,9 +81,7 @@ def _load_config(self, config_files, config_files_basename):
8181
pass
8282

8383
if config == {}:
84-
warnings.warn(
85-
"No configuration found in files {}.".format(",".join(config_files))
86-
)
84+
warnings.warn(f"No configuration found in files {', '.join(config_files)}.")
8785

8886
return config
8987

src/flickrhistory/databaseobjects.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def from_raw_api_data_flickrprofilegetprofile(cls, data):
112112

113113
def __str__(self):
114114
"""Return a str representation."""
115-
return "<FlickrUser({:s}@N0{:s})>".format(self.id, self.farm)
115+
return f"<FlickrUser({self.id}@N0{self.farm})>"
116116

117117
def __repr(self):
118118
"""Return a str representation."""
@@ -230,9 +230,7 @@ def from_raw_api_data_flickrphotossearch(cls, data):
230230
longitude = float(data["longitude"])
231231
latitude = float(data["latitude"])
232232
assert longitude != 0 and latitude != 0
233-
photo_data["geom"] = "SRID=4326;POINT({longitude:f} {latitude:f})".format(
234-
longitude=longitude, latitude=latitude
235-
)
233+
photo_data["geom"] = f"SRID=4326;POINT({longitude:f} {latitude:f})"
236234
except (
237235
AssertionError, # lon/lat is at exactly 0°N/S, 0°W/E -> bogus
238236
KeyError, # not contained in API dict

src/flickrhistory/fancyflickrhistorydownloader.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,34 @@ class FancyFlickrHistoryDownloader(BasicFlickrHistoryDownloader):
2929

3030
WELCOME = (
3131
"{t.bold}{t.blue} ### flickrhistory "
32-
+ "{t.normal}{t.blue}"
33-
+ version
34-
+ "{t.bold} ###"
35-
+ "{t.normal}"
32+
"{t.normal}{t.blue}"
33+
f"{version}"
34+
"{t.bold} ###"
35+
"{t.normal}"
3636
)
3737

3838
STATUS = (
3939
"{t.normal} Downloaded metadata for "
40-
+ "{t.bold}{t.magenta}{photos: 9d} 📷 photos "
41-
+ "{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
42-
+ "{t.normal} and updated "
43-
+ "{t.bold}{t.red}{profiles: 9d} 👱 user profiles "
44-
+ "{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
45-
+ "{t.normal} using "
46-
+ "{t.bold}{t.green}{workers: 9d} 💪 workers\n"
47-
+ "{t.normal}{t.bold} TODO: {todo: 12d} 🚧 time slots"
48-
+ "{t.normal}"
40+
"{t.bold}{t.magenta}{photos: 9d} 📷 photos "
41+
"{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
42+
"{t.normal} and updated "
43+
"{t.bold}{t.red}{profiles: 9d} 👱 user profiles "
44+
"{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
45+
"{t.normal} using "
46+
"{t.bold}{t.green}{workers: 9d} 💪 workers\n"
47+
"{t.normal}{t.bold} TODO: {todo: 12d} 🚧 time slots"
48+
"{t.normal}"
4949
)
5050
STATUS_LINES = len(STATUS.splitlines())
5151

5252
SHUTDOWN_ANNOUNCEMENT = "{t.bold}Cleaning up. 🛑 {t.normal}"
5353

5454
SUMMARY = (
5555
"{t.normal}Downloaded {t.bold}{t.magenta}{photos: 9d} 📷 photos "
56-
+ "{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
57-
+ "{t.normal}and updated {t.bold}{t.red}{profiles: 9d} 👱 user profiles "
58-
+ "{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
59-
+ "{t.normal}"
56+
"{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
57+
"{t.normal}and updated {t.bold}{t.red}{profiles: 9d} 👱 user profiles "
58+
"{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
59+
"{t.normal}"
6060
)
6161

6262
def __init__(self):

src/flickrhistory/photodownloader.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ def photos(self):
7575
seconds=1
7676
):
7777
raise DownloadBatchIsTooLargeError(
78-
(
79-
"More than 4000 rows returned ({:d}), "
80-
+ "please specify a shorter time span."
81-
).format(num_photos)
78+
f"More than 4000 rows returned ({num_photos}), "
79+
"please specify a shorter time span."
8280
)
8381

8482
for photo in results["photos"]["photo"]:

src/flickrhistory/timespan.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ def __init__(self, start, end):
2424
def __str__(self):
2525
"""Return a string representation of this TimeSpan."""
2626
return (
27-
"<{:s}" + "({:%Y-%m-%dT%H:%M:%S.000Z}-{:%Y-%m-%dT%H:%M:%S.000Z})>"
28-
).format(self.__class__.__name__, self.start, self.end)
27+
f"<{self.__class__.__name__}"
28+
f"({self.start:%Y-%m-%dT%H:%M:%S.000Z}"
29+
f"-{self.end:%Y-%m-%dT%H:%M:%S.000Z})>"
30+
)
2931

3032
def __repr__(self):
3133
"""Represent this TimeSpan in readable form."""

0 commit comments

Comments
 (0)