From 6ac061498541a623963be6f76d1866704d7f1357 Mon Sep 17 00:00:00 2001 From: dale-wahl <32108944+dale-wahl@users.noreply.github.com> Date: Thu, 28 May 2026 15:00:01 +0000 Subject: [PATCH] chore: sync map_item for pinterest from 4CAT df7aea3edf225ba149af46556457dbfdee2704f1 --- modules/pinterest.js | 85 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/modules/pinterest.js b/modules/pinterest.js index 5f9abcc..ad30168 100644 --- a/modules/pinterest.js +++ b/modules/pinterest.js @@ -91,4 +91,87 @@ export function capture(response, source_platform_url, source_url) { } return pins; -} \ No newline at end of file +} + +// === auto-generated by 4cat map_item sync — BLOCK REPLACED AUTOMATICALLY === +// (regenerated from datasources/pinterest/search_pinterest.py) +export function map_item(post) { + if (post['_zs-origin'] === 'html') { + return map_item_from_html(post); + } else { + return map_item_from_json(post); + } +} + +function map_item_from_json(post) { + let timestamp, unix_timestamp, str_timestamp; + try { + timestamp = new Date(post['created_at'] ?? post['createdAt']); + unix_timestamp = Math.floor(timestamp.getTime() / 1000); + str_timestamp = timestamp.toISOString().replace('T', ' ').substring(0, 19); + } catch (e) { + unix_timestamp = str_timestamp = new MissingMappedField(''); + } + + const post_id = post['entityId'] ?? post['id']; + + let image_url; + if ('imageSpec_orig' in post) { + image_url = post['imageSpec_orig']['url']; + } else if ('orig' in post['images']) { + image_url = post['images']['orig']['url']; + } else { + image_url = post['images']['url']; + } + + return new MappedItem({ + 'collected_from_url': normalize_url_encoding(post['__import_meta']?.['source_platform_url'] ?? ''), + 'id': post_id, + 'thread_id': post_id, + 'author': post['pinner']['username'], + 'author_fullname': post['pinner']['fullName'] ?? post['pinner']['full_name'] ?? '', + 'author_original': post['nativeCreator'] ? post['nativeCreator']['username'] : post['pinner']['username'], + 'body': (post['description'] ?? '').trim(), + 'subject': post['title'].trim(), + 'ai_description': post['auto_alt_text'] ?? '', + 'pinner_original': post['originPinner'] ? post['originPinner']['fullName'] : '', + 'pinner_via': post['viaPinner'] ? post['viaPinner']['fullName'] : '', + 'board': post['board']['name'], + 'board_pins': post['board']['pinCount'] ?? post['board']['pin_count'] ?? new MissingMappedField(''), + 'board_url': `https://www.pinterest.com${post['board']['url']}`, + 'timestamp': str_timestamp, + 'idea_tags': (post['pinJoin'] ? post['pinJoin']['visualAnnotation'] : []).join(','), + 'url': `https://www.pinterest.com/pin/${post_id}`, + 'is_video': (post['isVideo'] ?? post['videos']) ? 'yes' : 'no', + 'image_url': image_url, + 'dominant_colour': post['dominantColor'] ?? post['dominant_color'] ?? new MissingMappedField(''), + 'unix_timestamp': unix_timestamp + }); +} + +function map_item_from_html(post) { + return new MappedItem({ + 'collected_from_url': normalize_url_encoding(post['__import_meta']?.['source_platform_url'] ?? ''), + 'id': parseInt(post['id']), + 'thread_id': parseInt(post['id']), + 'author': new MissingMappedField(''), + 'author_fullname': new MissingMappedField(''), + 'author_original': new MissingMappedField(''), + 'body': (post['body'] ?? '').trim(), + 'subject': (post['title'] ?? '').trim(), + 'ai_description': new MissingMappedField(''), + 'pinner_original': new MissingMappedField(''), + 'pinner_via': new MissingMappedField(''), + 'board': new MissingMappedField(''), + 'board_pins': new MissingMappedField(''), + 'board_url': new MissingMappedField(''), + 'timestamp': new MissingMappedField(''), + 'idea_tags': (post['tags'] ?? []).join(','), + 'url': `https://www.pinterest.com/pin/${post['id']}`, + 'is_video': new MissingMappedField(''), + 'image_url': post['image'], + 'dominant_colour': new MissingMappedField(''), + 'unix_timestamp': new MissingMappedField('') + }); +} +// === end auto-generated ===