Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Get all messages of a Scratch user at once
- frodewin
-
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
-
1000+ posts
Get all messages of a Scratch user at once
not that i know of!
can't you just paginate?
can't you just paginate?
- Icely
-
100+ posts
Get all messages of a Scratch user at once
https://scratch.mit.edu/messages/ of the currently logged in user at once?Use GET, and parse the HTML, and return an array. Anybody knows a way to get all messages Yep. I'm helpful.
Last edited by Icely (Dec. 30, 2015 13:17:05)
- Smitop
-
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
(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
-
1000+ posts
Get all messages of a Scratch user at once
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. Anybody knows a way to get all messages
- frodewin
-
500+ posts
Get all messages of a Scratch user at once
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
-
1000+ posts
Get all messages of a Scratch user at once
Sometimes if you give jQuery a whole page it won't return anything. Try playing around with some stuff like this: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)?
$(data).find('#content')
$(data).first()
$(data).children().eq(1)
- Smitop
-
100+ posts
Get all messages of a Scratch user at once
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.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)?
- DrKat123
-
1000+ posts
Get all messages of a Scratch user at once
I tried, and it gives me: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.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)?
//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
-
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?
Anybody has an idea for a working script that creates a list of all notifications?
- NickyNouse
-
1000+ posts
Get all messages of a Scratch user at once
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. 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?
- frodewin
-
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.
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
-
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.
- wvj
-
1000+ posts
Get all messages of a Scratch user at once
Please don't post on an old topic without saying anything constructive snip
- cosmosaura
-
1000+ posts
Get all messages of a Scratch user at once
Closed to stop future necroposts.
- Discussion Forums
- » Advanced Topics
-
» Get all messages of a Scratch user at once