Skip to content

Commit 6add3cd

Browse files
authored
Merge pull request #48 from Boss-1s/scratch_chat_dev
Scratch chat dev push and pull
2 parents 5859c02 + b31f1ee commit 6add3cd

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

chat_db.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"0198134f-5130-7334-7525-dcfb2cd71b02": "Galexy_matter77777: Other - to Boss_1s - Sent at 7-29-2025 @13:57:2 GMT-5(DST) with ID|0198134f-5130-7334-7525-dcfb2cd71b02",
66
"0198184c-37e8-7784-886e-6783840e8ace": "Th3HalfMo0n: Good Morning - to Boss_1s - Sent at 7-30-2025 @01:11:45 GMT-5(DST) with ID|0198184c-37e8-7784-886e-6783840e8ace",
77
"01981873-3c30-73ba-b94b-8dc295f4c129": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @11:54:22 GMT-6(DST) with ID|01981873-3c30-73ba-b94b-8dc295f4c129",
8-
"01981849-5988-7384-2606-3c37ddc2ffa8": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @12:08:37 GMT-6(DST) with ID|01981849-5988-7384-2606-3c37ddc2ffa8"
8+
"01981849-5988-7384-2606-3c37ddc2ffa8": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @12:08:37 GMT-6(DST) with ID|01981849-5988-7384-2606-3c37ddc2ffa8",
9+
"0198533e-5a20-7906-4060-8104c94f618b": "cidanimations4102: Hi! - to JEFX_OFFICIAL - Sent at 8-11-2025 @15:54:12 GMT-5(DST) with ID|0198533e-5a20-7906-4060-8104c94f618b",
10+
"0198531c-7658-78b6-ddb6-ceb011baa467": "JEFX_OFFICIAL: ....... - to cidanimations4102 - Sent at 8-11-2025 @15:17:11 GMT-6(DST) with ID|0198531c-7658-78b6-ddb6-ceb011baa467",
11+
"0198531e-3f60-757a-9f5a-56bfcb4be5c8": "cidanimations4102: Hi! - to JEFX_OFFICIAL - Sent at 8-11-2025 @16:19:8 GMT-5(DST) with ID|0198531e-3f60-757a-9f5a-56bfcb4be5c8"
912
}

chat_history_db.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"0198134f-5130-7334-7525-dcfb2cd71b02": "Galexy_matter77777: Other - to Boss_1s - Sent at 7-29-2025 @13:57:2 GMT-5(DST) with ID|0198134f-5130-7334-7525-dcfb2cd71b02",
66
"0198184c-37e8-7784-886e-6783840e8ace": "Th3HalfMo0n: Good Morning - to Boss_1s - Sent at 7-30-2025 @01:11:45 GMT-5(DST) with ID|0198184c-37e8-7784-886e-6783840e8ace",
77
"01981873-3c30-73ba-b94b-8dc295f4c129": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @11:54:22 GMT-6(DST) with ID|01981873-3c30-73ba-b94b-8dc295f4c129",
8-
"01981849-5988-7384-2606-3c37ddc2ffa8": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @12:08:37 GMT-6(DST) with ID|01981849-5988-7384-2606-3c37ddc2ffa8"
8+
"01981849-5988-7384-2606-3c37ddc2ffa8": "Boss_1s: Hello! - to Boss_1s - Sent at 7-30-2025 @12:08:37 GMT-6(DST) with ID|01981849-5988-7384-2606-3c37ddc2ffa8",
9+
"0198531c-7658-78b6-ddb6-ceb011baa467": "JEFX_OFFICIAL: ....... - to cidanimations4102 - Sent at 8-11-2025 @15:17:11 GMT-6(DST) with ID|0198531c-7658-78b6-ddb6-ceb011baa467",
10+
"0198531e-3f60-757a-9f5a-56bfcb4be5c8": "cidanimations4102: Hi! - to JEFX_OFFICIAL - Sent at 8-11-2025 @16:19:8 GMT-5(DST) with ID|0198531e-3f60-757a-9f5a-56bfcb4be5c8"
911
}

scratch_chat_db.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,58 @@
1212
session = scratch3.login("Boss_1sALT", passwrd)
1313
cloud = session.connect_cloud("895107188") #<- this is the real project
1414

15+
def print2(str):
16+
print(str)
17+
os.system(str)
18+
1519
#db
1620
storage = cloud.storage(used_cloud_vars=["3","4"])
1721

18-
db1 = db("chat", json_file_path="chat_db.json", save_interval=60)
19-
db2 = db("history", json_file_path="chat_history_db.json", save_interval=60)
22+
db1 = db("chat", json_file_path="chat_db.json", save_interval=5)
23+
db2 = db("history", json_file_path="chat_history_db.json", save_interval=5)
2024

2125
storage.add_database(db1)
2226
storage.add_database(db2)
2327

2428
@storage.request(response_priority=1)
2529
def ping2():
2630
return "pong"
27-
print("Database handler pinged")
31+
print2("Database handler pinged")
2832

2933
@storage.request(name="delete")
3034
def delete_request(db_name, key):
3135
del storage.get_database(db_name).data[key]
3236

3337
@storage.request(name="delete_all")
3438
def delete_all(db_name):
35-
# write an empty dictionary to the file
36-
if db_name == "chat":
37-
with open("chat_db.json", "w") as f:
38-
json.dump({}, f)
39-
elif db_name == "history":
40-
with open("chat_history_db.json", "w") as f:
41-
json.dump({}, f)
42-
print(f"All data deleted from database {db_name}.")
43-
return ""
39+
try:
40+
# write an empty dictionary to the file
41+
if db_name == "chat":
42+
with open("chat_db.json", "w") as f:
43+
json.dump({}, f)
44+
elif db_name == "history":
45+
with open("chat_history_db.json", "w") as f:
46+
json.dump({}, f)
47+
print2(f"All data deleted from database {db_name}.")
48+
return "go delete"
49+
except Exception as e:
50+
print2(f"Encountered exception {e}, data may have not been deleted")
51+
return "no-go delete"
4452

4553
@db1.event
4654
def on_save():
47-
print("Data was saved to db chat")
55+
print2("Data was saved to db chat")
4856

4957
@db1.event
5058
def on_set(key, value):
51-
print("Key", key, "was set to value", value, "in db chat")
59+
print2(f"Key {key} was set to value {value} in db chat")
5260

5361
@db2.event
5462
def on_save():
55-
print("Data was saved to db history")
63+
print2("Data was saved to db history")
5664

5765
@db2.event
5866
def on_set(key, value):
59-
print("Key", key, "was set to value", value, "in db history")
67+
print2(f"Key {key} was set to value {value} in db history")
6068

6169
storage.start()

0 commit comments

Comments
 (0)