Discuss Scratch

Dagriffpatchfan
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

MineTurte wrote:

Dagriffpatchfan wrote:

I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah.
With crontab, how long does the script run? If I have a forever loop will it run for at least one minute? Every time it is automatically run?
MonkeyBean2
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

MineTurte wrote:

Dagriffpatchfan wrote:

I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah.
Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:
screen -dmS <name> <command>
eg.
screen -dmS scratchserver0 python3 main.py
and then to exit it or view its output you can do
screen -r <name>
and if you forgot the name you used you can use
screen -ls
to list all running screen sessions. Once you have gotten back into it with screen -r you can do ctrl+d to stop it.

Last edited by MonkeyBean2 (Nov. 29, 2024 17:38:11)

MonkeyBean2
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

wvzack wrote:

I am trying to make a project that monitors a scratch project so it can record the stats of it (views loves favs remixes) however I have not been able to think of a way to do this efficiently. The project would collect data once per day and save it to some type of file (im thinking with JSON but idk if that's a good choice). Here is what I thought of.
So you have a dictionary that has all the project ids of different projects the code is monitoring as keys, inside of each key in that dictionary you have another dictionary that has every day that it was collecting data. In each of thoughs keys you have a list with 4 items in it: views loves favorites and remixes.

While I think this would maybe work I also think it would take up a lot more power then is needed to make small additions to the data especially if it is getting the stats of a lot of projects at the same time.

Thanks!
A better way is to use a CSV like format, so you can just append to the file instead of reading and writing all of it at once. This also reduces the load on your disk which is good if you are using a raspberry pi with a microsd card. You can just have the project id, timestamp and then all of the stats in the CSV. You could even just put JSON in there (make sure it doesn't have newlines though), but it's probably better to make each value a separate CSV parameter, as that makes it much easier to process it (you can use most spreadsheet software). Also once a day sounds a bit slow lol.
Dagriffpatchfan
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

MonkeyBean2 wrote:

MineTurte wrote:

Dagriffpatchfan wrote:

I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah.
Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:
screen -dmS <name> <command>
eg.
screen -dmS scratchserver0 python3 main.py
and then to exit it or view its output you can do
screen -r <name>
and if you forgot the name you used you can use
screen -ls
to list all running screen sessions. Once you have gotten back into it with screen -r you can do ctrl+d to stop it.
1. Is this instructions for a windows pc?
2. I dont have admin priveleges and sign out of my account when Im done using the computer because I dont have a ton of screen time…does this still work when signed out?
8to16
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Dagriffpatchfan wrote:

(#1044)
1. Is this instructions for a windows pc?
from what i'm seeing this is for linux, but it should work for windows if you use WSL
davidtheplatform
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Dagriffpatchfan wrote:

MonkeyBean2 wrote:

MineTurte wrote:

Dagriffpatchfan wrote:

I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah.
Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:
screen -dmS <name> <command>
eg.
screen -dmS scratchserver0 python3 main.py
and then to exit it or view its output you can do
screen -r <name>
and if you forgot the name you used you can use
screen -ls
to list all running screen sessions. Once you have gotten back into it with screen -r you can do ctrl+d to stop it.
1. Is this instructions for a windows pc?
2. I dont have admin priveleges and sign out of my account when Im done using the computer because I dont have a ton of screen time…does this still work when signed out?
1. The instructions are for a Linux computer. It also works on WSL.
2. You shouldn’t use your normal computer for this. Do you have a raspberry pi which can stay on 24/7?

If you have to use windows, you can use task scheduler to run something every minute (or any period of time). I haven’t used it before though so I can’t give instructions.
Dagriffpatchfan
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
MonkeyBean2
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Dagriffpatchfan wrote:

1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
if using your pi, use the method I showed you with screen, that way if you are using ssh you can close the session and it will keep running
MineTurte
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Dagriffpatchfan wrote:

1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
If you don't mind me asking, which one?
wvzack
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
Maximouse
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
wvzack
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??

Last edited by wvzack (Dec. 23, 2024 16:02:45)

Maximouse
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

wvzack wrote:

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??
Is the function in a module that both scripts import? Each script will have a separate instance of the module.
davidtheplatform
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

wvzack wrote:

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??
It will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.
wvzack
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

davidtheplatform wrote:

wvzack wrote:

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??
It will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.
Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same time
davidtheplatform
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

wvzack wrote:

davidtheplatform wrote:

wvzack wrote:

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??
It will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.
Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same time
What do you mean by “at the same time”? Are you using a multithreading library or just saving files on a loop, or something else?
wvzack
Scratcher
500+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

davidtheplatform wrote:

wvzack wrote:

davidtheplatform wrote:

wvzack wrote:

Maximouse wrote:

wvzack wrote:

So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
open() will throw an error if it's called while the other script is using the file.
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??
It will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.
Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same time
What do you mean by “at the same time”? Are you using a multithreading library or just saving files on a loop, or something else?
So I would be monitoring turbowarp and scratch at the same time and they will both be importing the same script which opens/saves text files when a user does something on TW or scratch
georgek0
Scratcher
79 posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Hi, any advice on how to publish a module?
MineTurte
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

georgek0 wrote:

Hi, any advice on how to publish a module?
this should help

Last edited by MineTurte (Jan. 7, 2025 19:02:31)

kRxZy_kRxZy
Scratcher
1000+ posts

PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |

Where can I host python code 24/7 for free, I'm using it for scratch attach

Powered by DjangoBB