diff options
| author | Lars-Dominik Braun <lars@6xq.net> | 2018-12-24 09:43:45 +0100 | 
|---|---|---|
| committer | Lars-Dominik Braun <lars@6xq.net> | 2018-12-24 09:43:45 +0100 | 
| commit | ba98bcd4a07c589722c6db103b363c8aa1d3561d (patch) | |
| tree | 22c7651ad945c502e4b1154d8dccd7f0dcaaba54 /crocoite/tools.py | |
| parent | 36447c97a0036592d3748fbe594928ae9c76d5af (diff) | |
| download | crocoite-ba98bcd4a07c589722c6db103b363c8aa1d3561d.tar.gz crocoite-ba98bcd4a07c589722c6db103b363c8aa1d3561d.tar.bz2 crocoite-ba98bcd4a07c589722c6db103b363c8aa1d3561d.zip | |
Use f-strings where possible
Replaces str.format, which is less readable due to its separation of
format and arguments.
Diffstat (limited to 'crocoite/tools.py')
| -rw-r--r-- | crocoite/tools.py | 13 | 
1 files changed, 6 insertions, 7 deletions
| diff --git a/crocoite/tools.py b/crocoite/tools.py index 84c6f44..9c5d836 100644 --- a/crocoite/tools.py +++ b/crocoite/tools.py @@ -67,7 +67,7 @@ def mergeWarc (files, output):                                  'id': rid, 'date': headers.get_header('WARC-Date')}                          unique += 1                      else: -                        logging.debug ('Record {} is duplicate of {}'.format (rid, dup['id'])) +                        logging.debug (f'Record {rid} is duplicate of {dup["id"]}')                          # Payload may be identical, but HTTP headers are                          # (probably) not. Include them.                          record = writer.create_revisit_record ( @@ -80,7 +80,7 @@ def mergeWarc (files, output):                  else:                      unique += 1                  writer.write_record (record) -    logging.info ('Wrote {} unique records, {} revisits'.format (unique, revisit)) +    logging.info (f'Wrote {unique} unique records, {revisit} revisits')  def mergeWarcCli():      parser = argparse.ArgumentParser(description='Merge WARCs, reads filenames from stdin.') @@ -116,12 +116,12 @@ def extractScreenshot ():              urlSanitized = headers.get_header('WARC-Target-URI').replace ('/', '_')              xoff = 0              yoff = int (headers.get_header ('X-Crocoite-Screenshot-Y-Offset')) -            outpath = '{}-{}-{}-{}.png'.format (args.prefix, urlSanitized, xoff, yoff) +            outpath = f'{args.prefix}-{urlSanitized}-{xoff}-{yoff}.png'              if args.force or not os.path.exists (outpath):                  with open (outpath, 'wb') as out:                      shutil.copyfileobj (record.raw_stream, out)              else: -                print ('not overwriting {}'.format (outpath)) +                print (f'not overwriting {outputh}')  class Errata:      __slots__ = ('uuid', 'description', 'affects') @@ -145,8 +145,7 @@ class Errata:          return all (matchedAll)      def __repr__ (self): -        return '{}({!r}, {!r}, {!r})'.format (self.__class__.__name__, -                self.uuid, self.description, self.affects) +        return f'{self.__class__.__name__}({self.uuid!r}, {self.description!r}, {self.affects!r})'      @property      def fixable (self): @@ -180,7 +179,7 @@ def makeReport (fd):                  pass  def errata (): -    parser = argparse.ArgumentParser(description='Show/fix erratas for WARCs generated by {}.'.format (__package__)) +    parser = argparse.ArgumentParser(description=f'Show/fix erratas for WARCs generated by {__package__}.')      parser.add_argument('input', type=argparse.FileType ('rb'), help='Input WARC')      args = parser.parse_args() | 
