-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
67 lines (58 loc) · 1.89 KB
/
Copy pathsetup.py
File metadata and controls
67 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os.path
import requests
import filecmp
import shutil
import subprocess
import time
import json
if os.path.exists("config.json") == False:
username = input("Username di Reddit: ")
password = input("Password di Reddit: ")
client_ID = input("ID creato al passo 2: ")
client_secret = input("Secret creato al passo 2: ")
f = open("config.json", "a")
config = {}
config["thread_delay"] = 2
config["unverified_place_frequency"] = False
config["workers"] = {}
config["workers"][username] = {
"password": password,
"client_id": client_ID,
"client_secret": client_secret,
"start_coords": [0, 0],
}
json.dump(config, f)
f.close()
def run():
print("Script launched")
process = subprocess.Popen(
args=["python", "./main.py"], stdout=subprocess.PIPE, shell=False
)
return process
def download_image(process=""):
print("Search for image updates")
url = "https://raw.githubusercontent.com/italyplace/rplace/main/art.png"
r = requests.get(url, allow_redirects=True)
open("ntemp.bin", "wb").write(r.content)
if not os.path.exists("temp.bin") or not filecmp.cmp("ntemp.bin", "temp.bin"):
print("Update found!")
shutil.copyfile("ntemp.bin", "temp.bin")
# riavvio il processo quando sono nel loop
if process != "":
process.terminate()
process.wait()
process = run()
# Se Reddit schiatta, anche il bot bot schiatta controlliamo se il processo è vivo
if not isinstance(process, str) and process.poll() is not None:
process.terminate()
process.wait()
process = run()
return process
# scarico l'immagine all'avvio per vedere se ci sono aggiornamenti
download_image()
process = run()
# verifica ogni 5 minuti per aggiornamenti
t_end = 60 * 5
while True:
process = download_image(process)
time.sleep(t_end)