Discuss Scratch

ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

Is it possible to

1. Find the number of followers I have with the API
2. Find the number of projects I share

thanks

Last edited by ninjagolloyd (July 21, 2017 17:32:53)


bean
Wettining
Scratcher
500+ posts

A few questions about the scratch apis

ninjagolloyd wrote:

Is it possible to

1. Find the number of followers I have with the API
2. Find the number of projects I share

thanks
I know you can get a list of followers (I don't know the url for it though) but I'm not sure about the number of projects shared.
Wettining
Scratcher
500+ posts

A few questions about the scratch apis

ninjagolloyd wrote:

Is it possible to

1. Find the number of followers I have with the API
2. Find the number of projects I share

thanks
I found out how to do both…
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has

Last edited by Wettining (July 21, 2017 22:14:20)

Mrcomputer1
Scratcher
500+ posts

A few questions about the scratch apis

Wettining wrote:

ninjagolloyd wrote:

Is it possible to

1. Find the number of followers I have with the API
2. Find the number of projects I share

thanks
I found out how to do both…
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has
Both of those are limited to showing 20 projects/followers at a time.

A solution to that problem would be:
* Use Wettining's method to get part of the project/follower count
* Add ?offset=20 to the URL and repeat Wettining's method (add the number to the project/follower count)
* Increase the offset by 20 until an empty array [] is returned and now the project/follower count will be correct.

My Profile / My User Page / My Talk Page
——————–
Progress bar to 1000+ Posts - Image might not be up to date

——————–
My browser / operating system: Windows NT 10.0 (Windows 11 - 22H2), Firefox 122.0b4
——————–
My ScratchX Extensions——–If you like this post, give me an internet!——–Sharp Scratch Mod
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

Mrcomputer1 wrote:

Wettining wrote:

ninjagolloyd wrote:

Is it possible to

1. Find the number of followers I have with the API
2. Find the number of projects I share

thanks
I found out how to do both…
If you go to https://api.scratch.mit.edu/users/(username)/projects and count the ammount of times “id” is said, then you get the ammount of shared projects they have and if you go to https://api.scratch.mit.edu/users/(username)/followers and do the same thing you get the ammount of followers the user has
Both of those are limited to showing 20 projects/followers at a time.

A solution to that problem would be:
* Use Wettining's method to get part of the project/follower count
* Add ?offset=20 to the URL and repeat Wettining's method (add the number to the project/follower count)
* Increase the offset by 20 until an empty array [] is returned and now the project/follower count will be correct.
ok

bean
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

wait could I add the objects to an array then count the objects?

bean
nathanprocks
Scratcher
1000+ posts

A few questions about the scratch apis

The best way that I know of is to just scrape the projects/followers page. Using the API would take a really long time (and hundreds of requests) for some users' follower counts, e.g. griffpatch.
If you want to use the API, something like this should work:
var username = "griffpatch";
var count = 0;
function getProjectCount() {
    var req = new XMLHttpRequest();
    req.addEventListener("load", (e) => {
        let c = JSON.parse(e.target.responseText).length;
        if (c > 0) {
            count += c;
            setTimeout(getProjectCount, 250);
            console.log(count);
        }
    });
    req.open("GET", `https://api.scratch.mit.edu/users/${username}/projects?offset=${count}`);
    req.send();
}
getProjectCount();


My browser / operating system: Macrosoft Winding XO, Internet Exploder 6.0, Angel Player ver.:1.2.5
;
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

nathanprocks wrote:

The best way that I know of is to just scrape the projects/followers page. Using the API would take a really long time (and hundreds of requests) for some users' follower counts, e.g. griffpatch.
If you want to use the API, something like this should work:
var username = "griffpatch";
var count = 0;
function getProjectCount() {
    var req = new XMLHttpRequest();
    req.addEventListener("load", (e) => {
        let c = JSON.parse(e.target.responseText).length;
        if (c > 0) {
            count += c;
            setTimeout(getProjectCount, 250);
            console.log(count);
        }
    });
    req.open("GET", `https://api.scratch.mit.edu/users/${username}/projects?offset=${count}`);
    req.send();
}
getProjectCount();

true, thanks

btw did you mean to use backticks?

bean
nathanprocks
Scratcher
1000+ posts

A few questions about the scratch apis

ninjagolloyd wrote:

true, thanks

btw did you mean to use backticks?
Yes. It's called a template literal. It allows you to include expressions in strings, so instead of doing this:
let name = "Nathan";
let number = 42;
console.log("My name is " + name + ". My favourite number is " + number + ".");
You can use a template literal like this:
let name = "Nathan";
let number = 42;
console.log(`My name is ${name}. My favourite number is ${number}.`);

Last edited by nathanprocks (July 22, 2017 16:59:24)



My browser / operating system: Macrosoft Winding XO, Internet Exploder 6.0, Angel Player ver.:1.2.5
;
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

nathanprocks wrote:

ninjagolloyd wrote:

true, thanks

btw did you mean to use backticks?
Yes. It's called a template literal. It allows you to include expressions in strings, so instead of doing this:
let name = "Nathan";
let number = 42;
console.log("My name is " + name + ". My favourite number is " + number + ".");
You can use a template literal like this:
let name = "Nathan";
let number = 42;
console.log(`My name is ${name}. My favourite number is ${number}.`);
oo kewl thanks

bean
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this

Last edited by ninjagolloyd (July 22, 2017 17:10:18)


bean
nathanprocks
Scratcher
1000+ posts

A few questions about the scratch apis

ninjagolloyd wrote:

would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
It would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that.


My browser / operating system: Macrosoft Winding XO, Internet Exploder 6.0, Angel Player ver.:1.2.5
;
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

nathanprocks wrote:

ninjagolloyd wrote:

would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
It would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that.
ok

bean
Wettining
Scratcher
500+ posts

A few questions about the scratch apis

ninjagolloyd wrote:

nathanprocks wrote:

ninjagolloyd wrote:

would a jquery ajax thingy be any faster/more efficient? you can see i dont do much of this
It would be less efficient to load an entire bloated library just to use AJAX. If you want compatibility with older browsers and IE, there are better libraries for that.
ok
It would be best to just order out what you wanted to be loaded first, second, third, etc. instead of lazy-loading the entire page
TheUltimatum
Scratcher
1000+ posts

A few questions about the scratch apis

Best way to do any of this I've found so far is. BeautifulSoup.
__init__
Scratcher
1000+ posts

A few questions about the scratch apis

TheUltimatum wrote:

Best way to do any of this I've found so far is. BeautifulSoup.
+1. If there isn't an easy way to do something with an API, I use BeautifulSoup.

thisandagain pls explain
ninjagolloyd
Scratcher
500+ posts

A few questions about the scratch apis

__init__ wrote:

TheUltimatum wrote:

Best way to do any of this I've found so far is. BeautifulSoup.
+1. If there isn't an easy way to do something with an API, I use BeautifulSoup.
ohh yeahhhhhhhhh

but there is a way so

bean

Powered by DjangoBB