github: New importer.

This commit is contained in:
Brett Smith 2020-07-07 10:16:29 -04:00
parent 910b942e20
commit e5b600dae6
5 changed files with 90 additions and 1 deletions

View file

@ -228,6 +228,29 @@ Eventbrite
total_fees From the ``Fees Paid`` spreadsheet column 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 O'Reilly Media
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

View file

@ -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),
}

View file

@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [
setup( setup(
name='import2ledger', name='import2ledger',
description="Import different sources of financial data to Ledger", description="Import different sources of financial data to Ledger",
version='0.11.1', version='1.0.0',
author='Brett Smith', author='Brett Smith',
author_email='brettcsmith@brettcsmith.org', author_email='brettcsmith@brettcsmith.org',
license='GNU AGPLv3+', license='GNU AGPLv3+',

View file

@ -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
1 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
2 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
3 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
4 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
5 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

View file

@ -904,3 +904,34 @@
eventbrite_fees: !!python/object/apply:decimal.Decimal ["2.99"] eventbrite_fees: !!python/object/apply:decimal.Decimal ["2.99"]
payment_fees: !!python/object/apply:decimal.Decimal ["1"] payment_fees: !!python/object/apply:decimal.Decimal ["1"]
tax: !!python/object/apply:decimal.Decimal [0] 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