Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/flickrhistory/basicflickrhistorydownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,10 @@ def report_progress(self):
photo_count, _, profile_count, _ = self._statistics
print(
(
"Downloaded metadata for {photos: 6d} photos "
+ "and {profiles: 4d} user profiles "
+ "using {workers:d} workers, "
+ "{todo:d} time slots to cover"
).format(
photos=photo_count,
profiles=profile_count,
workers=(threading.active_count() - self.NUM_MANAGERS),
todo=len(self._todo_deque),
f"Downloaded metadata for {photo_count: 6d} photos "
f"and {profile_count: 4d} user profiles "
f"using {(threading.active_count() - self.NUM_MANAGERS)} workers, "
f"{len(self._todo_deque)} time slots to cover"
),
file=sys.stderr,
end=self.STATUS_UPDATE_LINE_END,
Expand All @@ -131,9 +126,7 @@ def summarise_overall_progress(self):
"""
photo_count, _, profile_count, _ = self._statistics
print(
("Downloaded {photos:d} photos " + "and {profiles:d} user profiles").format(
photos=photo_count, profiles=profile_count
),
f"Downloaded {photo_count} photos and {profile_count} user profiles",
file=sys.stderr,
)

Expand Down
8 changes: 3 additions & 5 deletions src/flickrhistory/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, cache=None, cache_file_basename=None):
or os.environ.get("XDG_CACHE_HOME")
or os.path.join(os.environ["HOME"], ".cache")
),
"{:s}.yml".format(cache_file_basename),
f"{cache_file_basename}.yml",
)
)

Expand All @@ -63,9 +63,7 @@ def _load_cache(self):
pass

if cache == {}:
warnings.warn(
"No cache found in file {}, starting empty".format(self._cache_file)
)
warnings.warn(f"No cache found in file {self._cache_file}, starting empty")

return cache

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

def __getitem__(self, pos):
"""Retrieve a cache entry."""
Expand Down
2 changes: 1 addition & 1 deletion src/flickrhistory/cacheupdaterthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(self):
newly_downloaded = self._done_queue.get(timeout=0.1)
with Cache() as cache:
cache["already downloaded"] += newly_downloaded
self.status = "added {}".format(newly_downloaded)
self.status = f"added {newly_downloaded}"
except queue.Empty:
if self.shutdown.is_set():
break
8 changes: 3 additions & 5 deletions src/flickrhistory/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def _load_config(self, config_files, config_files_basename):
config_files_basename = self.__module__.split(".")[0]

config_files = [
"/etc/{:s}.yml".format(config_files_basename),
f"/etc/{config_files_basename}.yml",
os.path.abspath(
os.path.join(
(
os.environ.get("APPDATA")
or os.environ.get("XDG_CONFIG_HOME")
or os.path.join(os.environ["HOME"], ".config")
),
"{:s}.yml".format(config_files_basename),
f"{config_files_basename}.yml",
)
),
]
Expand All @@ -81,9 +81,7 @@ def _load_config(self, config_files, config_files_basename):
pass

if config == {}:
warnings.warn(
"No configuration found in files {}.".format(",".join(config_files))
)
warnings.warn(f"No configuration found in files {', '.join(config_files)}.")

return config

Expand Down
8 changes: 3 additions & 5 deletions src/flickrhistory/databaseobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def from_raw_api_data_flickrprofilegetprofile(cls, data):

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

def __repr(self):
"""Return a str representation."""
Expand Down Expand Up @@ -230,9 +230,7 @@ def from_raw_api_data_flickrphotossearch(cls, data):
longitude = float(data["longitude"])
latitude = float(data["latitude"])
assert longitude != 0 and latitude != 0
photo_data["geom"] = "SRID=4326;POINT({longitude:f} {latitude:f})".format(
longitude=longitude, latitude=latitude
)
photo_data["geom"] = f"SRID=4326;POINT({longitude:f} {latitude:f})"
except (
AssertionError, # lon/lat is at exactly 0°N/S, 0°W/E -> bogus
KeyError, # not contained in API dict
Expand All @@ -248,7 +246,7 @@ def from_raw_api_data_flickrphotossearch(cls, data):

def __str__(self):
"""Return a str representation."""
return "<FlickrPhoto({:s})>".format(self.id)
return f"<FlickrPhoto({self.id})>"

def __repr(self):
"""Return a str representation."""
Expand Down
34 changes: 17 additions & 17 deletions src/flickrhistory/fancyflickrhistorydownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ class FancyFlickrHistoryDownloader(BasicFlickrHistoryDownloader):

WELCOME = (
"{t.bold}{t.blue} ### flickrhistory "
+ "{t.normal}{t.blue}"
+ version
+ "{t.bold} ###"
+ "{t.normal}"
"{t.normal}{t.blue}"
f"{version}"
"{t.bold} ###"
"{t.normal}"
)

STATUS = (
"{t.normal} Downloaded metadata for "
+ "{t.bold}{t.magenta}{photos: 9d} 📷 photos "
+ "{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
+ "{t.normal} and updated "
+ "{t.bold}{t.red}{profiles: 9d} 👱 user profiles "
+ "{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
+ "{t.normal} using "
+ "{t.bold}{t.green}{workers: 9d} 💪 workers\n"
+ "{t.normal}{t.bold} TODO: {todo: 12d} 🚧 time slots"
+ "{t.normal}"
"{t.bold}{t.magenta}{photos: 9d} 📷 photos "
"{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
"{t.normal} and updated "
"{t.bold}{t.red}{profiles: 9d} 👱 user profiles "
"{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
"{t.normal} using "
"{t.bold}{t.green}{workers: 9d} 💪 workers\n"
"{t.normal}{t.bold} TODO: {todo: 12d} 🚧 time slots"
"{t.normal}"
)
STATUS_LINES = len(STATUS.splitlines())

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

SUMMARY = (
"{t.normal}Downloaded {t.bold}{t.magenta}{photos: 9d} 📷 photos "
+ "{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
+ "{t.normal}and updated {t.bold}{t.red}{profiles: 9d} 👱 user profiles "
+ "{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
+ "{t.normal}"
"{t.normal}{t.magenta}{photo_rate: 11.1f}/s\n"
"{t.normal}and updated {t.bold}{t.red}{profiles: 9d} 👱 user profiles "
"{t.normal}{t.red}{profile_rate: 3.1f}/s\n"
"{t.normal}"
)

def __init__(self):
Expand Down
6 changes: 2 additions & 4 deletions src/flickrhistory/photodownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ def photos(self):
seconds=1
):
raise DownloadBatchIsTooLargeError(
(
"More than 4000 rows returned ({:d}), "
+ "please specify a shorter time span."
).format(num_photos)
f"More than 4000 rows returned ({num_photos}), "
"please specify a shorter time span."
)

for photo in results["photos"]["photo"]:
Expand Down
6 changes: 4 additions & 2 deletions src/flickrhistory/timespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def __init__(self, start, end):
def __str__(self):
"""Return a string representation of this TimeSpan."""
return (
"<{:s}" + "({:%Y-%m-%dT%H:%M:%S.000Z}-{:%Y-%m-%dT%H:%M:%S.000Z})>"
).format(self.__class__.__name__, self.start, self.end)
f"<{self.__class__.__name__}"
f"({self.start:%Y-%m-%dT%H:%M:%S.000Z}"
f"-{self.end:%Y-%m-%dT%H:%M:%S.000Z})>"
)

def __repr__(self):
"""Represent this TimeSpan in readable form."""
Expand Down