Discuss Scratch

frodewin
Scratcher
500+ posts

Get all messages of a Scratch user at once

Anybody knows a way to get all messages https://scratch.mit.edu/messages/ of the currently logged in user at once?
ChocolatePi
Scratcher
1000+ posts

Get all messages of a Scratch user at once

not that i know of!

can't you just paginate?
Icely
Scratcher
100+ posts

Get all messages of a Scratch user at once

frodewin wrote:

Anybody knows a way to get all messages https://scratch.mit.edu/messages/ of the currently logged in user at once?
Use GET, and parse the HTML, and return an array. Yep. I'm helpful.

Last edited by Icely (Dec. 30, 2015 13:17:05)

Smitop
Scratcher
100+ posts

Get all messages of a Scratch user at once

Here's some code for getting a page #:
(page nums start a 0, and go up for each extra page)
If a page exists, then you get a array of messages (passed to the callback)
If a page doesn't exist, then you get 0 (passed to the callback)
First parameter: page #
Second parameter: callback
function getPageNum(page, callback) {
    console.log("getting page # " + page);
    $.ajax({
            url: "https://scratch.mit.edu/messages/" + page + "/"
        }).done(function(data) {
            var callbackData = [];
            var dataExists = false;
            $(data).find("#notification-list li").not(".template").each(function(index) {
                dataExists = true;
                callbackData[index] = $.trim($(this).text().replace(/\s+/g, " "));
            });
            if (!dataExists) {
                callback(0);
            }
            callback(callbackData);
        });
}
NickyNouse
Scratcher
1000+ posts

Get all messages of a Scratch user at once

frodewin wrote:

Anybody knows a way to get all messages https://scratch.mit.edu/messages/ of the currently logged in user at once?
Right now you just have to parse the messages page, but they're about to overhaul the site and the messages page might be different when they're done. Also, I think someone found a messages API that isn't active yet.
frodewin
Scratcher
500+ posts

Get all messages of a Scratch user at once

Smitop wrote:

Here's some code for getting a page #:

Hi Smitop,

Thanks a lot for your function.
I tried it in the following html:

<html>
<head>
<script type="text/javascript" src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>

function getPageNum(page, callback) {
console.log("getting page # " + page);
$.ajax({
url: "https://scratch.mit.edu/messages/" + page + "/"
}).done(function(data) {
var callbackData = [];
var dataExists = false;
$(data).find("#notification-list li").not(".template").each(function(index) {
dataExists = true;
callbackData[index] = $.trim($(this).text().replace(/\s+/g, " "));
});
if (!dataExists) {
callback(0);
}
callback(callbackData);
});
}

function writeData(myData) {
document.getElementById('output').innerHTML += myData;
}

getPageNum(1,writeData);

</script>
</head>
<body>
<p id="output"></p>
</body>
</html>

(For testing reason, this should only load the page with number 1)

However, it only prints a “0” indicating no data, do you spot my mistake(s)?
NickyNouse
Scratcher
1000+ posts

Get all messages of a Scratch user at once

frodewin wrote:

Smitop wrote:

Here's some code for getting a page #:

Hi Smitop,

Thanks a lot for your function.
I tried it in the following html:

<html>
<head>
<script type="text/javascript" src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>

function getPageNum(page, callback) {
console.log("getting page # " + page);
$.ajax({
url: "https://scratch.mit.edu/messages/" + page + "/"
}).done(function(data) {
var callbackData = [];
var dataExists = false;
$(data).find("#notification-list li").not(".template").each(function(index) {
dataExists = true;
callbackData[index] = $.trim($(this).text().replace(/\s+/g, " "));
});
if (!dataExists) {
callback(0);
}
callback(callbackData);
});
}

function writeData(myData) {
document.getElementById('output').innerHTML += myData;
}

getPageNum(1,writeData);

</script>
</head>
<body>
<p id="output"></p>
</body>
</html>

(For testing reason, this should only load the page with number 1)

However, it only prints a “0” indicating no data, do you spot my mistake(s)?
Sometimes if you give jQuery a whole page it won't return anything. Try playing around with some stuff like this:
$(data).find('#content')
$(data).first()
$(data).children().eq(1)
Smitop
Scratcher
100+ posts

Get all messages of a Scratch user at once

frodewin wrote:

Smitop wrote:

Here's some code for getting a page #:

Hi Smitop,

Thanks a lot for your function.
I tried it in the following html:

<html>
<head>
<script type="text/javascript" src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>

function getPageNum(page, callback) {
console.log("getting page # " + page);
$.ajax({
url: "https://scratch.mit.edu/messages/" + page + "/"
}).done(function(data) {
var callbackData = [];
var dataExists = false;
$(data).find("#notification-list li").not(".template").each(function(index) {
dataExists = true;
callbackData[index] = $.trim($(this).text().replace(/\s+/g, " "));
});
if (!dataExists) {
callback(0);
}
callback(callbackData);
});
}

function writeData(myData) {
document.getElementById('output').innerHTML += myData;
}

getPageNum(1,writeData);

</script>
</head>
<body>
<p id="output"></p>
</body>
</html>

(For testing reason, this should only load the page with number 1)

However, it only prints a “0” indicating no data, do you spot my mistake(s)?
It appears that (for me) Scratch is redirecting from the messages page, to a logon page, so Scratch must not be giving the messages page, because the request isn't coming from a Scratch page. Try running the script, from the console, when you're on a Scratch page.
DrKat123
Scratcher
1000+ posts

Get all messages of a Scratch user at once

Smitop wrote:

frodewin wrote:

Smitop wrote:

Here's some code for getting a page #:

Hi Smitop,

Thanks a lot for your function.
I tried it in the following html:

<html>
<head>
<script type="text/javascript" src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>

function getPageNum(page, callback) {
console.log("getting page # " + page);
$.ajax({
url: "https://scratch.mit.edu/messages/" + page + "/"
}).done(function(data) {
var callbackData = [];
var dataExists = false;
$(data).find("#notification-list li").not(".template").each(function(index) {
dataExists = true;
callbackData[index] = $.trim($(this).text().replace(/\s+/g, " "));
});
if (!dataExists) {
callback(0);
}
callback(callbackData);
});
}

function writeData(myData) {
document.getElementById('output').innerHTML += myData;
}

getPageNum(1,writeData);

</script>
</head>
<body>
<p id="output"></p>
</body>
</html>

(For testing reason, this should only load the page with number 1)

However, it only prints a “0” indicating no data, do you spot my mistake(s)?
It appears that (for me) Scratch is redirecting from the messages page, to a logon page, so Scratch must not be giving the messages page, because the request isn't coming from a Scratch page. Try running the script, from the console, when you're on a Scratch page.
I tried, and it gives me:
//Le Firefox Console
undefined
getting page # 10
TypeError: callback is not a function
getPageNum/<()
debugger eval code:15
m.Callbacks/j()
jquery.min.js:2
m.Callbacks/k.fireWith()
jquery.min.js:2
x()
jquery.min.js:4
.send/b()
jquery.min.js:4
frodewin
Scratcher
500+ posts

Get all messages of a Scratch user at once

I'll pulling this out of its grave, because it is still a relevant unsolved problem.

Anybody has an idea for a working script that creates a list of all notifications?
NickyNouse
Scratcher
1000+ posts

Get all messages of a Scratch user at once

frodewin wrote:

I'll pulling this out of its grave, because it is still a relevant unsolved problem.

Anybody has an idea for a working script that creates a list of all notifications?
Something like smitop's answer should still work, but in order to not get a login page or something you might need to attach a cookie or csrftoken.
frodewin
Scratcher
500+ posts

Get all messages of a Scratch user at once

Doesn't seem to work for me.

What I tried:
1. Login to Scratch
2. Exporting my cookies
3. Accessing scratch with wget –load-cookies cookies.txt https://scratch.mit.edu/messages

But I got the non-logged-in version of the webpage.
nathanprocks
Scratcher
1000+ posts

Get all messages of a Scratch user at once

In Chrome Dev Tools (haven't tested in other browsers), go to the Network tab and refresh the messages page, right click messages/, then Copy > Copy as cURL. This works for me.
Eon713
Scratcher
12 posts

Get all messages of a Scratch user at once

whenclickedswitchcostumetoEon713sayplz reply to this message to show how to get lots of messages I wont check in a month I will count the days Bye!
wvj
Scratcher
1000+ posts

Get all messages of a Scratch user at once

Eon713 wrote:

snip
Please don't post on an old topic without saying anything constructive
SuperClowny
Scratcher
1 post

Get all messages of a Scratch user at once

Hi
WojtekGame
Scratcher
1000+ posts

Get all messages of a Scratch user at once

SuperClowny wrote:

Hi
Hey, no necroposin'!
cosmosaura
Scratch Team
1000+ posts

Get all messages of a Scratch user at once

Closed to stop future necroposts.

Powered by DjangoBB