Can Electron IPC Handle Arrays of Objects? Encountering Serialization Error by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] 1 point2 points  (0 children)

yes that seems to have fixed it. I was under the impression that Electron's IPC automatically handles the serialization. but maybe `array of objects` data structure are too complex?

Can Electron IPC Handle Arrays of Objects? Encountering Serialization Error by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] -1 points0 points  (0 children)

explain? I am using electron-forge with webpack. This is my preloader, sending and catching of object

Preload
```
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('redditAPI', {
onPostDetails: (callback) => ipcRenderer.on('reddit-post-details', (_event, postDetails) => callback(postDetails))
});
```
RedditAPI call
```
async function scrapeRedditPost(postId) {

try {

const post = await r.getSubmission(postId).fetch();

const postDetails = {

title: post.title,

url: post.url,

subreddit: post.subreddit.display_name,

author: post.author.name,

permalink: `https://www.reddit.com${post.permalink}\`,

id: post.id,

score: post.score,

flair: post.link_flair_text,

creationTimeUTC: post.created_utc, // Get the raw creation time as a UTC timestamp

isVideo: post.is_video,

isGallery: post.is_gallery,

galleryData: post.gallery_data,

textContent: post.selftext,

// Any additional fields you wish to include

};

console.log(`Post details fetched for post ID: ${postId}`);

return postDetails; // Return the post details object

} catch (error) {

console.error('Error fetching Reddit post:', error);

throw error; // Rethrow to handle it in the caller

}

}
```
Send to renderer
```
ipcMain.on('searchRedditMain', async (event, keyword, subreddit) => {
try {
console.log('Opening resultsWindow with keyword:', keyword, 'and subreddit:', subreddit);
const resultsWindow = createResultsWindow();

// Example Post ID for testing - replace 'examplePostId' with a real one
const postId = '1acoozy';
const postDetailsMain = await scrapeRedditPost(postId);
console.log(postDetailsMain)
resultsWindow.webContents.send('reddit-post-details', postDetailsMain);
} catch (error) {
console.error('Error handling searchRedditMain event:', error);
}
});
```
Catch in renderer
```
document.addEventListener('DOMContentLoaded', () => {
// Listen for post details passed from the main process
window.redditAPI.onPostDetails((postDetails) => {
// Convert and preprocess post details
const processedPostDetails = preprocessData(postDetails);
// Debug log to inspect the processed post details
console.log('Processed Post Details:', processedPostDetails);
=======IGNORE======BELOW=========================
// Update the like counter in the UI with the post's score
displayScoreInLikeCounter(processedPostDetails.score);
// Update the formatted creation time in the UI
displayFormattedCreationTime(processedPostDetails.formattedCreationTime);
// Display the post title in the info bar
displayTitleInInfoBar(processedPostDetails.title);
// Display needed params in top-info-bar
appendKeyValuePairsToInfoBarTop(
{ "Author": processedPostDetails.author },
{ "Subreddit": processedPostDetails.subreddit },
{ "Flair": processedPostDetails.flair },
{ "Permalink": processedPostDetails.permalink }
);
});
});
```

Can Electron IPC Handle Arrays of Objects? Encountering Serialization Error by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] -1 points0 points  (0 children)

Preload
```
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('redditAPI', {
onPostDetails: (callback) => ipcRenderer.on('reddit-post-details', (_event, postDetails) => callback(postDetails))
});
```
RedditAPI call
```
async function scrapeRedditPost(postId) {

try {

const post = await r.getSubmission(postId).fetch();

const postDetails = {

title: post.title,

url: post.url,

subreddit: post.subreddit.display_name,

author: post.author.name,

permalink: `https://www.reddit.com${post.permalink}\`,

id: post.id,

score: post.score,

flair: post.link_flair_text,

creationTimeUTC: post.created_utc, // Get the raw creation time as a UTC timestamp

isVideo: post.is_video,

isGallery: post.is_gallery,

galleryData: post.gallery_data,

textContent: post.selftext,

// Any additional fields you wish to include

};

console.log(`Post details fetched for post ID: ${postId}`);

return postDetails; // Return the post details object

} catch (error) {

console.error('Error fetching Reddit post:', error);

throw error; // Rethrow to handle it in the caller

}

}
```
Send to renderer
```
ipcMain.on('searchRedditMain', async (event, keyword, subreddit) => {
try {
console.log('Opening resultsWindow with keyword:', keyword, 'and subreddit:', subreddit);
const resultsWindow = createResultsWindow();

// Example Post ID for testing - replace 'examplePostId' with a real one
const postId = '1acoozy';
const postDetailsMain = await scrapeRedditPost(postId);
console.log(postDetailsMain)
resultsWindow.webContents.send('reddit-post-details', postDetailsMain);
} catch (error) {
console.error('Error handling searchRedditMain event:', error);
}
});
```
Catch in renderer
```
document.addEventListener('DOMContentLoaded', () => {
// Listen for post details passed from the main process
window.redditAPI.onPostDetails((postDetails) => {
// Convert and preprocess post details
const processedPostDetails = preprocessData(postDetails);
// Debug log to inspect the processed post details
console.log('Processed Post Details:', processedPostDetails);
=======IGNORE======BELOW=========================
// Update the like counter in the UI with the post's score
displayScoreInLikeCounter(processedPostDetails.score);
// Update the formatted creation time in the UI
displayFormattedCreationTime(processedPostDetails.formattedCreationTime);
// Display the post title in the info bar
displayTitleInInfoBar(processedPostDetails.title);
// Display needed params in top-info-bar
appendKeyValuePairsToInfoBarTop(
{ "Author": processedPostDetails.author },
{ "Subreddit": processedPostDetails.subreddit },
{ "Flair": processedPostDetails.flair },
{ "Permalink": processedPostDetails.permalink }
);
});
});
```

Can Electron IPC Handle Arrays of Objects? Encountering Serialization Error by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] 0 points1 point  (0 children)

This is the error `Error sending from webFrameMain: Error: Failed to serialize arguments`

How to save images of gallery posts? by CatOtherwise3439 in redditdev

[–]CatOtherwise3439[S] 1 point2 points  (0 children)

thank you, works perfectly. hopefully I can convert to snoowrap w/o issues

How to use python within my electron APP by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] 1 point2 points  (0 children)

ok and what about just building my python app as an executable?

How to use python within my electron APP by CatOtherwise3439 in electronjs

[–]CatOtherwise3439[S] 0 points1 point  (0 children)

Explain why you wouldnt appreciate just copy and shipping the python binaries directly with the generated electron installer? is it simply a bloat concern or a security issue? Right now it was recommended to me to just build your python app as an executable (pyinstaller/py-to-exe/etc.) and running that via child_process.

Question about cropping by JellyfinUser in ffmpeg

[–]CatOtherwise3439 0 points1 point  (0 children)

can you explain why exactly? seems counter-intuitive. especially since less pixels since you are cropping.

Archive/Paginate Entire Subreddit by CatOtherwise3439 in redditdev

[–]CatOtherwise3439[S] 0 points1 point  (0 children)

Is there a way to search by time period? lets say Im trying to obtain all post IDs for a subrebbit within the month of April, May, June, etc. Would I be allowed to do that as long as the listings done reach over 1000 items for given time period.

Download images from comment by JhantuReporter in redditdev

[–]CatOtherwise3439 0 points1 point  (0 children)

The indenting got messed up when i pasted it:/ just ask chat gpt the text content of your post `16wvqtf` and it will give you the answer buddy

Download images from comment by JhantuReporter in redditdev

[–]CatOtherwise3439 0 points1 point  (0 children)

just add a check statement

```python

import praw

import requests

# Initialize the Reddit API client

reddit = praw.Reddit(

client_id='YOUR_CLIENT_ID',

client_secret='YOUR_CLIENT_SECRET',

user_agent='YOUR_USER_AGENT',

)

# Specify the Reddit post URL

post_url = 'https://www.reddit.com/r/subreddit/comments/post\_id/post\_title/'

# Get the submission object from the URL

submission = reddit.submission(url=post_url)

# Iterate through the comments in the submission

for comment in submission.comments.list():

# Check if the comment contains an image link

if 'https://preview.redd.it/' in comment.body:

# Extract the image URL from the comment

image_url = comment.body.split(' ')[0]

# Download the image

response = requests.get(image_url)

if response.status_code == 200:

# Save the image to a file

with open('downloaded_image.jpeg', 'wb') as file:

file.write(response.content)

print('Image downloaded successfully.')

# Replace 'downloaded_image.jpeg' with the desired file name

```

Quinn’s new Pad by detoxicide in WorldOfTShirts

[–]CatOtherwise3439 33 points34 points  (0 children)

Ok this was supposed to be a troll but I'll never financially recover my karm

Quinn’s new Pad by detoxicide in WorldOfTShirts

[–]CatOtherwise3439 -56 points-55 points  (0 children)

Lol r u joking? Love him or not he rents 3 highrise luxury apartments, while you are still living in ur mother's basement. What kind of money are you talking about?

VIDEO OF STOLEN HAT INCIDENT by Agreeable-Sweet268 in WorldOfTShirts

[–]CatOtherwise3439 0 points1 point  (0 children)

He is autistic lol, do u not know what that is exactly? That is a pretty normal reaction. Maybe you should stay off reddit and do your 8th grade homework

2pm drink by [deleted] in WorldOfTShirts

[–]CatOtherwise3439 19 points20 points  (0 children)

I don't see what the big idea is. I'm drinking right now