Skip to content

Commit

Permalink
set User-Agent for wikidata API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Feb 28, 2024
1 parent 378bf34 commit 7bb8393
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/core/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { join } from 'node:path';
import type { NameType } from '../data';

export const USER_AGNET =
'An OpenStreetMap New Zealand project, contact https://github.com/osm-nz';

const repoRoot = join(__dirname, '../..');

export const englishDictFile = join(repoRoot, 'tmp/englishDictionary.json');
Expand Down
9 changes: 7 additions & 2 deletions src/stage2-preprocess/fetchWikidata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { wikidataFile } from '../core';
import { USER_AGNET, wikidataFile } from '../core';
import type { WikidataFile } from '../types';

type WikidataAPI = {
Expand Down Expand Up @@ -32,7 +32,12 @@ export async function fetchWikidata(): Promise<WikidataFile> {

const request = await fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(QUERY)}`,
{ headers: { Accept: 'application/sparql-results+json' } },
{
headers: {
Accept: 'application/sparql-results+json',
'User-Agent': USER_AGNET,
},
},
);
const apiResp: WikidataAPI = await request.json();

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type OsmPatchFile = FeatureCollection<Geometry, Tags> & {
addWayCount: number;
percentageAnt: number;
};
changesetTags?: Tags;
};

export type StatsFile = Record<NameType, null | OsmPatchFile['stats']>;
Expand Down

0 comments on commit 7bb8393

Please sign in to comment.