Skip to content

Commit

Permalink
modified Wikidata sync script to ignore certain Facebook API warnings
Browse files Browse the repository at this point in the history
* dry runs of the script were used to test/verify the new code's validity and its impact on performance
* warnings regarding Facebook usernames tagged with one of three "online access value" qualifier/value pairings (Q113165094 - location restrictions, Q58370623 - private account, Q107459441 - only visible when logged in) were successfully suppressed
* there did not appear to be any impact to the script's performance in terms of either function or speed
* resolves #10233
  • Loading branch information
Snowysauce committed Dec 24, 2024
1 parent 6001b85 commit f77b37a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/src/CategoryRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function CategoryRow(props) {
const v = params.v;
const filters = getFilterParams(params); // filters are used here for highlighting

// Determine dissolutation date (if any)
// Determine dissolution date (if any)
const dissolvedInfo = context.dissolved[item.id];
let dissolved;
if (Array.isArray(dissolvedInfo)) {
Expand Down Expand Up @@ -302,7 +302,7 @@ relation[${k}=${v}][network:wikidata=${qid}]
`;
});

/* Add an <hr/> line break only if addational information will be displayed. */
/* Add an <hr/> line break only if additional information will be displayed. */
if (item.matchNames || item.matchTags || item.note || item.preserveTags || item.issues || item.fromTemplate)
result += '<hr/>';

Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/build_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function collectFeatures() {
if (feature.id) { obj.id = feature.id; }
if (feature.properties) {
obj.properties = feature.properties;
delete obj.properties.id; // to prevent possiblity of conflicting ids
delete obj.properties.id; // to prevent possibility of conflicting ids
} else {
obj.properties = {};
}
Expand Down
49 changes: 42 additions & 7 deletions scripts/build_wikidata.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ if (_secrets && _secrets.wikibase) {

// what to fetch
let _cache = {};
console.log(`Loading index files (this might take around 30 seconds) ...`);
fileTree.read(_cache, loco);
fileTree.expandTemplates(_cache, loco);

Expand Down Expand Up @@ -335,7 +336,31 @@ function processEntities(result) {
const facebookUser = getClaimValue(entity, 'P2013');
if (facebookUser) {
target.identities.facebook = facebookUser;
facebookQueue.push({ qid: qid, username: facebookUser }); // queue logo fetch

// get access status of selected value - #10233
let restriction;

for (let i = 0; i < entity.claims['P2013'].length; i++) {
const c = entity.claims['P2013'][i];
if ( c.mainsnak.snaktype === 'value' && c.mainsnak.datavalue.value === facebookUser ) {
const qualifiers = (c.qualifiers && c.qualifiers.P6954) || [];
for (let j = 0; j < qualifiers.length; j++) {
const q = qualifiers[j];
if ( q.snaktype !== 'value' ) continue;

let value = q.datavalue.value.id;
// Q113165094 - location restrictions, Q58370623 - private account, Q107459441 - only visible when logged in
if (value === 'Q58370623' || value === 'Q107459441' || value === 'Q113165094') {
restriction = true;
break;
}
}

break;
}
}

facebookQueue.push({ qid: qid, username: facebookUser, restriction: restriction }); // queue logo fetch
}

// P2397 - YouTube ID
Expand Down Expand Up @@ -495,7 +520,7 @@ function processEntities(result) {

}); // foreach qid

return Promise.all( facebookQueue.map(obj => fetchFacebookLogo(obj.qid, obj.username)) )
return Promise.all( facebookQueue.map(obj => fetchFacebookLogo(obj.qid, obj.username, obj.restriction)) )
.then(() => processWbEditQueue(wbEditQueue));
}

Expand Down Expand Up @@ -633,7 +658,7 @@ function finish() {


// https://developers.facebook.com/docs/graph-api/reference/user/picture/
function fetchFacebookLogo(qid, username) {
function fetchFacebookLogo(qid, username, restriction) {
let target = _wikidata[qid];
let logoURL = `https://graph.facebook.com/${username}/picture?type=large`;
let userid;
Expand All @@ -656,16 +681,26 @@ function fetchFacebookLogo(qid, username) {
if (json.data && !json.data.is_silhouette) {
target.logos.facebook = logoURL;
}

if ( restriction ) {
// show warning if Wikidata notes that access to the profile is restricted in some way, but the profile is public - #10233
const warning = { qid: qid, msg: `Facebook username @${username} has a restricted access qualifier, but is publicly accessible` };
console.warn(chalk.yellow(warning.qid.padEnd(12)) + chalk.red(warning.msg));
_warnings.push(warning);
}
return true;
})
.catch(e => {
if (userid) {
target.identities.facebook = userid;
return fetchFacebookLogo(qid, userid); // retry with just the numeric id
return fetchFacebookLogo(qid, userid, restriction); // retry with just the numeric id
} else {
const warning = { qid: qid, msg: `Facebook username @${username}: ${e}` };
console.warn(chalk.yellow(warning.qid.padEnd(12)) + chalk.red(warning.msg));
_warnings.push(warning);
// suppress warning if Wikidata notes that access to the profile is restricted in some way - #10233
if ( !restriction ) {
const warning = { qid: qid, msg: `Facebook username @${username}: ${e}` };
console.warn(chalk.yellow(warning.qid.padEnd(12)) + chalk.red(warning.msg));
_warnings.push(warning);
}
}
});
}
Expand Down

0 comments on commit f77b37a

Please sign in to comment.