Changeset - e5b600dae681
[Not reviewed]
0 3 2
Brett Smith - 4 years ago 2020-07-07 14:41:02
brettcsmith@brettcsmith.org
github: New importer.
5 files changed with 90 insertions and 1 deletions:
0 comments (0 inline, 0 general)
README.rst
Show inline comments
...
 
@@ -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
 
^^^^^^^^^^^^^^
 

	
import2ledger/importers/github.py
Show inline comments
 
new file 100644
 
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),
 
        }
setup.py
Show inline comments
...
 
@@ -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+',
tests/data/GitHubSponsors.csv
Show inline comments
 
new file 100644
 
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
tests/data/imports.yml
Show inline comments
...
 
@@ -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
0 comments (0 inline, 0 general)