Ejemplo n.º 1
0
    def test_start_day(self):
        assert fiscalyear.START_DAY == 1

        fiscalyear.setup_fiscal_calendar(start_day=6)
        assert fiscalyear.START_DAY == 6
        fiscalyear.setup_fiscal_calendar(start_day=1)

        assert fiscalyear.START_DAY == 1
Ejemplo n.º 2
0
    def test_start_year(self):
        assert fiscalyear.START_YEAR == "previous"

        fiscalyear.setup_fiscal_calendar(start_year="same")
        assert fiscalyear.START_YEAR == "same"
        fiscalyear.setup_fiscal_calendar(start_year="previous")

        assert fiscalyear.START_YEAR == "previous"
Ejemplo n.º 3
0
    def test_start_month(self):
        assert fiscalyear.START_MONTH == 10

        fiscalyear.setup_fiscal_calendar(start_month=4)
        assert fiscalyear.START_MONTH == 4
        fiscalyear.setup_fiscal_calendar(start_month=10)

        assert fiscalyear.START_MONTH == 10
Ejemplo n.º 4
0
    def test_start_year(self):
        assert fiscalyear.START_YEAR == 'previous'

        fiscalyear.setup_fiscal_calendar(start_year='same')
        assert fiscalyear.START_YEAR == 'same'
        fiscalyear.setup_fiscal_calendar(start_year='previous')

        assert fiscalyear.START_YEAR == 'previous'
Ejemplo n.º 5
0
    def test_complex(self):
        # Test defaults
        day = fiscalyear.FiscalDate(2017, 12, 1)
        assert day.fiscal_year == 2018
        assert day.fiscal_quarter == 1

        # Change fiscal year settings
        fiscalyear.setup_fiscal_calendar("same", 1, 1)
        assert day.fiscal_year == 2017
        assert day.fiscal_quarter == 4

        # Restore defaults and re-test
        fiscalyear.setup_fiscal_calendar("previous", 10, 1)
        assert day.fiscal_year == 2018
        assert day.fiscal_quarter == 1
idx = 1
for name, format_data in [("Date", 17), ("Code", 9), ("Transaction type", 15),
                          ("Quantity", 9), ("Subquantity", 11),
                          ("Average price", 12), ("Brokerage", 10),
                          ("Cost base", 11), ("Capital gain <= 1 year", 21),
                          ("Capital gain > 1 year", 20),
                          ("Net capital gain", 15), ("History", 50),
                          ("Filename", 70)]:
    COLUMNS[name] = idx
    idx += 1
    FORMAT[name] = format_data
del idx

# In Australia, the financial year begins on 1 July
# Fiscal year is represented by the year of its end date
fiscalyear.setup_fiscal_calendar('previous', 7, 1)


class InvestmentRecord():
    """Holds data for a single investment event, such as a sell or a buy.

    """
    def __init__(self, filename: str, record_type: int) -> None:
        self.filename = filename
        self.record_type = record_type
        self.populate()

    def populate_WH_ContractNote(self, text: str) -> None:
        # We can handle nabTrade Contract Notes
        # These will have a first line of text as follows
        if not text.startswith("WealthHub Securities Limited"):
Ejemplo n.º 7
0
            json.dumps({
                "ID": "<your PayPal client ID here>",
                "Secret": "<your PayPal secret here>"
            }))

    print(
        "No PayPal SDK credentials available. Please add credentials details to {cred_file}",
        file=sys.stderr)

else:
    # Creating an environment
    environment = LiveEnvironment(client_id=CREDS["ID"],
                                  client_secret=CREDS["Secret"])
    client = PayPalHttpClient(environment)

    setup_fiscal_calendar(start_month=7)
    dt_from = FiscalYear(FiscalDateTime.now().fiscal_year).start.astimezone(
        tz.tzlocal())
    dt_to = FiscalDateTime.now().astimezone(tz.tzlocal())

    request = TransactionRequest(dt_from, dt_to)

    transactions = request.execute(client)

    header = [
        "Date", "Transaction Commodity", "Deposit", "Price", "Quantity",
        "Balance", "Num", "Description", "Notes", "Partner", "Transfer Account"
    ]
    print(",".join(header))

    for t in transactions:  #response.result.transaction_details:
Ejemplo n.º 8
0
def vodfone_quarter(c):
    fiscalyear.setup_fiscal_calendar(start_month=4)
    fiscalyear.setup_fiscal_calendar(start_day=10)

    return ('Q' + str(c.quarter))
Ejemplo n.º 9
0
def vodfone_fy(c):

    fiscalyear.setup_fiscal_calendar(start_month=4)
    fiscalyear.setup_fiscal_calendar(start_day=10)

    return (str(c.year - 2000) + '/' + str(c.fiscal_year - 2000))
Ejemplo n.º 10
0
# ----------------------------------------------------------------------------
# STYLING
# ----------------------------------------------------------------------------

CONTENT_STYLE = {
    "padding": "2rem 1rem",
    "font-family": '"Times New Roman", Times, serif'
}

# ----------------------------------------------------------------------------
# DATA LOADING AND CLEANING
# ----------------------------------------------------------------------------

# use fiscalyear package to calculate snow year dates, start the snow year on Sept. 1.
# Example: 2017 snow year = Oct 1, 2016 - Sept 30, 2017
fy.setup_fiscal_calendar(start_month=10)

# List of Station IDs in the CDEC Snow Sensor network for the JMT
Sierra_stations_list = [
    'BSH', 'CBT', 'CRL', 'CWD', 'MHP', 'STL', 'SWM', 'TNY', 'TUM', 'UTY', 'VLC'
]

# Load Snow Data (2000 - 3/6/2021)
data_filepath = pathlib.Path(__file__).parent.absolute()
snow = pd.read_csv(os.path.join(data_filepath, 'SWE.csv'))

# Clean up date.
# * Split DATE TIME into 2 values
# * Coerce Value column to numeric and drop NA rows to exclude missing data
# * Get columns for Day, Month and Year from the Date column
snow[['Date', 'Time']] = snow['DATE TIME'].str.split(expand=True)
Ejemplo n.º 11
0
def main():

    fy.setup_fiscal_calendar(start_month=9)
    now = fy.FiscalDateTime.now()
    start_date = now.prev_quarter.start.strftime('%Y-%m-%d')
    end_date = now.prev_quarter.end.strftime('%Y-%m-%d')
    print(start_date)
    print(end_date)

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description="Retrieve Google Analytics data.")
    parser.add_argument("-d", "--debug",
        help="Enable debugging messages", action="store_true")
    parser.add_argument("output_file", metavar="OUTPUT_FILE",
        nargs="?",
        default="sessions.csv",
        help="Output CSV file")
    parser.add_argument("-s", "--start-date",
        default=start_date,
        help="Start date")
    parser.add_argument("-e", "--end-date",
        default=end_date,
        help="End date")
    args = parser.parse_args()

    if args.start_date != start_date:
        args.start_date = parse_date(args.start_date)
        print(args.start_date)

    if args.end_date != end_date:
        args.end_date = parse_date(args.end_date)
        print(args.end_date)

    pd.set_option('display.max_columns', None)
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_colwidth', None)
    # pd.set_option('display.float_format', '{:,.0f}'.format)

    gc = GeonamesCache()
    global countries
    countries = gc.get_countries()
    countries['ZZ'] = {'iso3': 'ZZZ'}

    mapper = country(from_key='iso', to_key='iso3')

    scope = ['https://www.googleapis.com/auth/analytics.readonly']

    # Authenticate and construct service.
    service = get_service('analytics', 'v3', scope, 'client_secrets.json')

    profile_ids = get_profile_ids(service)
    pprint.pprint(profile_ids)

    total = pd.DataFrame()

    for profile_id in profile_ids:
        results = get_results(service, profile_id,
            args.start_date, args.end_date)
        df = create_dataframe(results)
        with pd.option_context('display.max_rows', None,
                'display.max_columns', None):
            print(df)
        total = total.add(df, fill_value=0)

    total.index = [conv_iso_2_to_3(i) for i in total.index]
    total.index.name = 'iso3'
    total.columns = [re.sub(r'^ga:', '', col) for col in total.columns]
    set_int(total)

    total.to_csv(args.output_file)