diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b9a75af..9f5ad6f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,8 @@ repos: +- repo: https://github.com/asottile/pyupgrade + rev: v1.23.0 + hooks: + - id: pyupgrade - repo: https://github.com/ambv/black rev: stable hooks: diff --git a/docs/source/conf.py b/docs/source/conf.py index 56dad0b..de7694c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # pycounter documentation build configuration file, created by # sphinx-quickstart on Thu Nov 13 08:44:21 2014. @@ -56,8 +55,8 @@ master_doc = "index" # General information about the project. -project = u"pycounter" -copyright = u"2014-2019, University of Pittsburgh" +project = "pycounter" +copyright = "2014-2019, University of Pittsburgh" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -98,7 +97,7 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ("index", "pycounter.tex", u"pycounter Documentation", u"Geoffrey Spear", "manual") + ("index", "pycounter.tex", "pycounter Documentation", "Geoffrey Spear", "manual") ] @@ -106,7 +105,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [("index", "pycounter", u"pycounter Documentation", [u"Geoffrey Spear"], 1)] +man_pages = [("index", "pycounter", "pycounter Documentation", ["Geoffrey Spear"], 1)] # -- Options for Texinfo output ------------------------------------------- @@ -117,8 +116,8 @@ ( "index", "pycounter", - u"pycounter Documentation", - u"Geoffrey Spear", + "pycounter Documentation", + "Geoffrey Spear", "pycounter", "One line description of project.", "Miscellaneous", diff --git a/pycounter/constants.py b/pycounter/constants.py index 6801b9a..281b170 100644 --- a/pycounter/constants.py +++ b/pycounter/constants.py @@ -8,19 +8,19 @@ } METRICS = { - u"JR1": u"FT Article Requests", - u"JR1 GOA": u"Gold Open Access Article Requests", - u"BR1": u"Book Title Requests", - u"BR2": u"Book Section Requests", - u"DB1": [ - u"Regular Searches", - u"Searches-federated and automated", - u"Result Clicks", - u"Record Views", + "JR1": "FT Article Requests", + "JR1 GOA": "Gold Open Access Article Requests", + "BR1": "Book Title Requests", + "BR2": "Book Section Requests", + "DB1": [ + "Regular Searches", + "Searches-federated and automated", + "Result Clicks", + "Record Views", ], - u"DB2": [ - u"Access denied: concurrent/simultaneous user license exceeded", - u"Access denied: content item not licensed", + "DB2": [ + "Access denied: concurrent/simultaneous user license exceeded", + "Access denied: content item not licensed", ], } @@ -34,165 +34,164 @@ } CODES = { - u"Database": u"DB", - u"Journal": u"JR", - u"Book": u"BR", - u"Title": u"TR", - u"Platform": u"PR", - u"Multimedia": u"MR", - u"Consortium": u"CR", + "Database": "DB", + "Journal": "JR", + "Book": "BR", + "Title": "TR", + "Platform": "PR", + "Multimedia": "MR", + "Consortium": "CR", } # from http://www.niso.org/workrooms/sushi/registry/ # Not all of these are actually supported by pycounter REPORT_DESCRIPTIONS = { - u"BR1": u"Number of Successful Title Requests by Month and Title", - u"BR2": u"Number of Successful Section Requests by Month and Title", - u"BR3": u"Access Denied to Content Items by Month, Title, and Category", - u"BR4": u"Access Denied to Content Items by Month, Platform, and Category", - u"BR5": u"Total Searches by Month and Title", - u"CR1": u"Number of Successful Full-text Journal Article or Book Chapter " - u"Requests by Month", - u"CR2": u"Total Searches by Month and Database", - u"CR3": u"Number of Successful Multimedia Full Content Unit Requests " - u"by Month and Collection", - u"DB1": u"Total Searches, Result Clicks and Record Views by Month and " u"Database", - u"DB2": u"Access Denied by Month, Database and Category", - u"JR1": u"Number of Successful Full-Text Article Requests by Month and " u"Journal", - u"JR1GOA": u"Number of Successful Gold Open Access Full-Text Article " - u"Requests by Month and Journal", - u"JR1a": u"Number of Successful Full-Text Article Requests from an " - u"Archive by Month and Journal", - u"JR2": u"Access Denied to Full Text Articles by Month, Journal, and " u"Category", - u"JR3": u"Number of Successful Item Requests and Turnaways by Month, " - u"Journal, and Page-Type", - u"JR3mobile": u"Number of Successful Item Requests by Month, Journal, " - u"and Page-Type for usage on a mobile device", - u"JR4": u"Total Searches Run by Month and Collection", - u"JR5": u"Number of Successful Full-Text Article Requests by " - u"Year-of-Publication (YOP) and Journal", - u"MR1": u"Number of Successful Multimedia Full Content Unit Requests " - u"by Month and Collection", - u"MR2": u"Number of Successful Multimedia Full Content Unit Requests by " - u"Month, Collection, and Item Type", - u"PR1": u"Total Searches, Result Clicks, and Record Views by Month and " - u"Platform", - u"TR1": u"Number of Successful Requests for Journal Full-Text Articles " - u"and Book Sections by Month and Title", - u"TR1mobile": u"Number of Successful Requests for Journal Full-Text " - u"Articles and Book Sections by Month and Title " - u"(formatted for normal browsers/delivered to mobile " - u"devices AND formatted for mobile devices/delivered " - u"to mobile devices)", - u"TR2": u"Access Denied to Full-Text Items by Month, Title, and Category", - u"TR3": u"Number of Successful Item Requests by Month, Title, and " u"Page-Type", - u"TR3mobile": u"Number of Successful Item Requests by Month, Title, " - u"and Page-Type (formatted for normal browsers/delivered " - u"to mobile devices and for mobile devices/delivered to " - u"mobile devices)", - u"TR_J1": u'Journal Requests (Excluding "OA_Gold")', + "BR1": "Number of Successful Title Requests by Month and Title", + "BR2": "Number of Successful Section Requests by Month and Title", + "BR3": "Access Denied to Content Items by Month, Title, and Category", + "BR4": "Access Denied to Content Items by Month, Platform, and Category", + "BR5": "Total Searches by Month and Title", + "CR1": "Number of Successful Full-text Journal Article or Book Chapter " + "Requests by Month", + "CR2": "Total Searches by Month and Database", + "CR3": "Number of Successful Multimedia Full Content Unit Requests " + "by Month and Collection", + "DB1": "Total Searches, Result Clicks and Record Views by Month and " "Database", + "DB2": "Access Denied by Month, Database and Category", + "JR1": "Number of Successful Full-Text Article Requests by Month and " "Journal", + "JR1GOA": "Number of Successful Gold Open Access Full-Text Article " + "Requests by Month and Journal", + "JR1a": "Number of Successful Full-Text Article Requests from an " + "Archive by Month and Journal", + "JR2": "Access Denied to Full Text Articles by Month, Journal, and " "Category", + "JR3": "Number of Successful Item Requests and Turnaways by Month, " + "Journal, and Page-Type", + "JR3mobile": "Number of Successful Item Requests by Month, Journal, " + "and Page-Type for usage on a mobile device", + "JR4": "Total Searches Run by Month and Collection", + "JR5": "Number of Successful Full-Text Article Requests by " + "Year-of-Publication (YOP) and Journal", + "MR1": "Number of Successful Multimedia Full Content Unit Requests " + "by Month and Collection", + "MR2": "Number of Successful Multimedia Full Content Unit Requests by " + "Month, Collection, and Item Type", + "PR1": "Total Searches, Result Clicks, and Record Views by Month and " "Platform", + "TR1": "Number of Successful Requests for Journal Full-Text Articles " + "and Book Sections by Month and Title", + "TR1mobile": "Number of Successful Requests for Journal Full-Text " + "Articles and Book Sections by Month and Title " + "(formatted for normal browsers/delivered to mobile " + "devices AND formatted for mobile devices/delivered " + "to mobile devices)", + "TR2": "Access Denied to Full-Text Items by Month, Title, and Category", + "TR3": "Number of Successful Item Requests by Month, Title, and " "Page-Type", + "TR3mobile": "Number of Successful Item Requests by Month, Title, " + "and Page-Type (formatted for normal browsers/delivered " + "to mobile devices and for mobile devices/delivered to " + "mobile devices)", + "TR_J1": 'Journal Requests (Excluding "OA_Gold")', } HEADER_FIELDS = { "JR1": ( - u"Journal", - u"Publisher", - u"Platform", - u"Journal DOI", - u"Proprietary Identifier", - u"Print ISSN", - u"Online ISSN", - u"Reporting Period Total", - u"Reporting Period HTML", - u"Reporting Period PDF", + "Journal", + "Publisher", + "Platform", + "Journal DOI", + "Proprietary Identifier", + "Print ISSN", + "Online ISSN", + "Reporting Period Total", + "Reporting Period HTML", + "Reporting Period PDF", ), "JR2": ( - u"Journal", - u"Publisher", - u"Platform", - u"Journal DOI", - u"Proprietary Identifier", - u"Print ISSN", - u"Online ISSN", - u"Reporting Period Total", - u"Reporting Period HTML", - u"Reporting Period PDF", + "Journal", + "Publisher", + "Platform", + "Journal DOI", + "Proprietary Identifier", + "Print ISSN", + "Online ISSN", + "Reporting Period Total", + "Reporting Period HTML", + "Reporting Period PDF", ), "JR3": ( - u"Journal", - u"Publisher", - u"Platform", - u"Journal DOI", - u"Proprietary Identifier", - u"Print ISSN", - u"Online ISSN", - u"Reporting Period Total", - u"Reporting Period HTML", - u"Reporting Period PDF", + "Journal", + "Publisher", + "Platform", + "Journal DOI", + "Proprietary Identifier", + "Print ISSN", + "Online ISSN", + "Reporting Period Total", + "Reporting Period HTML", + "Reporting Period PDF", ), "BR1": ( - u"", - u"Publisher", - u"Platform", - u"Book DOI", - u"Proprietary Identifier", - u"ISBN", - u"ISSN", - u"Reporting Period Total", + "", + "Publisher", + "Platform", + "Book DOI", + "Proprietary Identifier", + "ISBN", + "ISSN", + "Reporting Period Total", ), "BR2": ( - u"", - u"Publisher", - u"Platform", - u"Book DOI", - u"Proprietary Identifier", - u"ISBN", - u"ISSN", - u"Reporting Period Total", + "", + "Publisher", + "Platform", + "Book DOI", + "Proprietary Identifier", + "ISBN", + "ISSN", + "Reporting Period Total", ), "BR3": ( - u"", - u"Publisher", - u"Platform", - u"Book DOI", - u"Proprietary Identifier", - u"ISBN", - u"ISSN", - u"Reporting Period Total", + "", + "Publisher", + "Platform", + "Book DOI", + "Proprietary Identifier", + "ISBN", + "ISSN", + "Reporting Period Total", ), "DB1": ( - u"Database", - u"Publisher", - u"Platform", - u"User Activity", - u"Reporting Period Total", + "Database", + "Publisher", + "Platform", + "User Activity", + "Reporting Period Total", ), "DB2": ( - u"Database", - u"Publisher", - u"Platform", - u"Access denied category", - u"Reporting Period Total", + "Database", + "Publisher", + "Platform", + "Access denied category", + "Reporting Period Total", ), - "PR1": (u"Platform", u"Publisher", u"User Activity", u"Reporting Period Total"), + "PR1": ("Platform", "Publisher", "User Activity", "Reporting Period Total"), # FIXME: this is outputting counter 5 reports in 4 format for... reasons. "TR_J1": ( - u"Journal", - u"Publisher", - u"Platform", - u"Journal DOI", - u"Proprietary Identifier", - u"Print ISSN", - u"Online ISSN", - u"Reporting Period Total", - u"Reporting Period HTML", - u"Reporting Period PDF", + "Journal", + "Publisher", + "Platform", + "Journal DOI", + "Proprietary Identifier", + "Print ISSN", + "Online ISSN", + "Reporting Period Total", + "Reporting Period HTML", + "Reporting Period PDF", ), } TOTAL_TEXT = { - "JR1": u"Total for all journals", - "BR1": u"Total for all titles", - "BR2": u"Total for all titles", - "DB2": u"Total for all databases", + "JR1": "Total for all journals", + "BR1": "Total for all titles", + "BR2": "Total for all titles", + "DB2": "Total for all databases", } diff --git a/pycounter/exceptions.py b/pycounter/exceptions.py index e855c93..cea3fa9 100644 --- a/pycounter/exceptions.py +++ b/pycounter/exceptions.py @@ -17,7 +17,7 @@ class SushiException(PycounterException): """Base class for SUSHI-related exceptions.""" def __init__(self, message, raw=None, xml=None): - super(SushiException, self).__init__(message) + super().__init__(message) self.raw = raw self.xml = xml @@ -59,7 +59,7 @@ class Sushi5Error(SushiException): """ def __init__(self, message, severity, code): - super(Sushi5Error, self).__init__(message) + super().__init__(message) self.message = message self.severity = severity self.code = code diff --git a/pycounter/report.py b/pycounter/report.py index ee2afe8..45cbc2f 100644 --- a/pycounter/report.py +++ b/pycounter/report.py @@ -25,7 +25,7 @@ ) -class CounterReport(object): +class CounterReport: """ a COUNTER usage statistics report. @@ -84,11 +84,8 @@ def __init__( self.section_type = section_type def __repr__(self): - return "" % ( - self.report_type, - self.report_version, - self.period[0], - self.period[1], + return "".format( + self.report_type, self.report_version, self.period[0], self.period[1] ) def __iter__(self): @@ -130,25 +127,22 @@ def as_generic(self): if code == self.report_type[0:2]: rep_type = name - report_name = "%s Report %s (R%s)" % ( - rep_type, - self.report_type[-1], - self.report_version, + report_name = "{} Report {} (R{})".format( + rep_type, self.report_type[-1], self.report_version ) output_lines.append([report_name, REPORT_DESCRIPTIONS[self.report_type]]) if self.report_type == "BR2": - output_lines.append([self.customer, u"Section Type:"]) + output_lines.append([self.customer, "Section Type:"]) output_lines.append([self.institutional_identifier, self.section_type]) else: output_lines.append([self.customer]) output_lines.append([self.institutional_identifier]) - output_lines.append([u"Period covered by Report:"]) - period = "%s to %s" % ( - self.period[0].strftime("%Y-%m-%d"), - self.period[1].strftime("%Y-%m-%d"), + output_lines.append(["Period covered by Report:"]) + period = "{} to {}".format( + self.period[0].strftime("%Y-%m-%d"), self.period[1].strftime("%Y-%m-%d") ) output_lines.append([period]) - output_lines.append([u"Date run:"]) + output_lines.append(["Date run:"]) output_lines.append([self.date_run.strftime("%Y-%m-%d")]) output_lines.append(self._table_header()) if self.report_type in ("JR1", "BR1", "BR2", "DB2"): @@ -168,7 +162,7 @@ def as_generic(self): def _totals_lines(self): """Generate Totals for COUNTER report, as list of lists of cells.""" total_lines = [] - metrics = set(resource.metric for resource in self.pubs) + metrics = {resource.metric for resource in self.pubs} for metric in sorted(metrics): total_lines.append(self._totals_line(metric)) @@ -178,18 +172,18 @@ def _totals_lines(self): def _totals_line(self, metric): """Generate Totals for a given metric.""" total_cells = [TOTAL_TEXT[self.report_type]] - publishers = set(resource.publisher for resource in self.pubs) + publishers = {resource.publisher for resource in self.pubs} if len(publishers) == 1: total_cells.append(publishers.pop()) else: - total_cells.append(u"") - platforms = set(resource.platform for resource in self.pubs) + total_cells.append("") + platforms = {resource.platform for resource in self.pubs} if len(platforms) == 1: total_cells.append(platforms.pop()) else: - total_cells.append(u"") + total_cells.append("") if self.report_type in ("JR1", "BR1", "BR2"): - total_cells.extend([u""] * 4) + total_cells.extend([""] * 4) elif self.report_type == "DB2": total_cells.append(metric) total_usage = 0 @@ -350,7 +344,7 @@ class CounterJournal(CounterEresource): def __init__( self, period=None, - metric=METRICS[u"JR1"], + metric=METRICS["JR1"], issn=None, eissn=None, month_data=None, @@ -362,9 +356,7 @@ def __init__( doi="", proprietary_id="", ): - super(CounterJournal, self).__init__( - period, metric, month_data, title, platform, publisher - ) + super().__init__(period, metric, month_data, title, platform, publisher) self.html_total = html_total self.pdf_total = pdf_total self.doi = doi @@ -448,9 +440,7 @@ def __init__( print_isbn=None, online_isbn=None, ): - super(CounterBook, self).__init__( - period, metric, month_data, title, platform, publisher - ) + super().__init__(period, metric, month_data, title, platform, publisher) self.eissn = None self.doi = doi self.proprietary_id = proprietary_id @@ -462,7 +452,7 @@ def __init__( if issn is not None: self.issn = issn else: - self.issn = u"" + self.issn = "" def __repr__(self): return """