Discuss Scratch

-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Hai!

I'd like to get my live follower count in a scratch project. The programming language which I want to use is “python” .. I don't know the code to do, make a server etc.. can I have help? I'll credit each and everyone who helps me

NOTE : I cannot use scratchclient

Last edited by -BlazingWind- (Nov. 8, 2021 06:36:55)

Chiroyce
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

-BlazingWind- wrote:

NOTE : I cannot use scratchclient
Why?
god286
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

I don't think the Scratch API returns the follower count so you either use ScratchDB (which is not live) or you make a bunch of HTTP requests to the Scratch API because I think every request = 20 followers returned
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Chiroyce wrote:

-BlazingWind- wrote:

NOTE : I cannot use scratchclient
Why?

pip install scratchclient
Defaulting to user installation because normal site-packages is not writeable
Collecting scratchclient
Using cached scratchclient-0.4.8.tar.gz (9.4 kB)
Preparing metadata (setup.py) … done
Requirement already satisfied: requests in c:\users\Username\appdata\roaming\python\python39\site-packages (from scratchclient) (2.26.0)
Requirement already satisfied: websocket-client in c:\users\Username\appdata\roaming\python\python39\site-packages (from scratchclient) (1.2.1)
Collecting numpy
Downloading numpy-1.21.4-cp39-cp39-win_amd64.whl (14.0 MB)
|████████████████████████████████| 14.0 MB 3.3 MB/s
Collecting wsaccel
Using cached wsaccel-0.6.3.tar.gz (215 kB)
Preparing metadata (setup.py) … done
Collecting pymitter
Using cached pymitter-0.3.1.tar.gz (6.2 kB)
Preparing metadata (setup.py) … done
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\Username\appdata\roaming\python\python39\site-packages (from requests->scratchclient) (1.26.7)
Requirement already satisfied: idna<4,>=2.5 in c:\users\Username\appdata\roaming\python\python39\site-packages (from requests->scratchclient) (3.2)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\Username\appdata\roaming\python\python39\site-packages (from requests->scratchclient) (2021.5.30)
Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\Username\appdata\roaming\python\python39\site-packages (from requests->scratchclient) (2.0.6)
Using legacy ‘setup.py install’ for scratchclient, since package ‘wheel’ is not installed.
Using legacy ‘setup.py install’ for pymitter, since package ‘wheel’ is not installed.
Using legacy ‘setup.py install’ for wsaccel, since package ‘wheel’ is not installed.
Installing collected packages: wsaccel, pymitter, numpy, scratchclient
Running setup.py install for wsaccel … error
ERROR: Command errored out with exit status 1:
command: ‘C:\Program Files\Python39\python.exe’ -u -c 'import io, os, sys, setuptools, tokenize; sys.argv = ‘“’”'C:\\Users\\Username\\AppData\\Local\\Temp\\pip-install-hht8wa01\\wsaccel_8e473a7ce1504ee3a89c0fe5176ca1fa\\setup.py'“'”'; __file__='“'”'C:\\Users\\Username\\AppData\\Local\\Temp\\pip-install-hht8wa01\\wsaccel_8e473a7ce1504ee3a89c0fe5176ca1fa\\setup.py'“'”';f = getattr(tokenize, ‘“’”'open'“'”', open)(__file__) if os.path.exists(__file__) else io.StringIO('“'”'from setuptools import setup; setup()'“'”');code = f.read().replace('“'”'\r\n'“'”', ‘“’”'\n'“'”');f.close();exec(compile(code, __file__, ‘“’”'exec'“'”'))' install –record ‘C:\Users\Username\AppData\Local\Temp\pip-record-lxlpwox1\install-record.txt’ –single-version-externally-managed –user –prefix= –compile –install-headers ‘C:\Users\Username\AppData\Roaming\Python\Python39\Include\wsaccel’
cwd: C:\Users\Username\AppData\Local\Temp\pip-install-hht8wa01\wsaccel_8e473a7ce1504ee3a89c0fe5176ca1fa\
Complete output (10 lines):
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.9
creating build\lib.win-amd64-3.9\wsaccel
copying wsaccel\__init__.py -> build\lib.win-amd64-3.9\wsaccel
running build_ext
building ‘wsaccel.utf8validator’ extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
—————————————-
ERROR: Command errored out with exit status 1: ‘C:\Program Files\Python39\python.exe’ -u -c 'import io, os, sys, setuptools, tokenize; sys.argv = ‘“’”'C:\\Users\\Username\\AppData\\Local\\Temp\\pip-install-hht8wa01\\wsaccel_8e473a7ce1504ee3a89c0fe5176ca1fa\\setup.py'“'”'; __file__='“'”'C:\\Users\\Username\\AppData\\Local\\Temp\\pip-install-hht8wa01\\wsaccel_8e473a7ce1504ee3a89c0fe5176ca1fa\\setup.py'“'”';f = getattr(tokenize, ‘“’”'open'“'”', open)(__file__) if os.path.exists(__file__) else io.StringIO('“'”'from setuptools import setup; setup()'“'”');code = f.read().replace('“'”'\r\n'“'”', ‘“’”'\n'“'”');f.close();exec(compile(code, __file__, ‘“’”'exec'“'”'))' install –record ‘C:\Users\Username\AppData\Local\Temp\pip-record-lxlpwox1\install-record.txt’ –single-version-externally-managed –user –prefix= –compile –install-headers ‘C:\Users\Username\AppData\Roaming\Python\Python39\Include\wsaccel’ Check the logs for full command output.



This error comes…
Verixion
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Chiroyce wrote:

-BlazingWind- wrote:

NOTE : I cannot use scratchclient
Why?
Maybe because of the Visual C++ Build Tools (wsaccel) or they just don't want to use it because of scratchconnect
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

god286 wrote:

I don't think the Scratch API returns the follower count so you either use ScratchDB (which is not live) or you make a bunch of HTTP requests to the Scratch API because I think every request = 20 followers returned


I'm not saying the use the Scratch API only.. I can go with anything!
Chiroyce
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

-BlazingWind- wrote:

error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
You need the following software installed on your computer - if that's there then you can easily fix this.
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Verixion wrote:

Chiroyce wrote:

-BlazingWind- wrote:

NOTE : I cannot use scratchclient
Why?
don't want to use it because of scratchconnect

It's because Of visual studio 14+ requirment
Verixion
Scratcher
100+ posts

Get my live follower count in a Scratch Project

god286 wrote:

I don't think the Scratch API returns the follower count so you either use ScratchDB (which is not live) or you make a bunch of HTTP requests to the Scratch API because I think every request = 20 followers returned
max limit is 40. scratch-api's follower count is incorrect so we webscrape and use regex to get follower count
Chiroyce
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

-BlazingWind- wrote:

It's because Of visual studio 14+ requirment
then download it and install it - if you can. just go here https://visualstudio.microsoft.com/visual-cpp-build-tools/ and click download - and run the exe file
god286
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

Verixion wrote:

god286 wrote:

I don't think the Scratch API returns the follower count so you either use ScratchDB (which is not live) or you make a bunch of HTTP requests to the Scratch API because I think every request = 20 followers returned
max limit is 40. scratch-api's follower count is incorrect so we webscrape and use regex to get follower count
wow…
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Chiroyce wrote:

-BlazingWind- wrote:

It's because Of visual studio 14+ requirment
then download it and install it - if you can. just go here https://visualstudio.microsoft.com/visual-cpp-build-tools/ and click download - and run the exe file


Wait a sec…

Downloaded the .exe (success)

Running it now!
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project



What all should I select?
Chiroyce
Scratcher
1000+ posts

Get my live follower count in a Scratch Project

-BlazingWind- wrote:

What all should I select?
I think only the first one is required, since it says Visual C++ v14.0 or higher - just make sure to check with someone else …
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Hey!


Done! Installed visual studio 14+ and also successfully installed scratchclient!
Verixion
Scratcher
100+ posts

Get my live follower count in a Scratch Project

code: read the comments before running and replace needed strings
import requests
import re
from scratchclient import ScratchSession
import time
def get_follower_count(username) -> int:
    follower_req = requests.get(f"https://scratch.mit.edu/users/{username}/followers", headers={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0" # set user-agent or scratch sadly wont accept our request
    })
    follower_count = int(re.search(r'Followers \((\d+)\)', follower_req.text)[1])
    return follower_count
session = ScratchSession("<USERNAME>", "<PASSWORD>") # replace <USERNAME> and <PASSWORD> with an alt account's actual username and password (probably using env vars)
cloud_connection = session.create_cloud_connection(1) # replace 1 with target project id
while True:
    cloud_connection.set_cloud_variable("message count", get_follower_count("-BlazingWind-")) # set the cloud variable "message count" to the follower count of "-BlazingWind-".
    time.sleep(5) # every 5 seconds follower count updates
-BlazingWind-
Scratcher
100+ posts

Get my live follower count in a Scratch Project

Verixion wrote:

code: read the comments before running and replace needed strings
import requests
import re
from scratchclient import ScratchSession
import time
def get_follower_count(username) -> int:
    follower_req = requests.get(f"https://scratch.mit.edu/users/{username}/followers", headers={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0" # set user-agent or scratch sadly wont accept our request
    })
    follower_count = int(re.search(r'Followers \((\d+)\)', follower_req.text)[1])
    return follower_count
session = ScratchSession("<USERNAME>", "<PASSWORD>") # replace <USERNAME> and <PASSWORD> with an alt account's actual username and password (probably using env vars)
cloud_connection = session.create_cloud_connection(1) # replace 1 with target project id
while True:
    cloud_connection.set_cloud_variable("message count", get_follower_count("-BlazingWind-")) # set the cloud variable "message count" to the follower count of "-BlazingWind-".
    time.sleep(5) # every 5 seconds follower count updates


Cool!

Now able to make the project and it's working!

Thank you so much! I'll credit @Chiroyce and @verixion in the credits once I share it!
Sid72020123
Scratcher
500+ posts

Get my live follower count in a Scratch Project

Verixion wrote:

Chiroyce wrote:

-BlazingWind- wrote:

NOTE : I cannot use scratchclient
Why?
Maybe because of the Visual C++ Build Tools (wsaccel) or they just don't want to use it because of scratchconnect
No scratchconnect doesn't use wsaccel! It uses websocket-client!

Powered by DjangoBB