-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_storage.py
65 lines (48 loc) · 1.53 KB
/
data_storage.py
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
from ds_messenger import *
from pathlib import Path
#p = Path('/Users/laurawang/Desktop/UCI/2022Winter/ICS32/lecture/final_project/final_project/lll.dsu')
#ds_messager= DirectMessenger('168.235.86.101', 'Daddy', '123')
# dm.send('Hi', 'wobuzhidao')
def get_all_history(ds_messager):
lst = ds_messager.retrieve_all()
#print(lst)
hist = {}
temp_lst = []
for i in lst:
set = [i.sender, i]
temp_lst.append(set)
for p in range(len(temp_lst)):
if temp_lst[p][0] in hist.keys():
hist[temp_lst[p][0]].append(temp_lst[p][1])
else:
hist[temp_lst[p][0]] = [temp_lst[p][1]]
print(hist.keys())
return hist
'''
def add_retrived_history(hist,my_name)->None:
'add objects of DirectMessage into the dsu file'
for i in hist:
p=Path('.').joinpath(i+'.dsu')
print(p)
try:
if p.exists():
#if p.exists() and i.sender == my_name:
for dm in hist[i]:
dm.save(p)
except:
pass
'''
def add_retrived_history(hist, my_name) -> None:
'add objects of DirectMessage into the dsu file'
try:
for i in hist:
p = Path('.').joinpath(i + '.dsu')
print(p)
if not p.exists():
p.touch()
for dm in hist[i]:
dm.save(p)
except:
pass
#hist=get_all_history(ds_messager)
#dd_retirved_history(hist, "Somebody")