コード例 #1
0
ファイル: cli.py プロジェクト: jessiedeot/pyoblib
def convert(args):

    p = ob_parser.Parser(taxonomy)

    ff = None
    if json:
        ff = ob_parser.FileFormat.JSON
    elif xml:
        ff = ob_parser.FileFormat.XML
    elif args.infile.lower().endswith(
            ".json") and args.outfile.lower().endswith(".xml"):
        ff = ob_parser.FileFormat.JSON
    elif args.infile.lower().endswith(
            ".xml") and args.outfile.lower().endswith(".json"):
        ff = ob_parser.FileFormat.XML

    if ff is None:
        print("Unable to determine file format.  Conversion not processed.")
        sys.exit(1)

    try:
        p.convert(args.infile,
                  args.outfile,
                  ff,
                  entrypoint_name=args.entrypoint)
    except ob.OBValidationErrors as errors:
        for e in errors.get_errors():
            print(e)
コード例 #2
0
# You may obtain a copy of the License at

#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from jsondiff import diff
from oblib import parser, taxonomy

taxonomy = taxonomy.Taxonomy()
parser = parser.Parser(taxonomy)


class TestParser(unittest.TestCase):
    # Note: this module is tested differently than others.  Sample JSON and XML
    # files are imported and then exported and later compared using the string
    # methods.  Thereafter files are loaded and created but the files contents
    # themselves are not examined (it is assumed that this would be picked up
    # in the comparisons of the strings).

    def test_json(self):

        entrypoint = parser.from_JSON_string(TEST_JSON)
        out = parser.to_JSON_string(entrypoint)
        d = diff(TEST_JSON, out)
コード例 #3
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This sample program creates a XBRL JSON Power Purchase Agreement populated with fake data.
It can be used as a starting point for building a program to create real Power Purchase Agreement
Orange Button data.
"""

from oblib import taxonomy, data_model, parser

import datetime

# Initialize oblib and create an Entrypoint for a Power Purchase Agreement
tax = taxonomy.Taxonomy()
ob_parser = parser.Parser(tax)
entrypoint = data_model.OBInstance("PowerPurchaseAgreement",
                                   tax,
                                   dev_validation_off=True)

#
# PowerPurcahseAgreements (PPA's) have two tables, a PowerPurchaseAgremeentContract table and an EnergyRateTable.
# Both tables can be placed in the same set of XBRL JSON (or XML).  They are both included in the code.
#

# Create 5 rows of data in the PowerPurchaseAgreementContract table
for i in range(0, 5):

    # The priamry key will be numbered 1-5 in each row, in a real application it can be set to any string value.
    pk_value = str(i + 1)