Skip to content

Commit

Permalink
aligned wd claims language option to the general -l, --lang
Browse files Browse the repository at this point in the history
and converted to use const instead of var when relevent
  • Loading branch information
maxlath committed Aug 28, 2016
1 parent d34cfa3 commit 4f5e805
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ wd label Q1103345
```

**Options**

* `-l, --lang`: specify the label's language

By default, the result uses your environment local language (`process.env.LANG`), but you can pass a 2-letters language code as second argument
Expand All @@ -63,9 +62,13 @@ A quick way to access the claims of an entity
wd claims Q2001
# or just his place of birth
wd claims Q2001 P19
# or by specifying another language than your local language
wd claims Q2001 fr
wd claims Q2001 P19 fr
```

**Options**
* `-l, --lang`: specify the properties labels' language
```sh
wd claims Q2001 -l es
wd claims Q2001 P19 --lang ru
```

### wd data
Expand Down
38 changes: 17 additions & 21 deletions bin/wd-claims
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,54 @@ const strings = require('../lib/strings')
program
.arguments(strings.claims.args)
.description(strings.claims.description)
.option('-l, --lang <lang>', "specify the properties labels' language")
.parse(process.argv)

var id = program.args[0]
var prop = program.args[1]
var localLang = require('../lib/local_lang')
const localLang = require('../lib/local_lang')

Promise = require('bluebird')

if ( /^\w{2}$/.test(prop) ) {
var lang = prop
prop = null
} else {
var lang = program.args[2] || localLang || 'en'
}
const lang = program.lang || localLang || 'en'

if (!(id && lang)) return program.help()

var propsPromise = require('../lib/get_lang_props')(lang)
const propsPromise = require('../lib/get_lang_props')(lang)

if (/^[0-9]+$/.test(id)) { id = `Q${id}` }
if (/^[0-9]+$/.test(prop)) { prop = `P${prop}` }

var copy = require('../lib/copy')
var breq = require('bluereq')
var error_ = require('../lib/error')
var exist = require('../lib/exist')
const copy = require('../lib/copy')
const breq = require('bluereq')
const error_ = require('../lib/error')
const exist = require('../lib/exist')

var wdk = require('wikidata-sdk')
const wdk = require('wikidata-sdk')
require('colors')

var url = wdk.getEntities({
const url = wdk.getEntities({
props: 'claims',
ids: id
})

var parseRes = function (res, props) {
var entity = res.body.entities && res.body.entities[id]
const parseRes = function (res, props) {
const entity = res.body.entities && res.body.entities[id]

var logProp = function (k, v) {
var label = props[k]
const logProp = function (k, v) {
const label = props[k]
console.log(k.grey, v, label && label.grey || '')
}

if (exist(entity)) {
var claims = wdk.simplifyClaims(entity.claims)
const claims = wdk.simplifyClaims(entity.claims)
if (exist(prop)) {
var value = claims[prop]
const value = claims[prop]
if (value != null) {
logProp(prop, claims[prop])
copy(claims[prop].toString())
} else {
label = props[prop]
const label = props[prop]
console.log('no statement found'.yellow, label)
}
} else {
Expand Down

0 comments on commit 4f5e805

Please sign in to comment.