Discuss Scratch

CKCG
Scratcher
100+ posts

Scratch API for signatures

So I've had an idea… (I'm not sure if this has already been asked, but tell me if it has.)
Why not have an API to set your signature to your latest projects? Or, all the other information the Scratch API provides?
I think I understand how APIs work but I'm not sure how we would put it into a signature or others things on Scratch.
Any ideas for how we could do this or other things this would be useful for?

Why not just update your signature when you post new stuff?
simply, because i'm lazy

Last edited by CKCG (Dec. 9, 2018 21:09:36)


I'm no longer active on these forums.
_nix
Scratcher
1000+ posts

Scratch API for signatures

Changing your signature via the API isn't too complicated if I recall correctly - it's just a simple POST request to https://scratch.mit.edu/discuss/settings/<username>. Take a look at your browser network log when you click the “submit” button on the change signature page; that's what you want to replicate.

I've got experience writing programs to interact with the Scratch API (both receiving and sending data) so I can give you pointers if you'd like'em.

For this particular kind of project, you'll want to poll the Scratch API for whatever data you want to reflect in your signature. That means you send an HTTP request getting the data on a regular period, like every ten minutes or so. That way you can make your signature automatically update to show the new projects (or whatever data) at a constant basis. (For the APIs of some other sites, you would listen for events; that is, you'd wait for the API server itself to tell you when things happen. But Scratch doesn't have an API like that, so you have to make use of polling instead.)

Last edited by _nix (Dec. 9, 2018 21:41:37)


══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
CKCG
Scratcher
100+ posts

Scratch API for signatures

Thanks for the help and quick response! Pointers please! I'm very new with the idea of APIs. Let me get on my not-school-computer so I can check out the browser log.

Last edited by CKCG (Dec. 9, 2018 21:45:52)


I'm no longer active on these forums.
_nix
Scratcher
1000+ posts

Scratch API for signatures

CKCG wrote:

Thanks for the help and quick response! Pointers please! I'm very new with the idea of APIs. Let me get on my not-school-computer so I can check out the browser log.
No problem! And sure. The first thing I recommend you do is play around with the API to see what kinds of data you can get. So for example, go to https://api.scratch.mit.edu/users/CKCG in your web browser and see what data you get. I've written a really big list of all the URLs on the API (these are actually called “endpoints”, that is, URLs you can go to to get data) right here; exploring that will probably help you come up with ideas for what you want to generate in your signature.

The next step will be setting up a development environment where you can work with the Scratch API. That basically means making a folder on your computer containing the actual code that will update your signature, and having a terminal open so that you can work with that. Do you have experience with JavaScript or Python? Have you worked with a terminal before? (That means cmd.exe on a Windows computer and the “Terminal” app on a Mac.) Just asking these so we're on the same picture - knowing this stuff will really help me help you

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
_nix
Scratcher
1000+ posts

Scratch API for signatures

CKCG wrote:

Why not just update your signature when you post new stuff?
simply, because i'm lazy
Oh PS - this is totally something I say a lot of the time. Why write a program when I could just do it by hand? Well, because I'm too lazy to do it by hand – but also because writing a program to do it for me is fun!

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
CKCG
Scratcher
100+ posts

Scratch API for signatures

I'm sorry I have to go now, but I'll be able to talk later. I have experience with opening terminals (lol) and with python.

I'm no longer active on these forums.
CKCG
Scratcher
100+ posts

Scratch API for signatures

_nix wrote:

CKCG wrote:

Why not just update your signature when you post new stuff?
simply, because i'm lazy
– but also because writing a program to do it for me is fun!
Lol and homework procrastination

I'm no longer active on these forums.
_nix
Scratcher
1000+ posts

Scratch API for signatures

CKCG wrote:

I'm sorry I have to go now, but I'll be able to talk later. I have experience with opening terminals (lol) and with python.
Alright, cool! So you'll probably want to use the Requests library. Here's, for example, some code that prints the name of the five most recently featured projects:
import requests
r = requests.get('https://api.scratch.mit.edu/proxy/featured')
data = r.json()
for project in data['community_featured_projects'][0:5]:
    print('%s - https://scratch.mit.edu/projects/%s' % (project['title'], project['id']))

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
CKCG
Scratcher
100+ posts

Scratch API for signatures

Very sorry for being inactive but it's been busy with the holidays and exam week. I should be able to start doing more things with this idea next week. Thanks for your help so far!

I'm no longer active on these forums.
_nix
Scratcher
1000+ posts

Scratch API for signatures

CKCG wrote:

Very sorry for being inactive but it's been busy with the holidays and exam week. I should be able to start doing more things with this idea next week. Thanks for your help so far!
No problem! Glad to help. And happy holidays!

══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they
sparrows one word to the paragraph // <3 // ~(quasar) nebula
apple502j
Scratcher
1000+ posts

Scratch API for signatures

_nix wrote:

CKCG wrote:

I'm sorry I have to go now, but I'll be able to talk later. I have experience with opening terminals (lol) and with python.
Alright, cool! So you'll probably want to use the Requests library. Here's, for example, some code that prints the name of the five most recently featured projects:
import requests
r = requests.get('https://api.scratch.mit.edu/proxy/featured')
data = r.json()
for project in data['community_featured_projects'][0:5]:
    print('%s - https://scratch.mit.edu/projects/%s' % (project['title'], project['id']))
this is better let's use my ibrary
import scratchapi2
for project in list(scratchapi2.FrontPage().featured_projects())[0:5]:
    print("{0} - {1}".format(project.title, project.url))

署名は、ディスカッションフォーラムの機能である。署名は、その人のすべての投稿の下部に追加される。署名は、BBCodeで記述できる。 署名を追加/変更/削除したい場合は、ディスカッションフォーラムのホームの一番下に行き、「Change your signature」を押す。署名の大きさは150pxまでである。これには、改行、画像を含む。- Japanese Scratch-Wiki 「署名
CKCG
Scratcher
100+ posts

Scratch API for signatures

apple502j wrote:

_nix wrote:

CKCG wrote:

I'm sorry I have to go now, but I'll be able to talk later. I have experience with opening terminals (lol) and with python.
Alright, cool! So you'll probably want to use the Requests library. Here's, for example, some code that prints the name of the five most recently featured projects:
import requests
r = requests.get('https://api.scratch.mit.edu/proxy/featured')
data = r.json()
for project in data['community_featured_projects'][0:5]:
    print('%s - https://scratch.mit.edu/projects/%s' % (project['title'], project['id']))
this is better let's use my ibrary
import scratchapi2
for project in list(scratchapi2.FrontPage().featured_projects())[0:5]:
    print("{0} - {1}".format(project.title, project.url))
Thanks, I'll check that out

I'm no longer active on these forums.

Powered by DjangoBB