diff --git a/README.rst b/README.rst index 7e57f80..bccc94d 100644 --- a/README.rst +++ b/README.rst @@ -228,6 +228,29 @@ Eventbrite total_fees From the ``Fees Paid`` spreadsheet column ================ =========================================================== +GitHub +^^^^^^ + +``github sponsors ledger entry`` + Imports one transaction per processed sponsorship. Generated from CSV export of GitHub Sponsors report. + + This template can use these variables. Note that name and email may both be empty if the sponsor chooses not to make that information public. + + ================ =========================================================== + Name Contents + ================ =========================================================== + email From the ``Sponsor Public Email`` column + ---------------- ----------------------------------------------------------- + handle From the ``Sponsor Handle`` column, their username on + GitHub + ---------------- ----------------------------------------------------------- + name From the ``Sponsor Public Name`` column + ---------------- ----------------------------------------------------------- + start_date A date, from the ``Sponsorship Started On`` column + ---------------- ----------------------------------------------------------- + transaction_id From the ``Transaction ID`` column + ================ =========================================================== + O'Reilly Media ^^^^^^^^^^^^^^ diff --git a/import2ledger/importers/github.py b/import2ledger/importers/github.py new file mode 100644 index 0000000..ae2ea9a --- /dev/null +++ b/import2ledger/importers/github.py @@ -0,0 +1,30 @@ +import decimal + +from . import _csv +from .. import strparse + +class SponsorsImporter(_csv.CSVImporterBase): + DATE_FMT = '%Y-%m-%d %H:%M:%S %z' + NEEDED_FIELDS = frozenset([ + 'Processed Amount', + 'Status', + 'Transaction Date', + ]) + COPIED_FIELDS = { + 'Sponsor Handle': 'handle', + 'Sponsor Profile Name': 'name', + 'Sponsor Public Email': 'email', + 'Transaction ID': 'transaction_id', + } + ENTRY_SEED = {'currency': 'USD'} + + def _read_row(self, row): + amount = strparse.currency_decimal(row['Processed Amount']) + if (not amount) or row['Status'] != 'settled': + return None + return { + 'amount': amount, + 'date': strparse.date(row['Transaction Date'], self.DATE_FMT), + 'payee': row['Sponsor Profile Name'] or row['Sponsor Handle'], + 'start_date': strparse.date(row['Sponsorship Started On'], self.DATE_FMT), + } diff --git a/setup.py b/setup.py index 8de41b7..43bc81a 100755 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [ setup( name='import2ledger', description="Import different sources of financial data to Ledger", - version='0.11.1', + version='1.0.0', author='Brett Smith', author_email='brettcsmith@brettcsmith.org', license='GNU AGPLv3+', diff --git a/tests/data/GitHubSponsors.csv b/tests/data/GitHubSponsors.csv new file mode 100644 index 0000000..ad75ced --- /dev/null +++ b/tests/data/GitHubSponsors.csv @@ -0,0 +1,5 @@ +Sponsor Handle,Sponsor Profile Name,Sponsor Public Email,Sponsorship Started On,Is Public?,Is Yearly?,Transaction ID,Tier Name,Tier Monthly Amount,Processed Amount,Is Prorated?,Status,Transaction Date +exampleA,Alex Jones,ajones@example.com,2019-10-01 10:00:00 -0400,TRUE,FALSE,ch_1Gabcdefghijklmnopqrstuv,$1/month,$1.00,$1.00,FALSE,settled,2020-01-02 14:02:00 -0500 +exampleB,,,2019-11-01 11:00:00 -0400,FALSE,FALSE,1023ABCD5678EFGHI,$10/month,$10.00,$10.00,FALSE,settled,2020-01-03 15:03:00 -0500 +exampleC,Example Co,info@example.com,2019-12-01 12:00:00 -0500,TRUE,TRUE,ch_1Gabcdefghijklmnopqrstuw,$10/month,$10.00,$120.00,FALSE,settled,2020-01-04 16:04:00 -0500 +exampleD,Declined Smith,dsmith@example.com,2020-01-01 01:00:00 -0500,TRUE,FALSE,1023ABCD5678EFGHJ,$1/month,$1.00,$1.00,FALSE,processor_declined,2020-01-05 17:05:00 -0500 diff --git a/tests/data/imports.yml b/tests/data/imports.yml index 49af4d7..c00c289 100644 --- a/tests/data/imports.yml +++ b/tests/data/imports.yml @@ -904,3 +904,34 @@ eventbrite_fees: !!python/object/apply:decimal.Decimal ["2.99"] payment_fees: !!python/object/apply:decimal.Decimal ["1"] tax: !!python/object/apply:decimal.Decimal [0] + +- source: GitHubSponsors.csv + importer: github.SponsorsImporter + expect: + - date: !!python/object/apply:datetime.date [2020, 1, 2] + payee: Alex Jones + handle: exampleA + name: Alex Jones + email: ajones@example.com + start_date: !!python/object/apply:datetime.date [2019, 10, 1] + transaction_id: ch_1Gabcdefghijklmnopqrstuv + amount: !!python/object/apply:decimal.Decimal ["1"] + currency: USD + - date: !!python/object/apply:datetime.date [2020, 1, 3] + payee: exampleB + handle: exampleB + name: "" + email: "" + start_date: !!python/object/apply:datetime.date [2019, 11, 1] + transaction_id: 1023ABCD5678EFGHI + amount: !!python/object/apply:decimal.Decimal ["10"] + currency: USD + - date: !!python/object/apply:datetime.date [2020, 1, 4] + payee: Example Co + handle: exampleC + name: Example Co + email: info@example.com + start_date: !!python/object/apply:datetime.date [2019, 12, 1] + transaction_id: ch_1Gabcdefghijklmnopqrstuw + amount: !!python/object/apply:decimal.Decimal ["120"] + currency: USD