Changeset - c714b2f41fd2
[Not reviewed]
0 3 0
Brett Smith - 3 years ago 2021-03-18 15:47:56
brettcsmith@brettcsmith.org
patreon: Income2017Importer grabs email address.
3 files changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
import2ledger/importers/patreon.py
Show inline comments
...
 
@@ -57,116 +57,117 @@ class IncomeImporter(_csv.CSVImporterBase):
 

	
 
    def __init_subclass__(cls):
 
        cls.NEEDED_FIELDS = frozenset([
 
            cls.AMOUNT_KEY,
 
            cls.DATE_KEY,
 
            cls.STATUS_KEY,
 
        ])
 

	
 
    def _read_row(self, row):
 
        if row[self.STATUS_KEY] != 'Paid':
 
            return None
 
        else:
 
            return {
 
                'amount': strparse.currency_decimal(row[self.AMOUNT_KEY]),
 
                'date': strparse.date(row[self.DATE_KEY], '%Y-%m-%d %H:%M:%S'),
 
            }
 

	
 

	
 
class PayoutImporter(_csv.CSVImporterBase):
 
    AMOUNT_KEY = 'Total funds deducted from creator balance'
 
    PLEDGE_KEY = 'Funds used for pledges to other creators'
 
    TRANSFER_KEY = 'Funds transferred to you'
 
    NEEDED_FIELDS = frozenset([
 
        'Month',
 
        TRANSFER_KEY,
 
        PLEDGE_KEY,
 
        AMOUNT_KEY,
 
    ])
 
    ENTRY_SEED = {
 
        'currency': 'USD',
 
        'payee': 'Patreon',
 
    }
 

	
 
    def _read_row(self, row):
 
        amount = strparse.currency_decimal(row[self.AMOUNT_KEY])
 
        if not amount:
 
            return None
 
        else:
 
            return {
 
                'amount': amount,
 
                'date': strparse.date(row['Month'], '%Y-%m'),
 
                'pledges_amount': strparse.currency_decimal(row[self.PLEDGE_KEY]),
 
                'transfer_amount': strparse.currency_decimal(row[self.TRANSFER_KEY]),
 
            }
 

	
 

	
 
class FeeImporterBase(_csv.CSVImporterBase):
 
    ENTRY_SEED = {
 
        'currency': 'USD',
 
        'payee': "Patreon",
 
    }
 

	
 
    def _read_row(self, row):
 
        return {
 
            'amount': row[self.AMOUNT_FIELD],
 
            'date': strparse.date(row['Month'], '%Y-%m'),
 
        }
 

	
 

	
 
class ServiceFeesImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Patreon Fee'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 

	
 

	
 
class CardFeesImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Processing Fees'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 

	
 

	
 
class VATImporter(FeeImporterBase):
 
    AMOUNT_FIELD = 'Vat Charged'
 
    NEEDED_FIELDS = frozenset(['Month', AMOUNT_FIELD])
 
    COPIED_FIELDS = {
 
        'Country Code': 'country_code',
 
        'Country Name': 'country_name',
 
    }
 

	
 

	
 

	
 
class Income2020OctoberImporter(IncomeImporter):
 
    AMOUNT_KEY = 'Pledge $'
 

	
 

	
 
class Income2020AugustImporter(Income2020OctoberImporter):
 
    DATE_KEY = 'Charged On Date'
 
    STATUS_KEY = 'Charge Status'
 

	
 

	
 
class Income2017Importer(_csv.CSVImporterBase):
 
    NEEDED_FIELDS = frozenset([
 
        'FirstName',
 
        'LastName',
 
        'Pledge',
 
        'Status',
 
    ])
 
    COPIED_FIELDS = {
 
        'Email': 'email',
 
        'Pledge': 'amount',
 
    }
 
    ENTRY_SEED = {
 
        'currency': 'USD',
 
    }
 

	
 
    def __init__(self, input_file):
 
        super().__init__(input_file)
 
        match = re.search(r'(?:\b|_)(\d{4}-\d{2}-\d{2})(?:\b|_)',
 
                          pathlib.Path(input_file.name).name)
 
        if match:
 
            self.entry_seed['date'] = strparse.date(match.group(1), '%Y-%m-%d')
 

	
 
    def _read_row(self, row):
 
        if row['Status'] != 'Processed':
 
            return None
 
        else:
 
            return {
 
                'payee': '{0[FirstName]} {0[LastName]}'.format(row),
 
            }
setup.py
Show inline comments
 
#!/usr/bin/env python3
 

	
 
import sys
 

	
 
from setuptools import setup, find_packages
 

	
 
REQUIREMENTS = {
 
    'install_requires': [
 
        'babel',
 
        'enum34;python_version<"3.4"',
 
    ],
 
    'setup_requires': ['pytest-runner'],
 
    'extras_require': {
 
        'brightfunds': ['xlrd'],
 
        'nbpy2017': ['beautifulsoup4', 'html5lib'],
 
    },
 
}
 

	
 
all_extras_require = [
 
    req for reqlist in REQUIREMENTS['extras_require'].values() for req in reqlist
 
]
 

	
 
REQUIREMENTS['extras_require']['all_importers'] = all_extras_require
 
REQUIREMENTS['tests_require'] = [
 
    'pytest',
 
    'PyYAML',
 
    *all_extras_require,
 
]
 

	
 
setup(
 
    name='import2ledger',
 
    description="Import different sources of financial data to Ledger",
 
    version='1.4.2',
 
    version='1.4.3',
 
    author='Brett Smith',
 
    author_email='brettcsmith@brettcsmith.org',
 
    license='GNU AGPLv3+',
 

	
 
    packages=find_packages(include=['import2ledger', 'import2ledger.*']),
 
    entry_points={
 
        'console_scripts': ['import2ledger = import2ledger.__main__:main'],
 
    },
 

	
 
    **REQUIREMENTS,
 
)
tests/data/imports.yml
Show inline comments
 
- source: PatreonPatronReport_2017-09-01.csv
 
  importer: patreon.Income2017Importer
 
  expect:
 
    - payee: Alex Jones
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["1500.00"]
 
      currency: USD
 
      email: alex@example.org
 
    - payee: Dakota Doe
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["12.00"]
 
      currency: USD
 
      email: ddoe@example.org
 

	
 
- source: PatreonPatronReport_2020-08-01.csv
 
  importer: patreon.Income2020AugustImporter
 
  expect:
 
    - payee: Alex Jones
 
      email: ajones@example.com
 
      tier: Even tier
 
      patreon_id: "1234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["2"]
 
      currency: USD
 
    - payee: Breonna
 
      email: breonna@example.org
 
      tier: Odd tier
 
      patreon_id: "234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 2]
 
      amount: !!python/object/apply:decimal.Decimal ["5.00"]
 
      currency: USD
 

	
 
- source: PatreonPatronReport_2020-10-01.csv
 
  importer: patreon.Income2020OctoberImporter
 
  expect:
 
    - payee: Alex Jones
 
      email: ajones@example.com
 
      tier: Even tier
 
      patreon_id: "1234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["2"]
 
      currency: USD
 
    - payee: Breonna
 
      email: breonna@example.org
 
      tier: Odd tier
 
      patreon_id: "234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 2]
 
      amount: !!python/object/apply:decimal.Decimal ["5.00"]
 
      currency: USD
 

	
 
- source: PatreonPatronReport_2020-11-01.csv
 
  importer: patreon.IncomeImporter
 
  expect:
 
    - payee: Alex Jones
 
      email: ajones@example.com
 
      tier: Even tier
 
      patreon_id: "1234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["2"]
 
      currency: USD
 
    - payee: Breonna
 
      email: breonna@example.org
 
      tier: Odd tier
 
      patreon_id: "234567"
 
      date: !!python/object/apply:datetime.date [2020, 8, 2]
 
      amount: !!python/object/apply:decimal.Decimal ["5.00"]
 
      currency: USD
 

	
 
- source: PatreonEarnings.csv
 
  importer: patreon.ServiceFeesImporter
 
  expect:
 
    - payee: Patreon
 
      date: !!python/object/apply:datetime.date [2017, 9, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["61.73"]
 
      currency: USD
 
    - payee: Patreon
 
      date: !!python/object/apply:datetime.date [2017, 10, 1]
 
      amount: !!python/object/apply:decimal.Decimal ["117.03"]
 
      currency: USD
 

	
 
- source: PatreonEarnings2020.csv
 
  importer: patreon.EarningsImporter
 
  expect:
 
    - payee: Frances Jones
 
      email: fjones@example.com
 
      user_id: "32101234"
 
      event_id: "30123456"
 
      date: !!python/object/apply:datetime.date [2020, 12, 3]
 
      currency: USD
 
      amount: !!python/object/apply:decimal.Decimal ["5"]
 
      tax_amount: !!python/object/apply:decimal.Decimal ["1"]
 
      net_amount: !!python/object/apply:decimal.Decimal ["4.31"]
 
      platform_fee: !!python/object/apply:decimal.Decimal ["0.25"]
 
      processing_fee: !!python/object/apply:decimal.Decimal ["0.44"]
 
      currency_fee: !!python/object/apply:decimal.Decimal ["0"]
 
    - payee: Barbara Johnson
 
      email: bjohnson@example.com
 
      user_id: "2345678"
 
      event_id: "34567890"
 
      date: !!python/object/apply:datetime.date [2020, 12, 2]
 
      currency: USD
 
      amount: !!python/object/apply:decimal.Decimal ["6.06"]
 
      tax_amount: !!python/object/apply:decimal.Decimal ["1.27"]
 
      net_amount: !!python/object/apply:decimal.Decimal ["5.14"]
 
      platform_fee: !!python/object/apply:decimal.Decimal ["0.31"]
 
      processing_fee: !!python/object/apply:decimal.Decimal ["0.42"]
 
      currency_fee: !!python/object/apply:decimal.Decimal ["0.19"]
 
    - payee: Alex Jones
 
      email: ajones@example.com
0 comments (0 inline, 0 general)