Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion modules/pinterest.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,87 @@ export function capture(response, source_platform_url, source_url) {
}

return pins;
}
}

// === 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 ===