Ejemplo n.º 1
0
def download_table():
    parser = argparse.ArgumentParser(
        description="Download a table from a clld database",
        epilog="""\
This script can be used to download the content of dynamic tables displayed on
HTML pages of clld apps. The content is retrieved as a JSON array of objects,
and written to stdout, thus can be easily integrated into a pipeline of csvkit
commands.""")
    parser.add_argument('host', help='The database host, e.g. "wals.info"')
    parser.add_argument('resource', help='Resource type to download, e.g. "language"')
    parser.add_argument('--output', help='file path to write the data to', default=None)
    parser.add_argument(
        '--with-html',
        help="""By default, HTML markup is stripped from the data. Use this option to
keep it.""",
        action="store_true",
        default=False)

    constraints = ['parameter', 'language', 'contribution']
    for name in constraints:
        parser.add_argument(
            '--' + name,
            help="""\
"value" or "valueset" tables can often be restricted to a certain %s
by passing its local ID."""
                 % name,
            default=None)
    args = parser.parse_args()
    db = Database(args.host)
    table = db.table(
        args.resource,
        strip_html=not args.with_html,
        **{name: getattr(args, name) for name in constraints if getattr(args, name)})
    table.save(fname=args.output)
Ejemplo n.º 2
0
    def test_Database(self):
        from clldclient.database import Database

        with patch('clldclient.database.Cache', MockCache):
            client = Database('localhost:6543')
            self.assertEquals(client.url('/p').as_string(), 'http://localhost:6543/p')
            self.assertEquals(
                client.url('/p', q='s').as_string(), 'http://localhost:6543/p?q=s')

            ds = client.dataset
            assert ds.license
            assert ds.citation
            assert ds.name
            assert repr(ds)
            assert ds['http://purl.org/dc/terms/title']
            self.assertRaises(KeyError, ds.__getitem__, 'abcd')
            ds.get_text(list(ds.g.objects(ds.uriref, DCTERMS['title']))[0])
            self.assertEquals(len(ds.resource_types), 2)
            res = client.resources('parameter')
            self.assertEquals(res.member_type, 'parameter')
            self.assertEquals(len(res), 1)
            for param in res:
                self.assertEquals(param.type, 'parameter')
            param = client.resource('parameter', 'parameter')
            self.assertEquals(len(param.domain), 2)
            self.assertEquals(param.id, 'parameter')
            param2 = client.resource('parameter', 'parameter')
            self.assertEquals(param, param2)
            self.assertFalse(param == 1)
            lat = client.resource('language', 'language')
            self.assertEquals(lat.iso_code, 'abc')
            self.assertEquals(lat.glottocode, 'abcd1234')
            self.assertEquals(len(list(client.formats(param))), 1)
Ejemplo n.º 3
0
 def __init__(self):
     self.__resource_map__['parameter'] = ConceptSet
     self.__resource_map__['value'] = Concept
     Database.__init__(self, 'concepticon.clld.org')
Ejemplo n.º 4
0
 def __init__(self):
     self.__resource_map__.update(
         language=Language,
         genus=Genus,
         family=Family)
     Database.__init__(self, 'wals.info')
Ejemplo n.º 5
0
 def __init__(self):
     self.__resource_map__['language'] = Languoid
     Database.__init__(self, 'glottolog.org')