From 6cde0289a59e81039c6d95fc7422f9facb869ec6 Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Sun, 28 Jun 2020 12:20:34 -0400 Subject: [PATCH] Prevent newlines in JSONL If a set of 100 ids are hydrated and not one of them is still available the Hydrator was writing a blank line to the jsonl file. This could cause problems for downstream users of the jsonl that are expecting each line to contain a JSON object. Refs #48 --- app/utils/twitter.js | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/utils/twitter.js b/app/utils/twitter.js index 6d62212..3254363 100644 --- a/app/utils/twitter.js +++ b/app/utils/twitter.js @@ -56,8 +56,10 @@ export async function getUserSettings(auth) { export async function hydrateToStream(ids, out, auth, event, datasetId, tries=0) { try { const tweets = await fetchTweets(ids, auth) - const text = tweets.map(t => JSON.stringify(t)).join('\n') - out.write(text + "\n") + if (tweets.length > 0) { + const text = tweets.map(t => JSON.stringify(t)).join('\n') + out.write(text + "\n") + } event.sender.send(UPDATE_PROGRESS, { datasetId: datasetId, idsRead: ids.length, diff --git a/package.json b/package.json index bffe3e1..3842626 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hydrator", - "version": "0.0.11", + "version": "0.0.12", "description": "A desktop utility to hydrate Twitter ID datasets.", "main": "init.js", "author": {