-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_file.py
45 lines (37 loc) · 950 Bytes
/
update_file.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
import pickle
import os
def update(Id):
updating(Id)
'''for i in Id.followers:
updating(i)
for i in Id.following:
updating(i)'''
def updating(Id):
f2=open("temp.txt","wb")
try:
with open("Users.txt","rb") as f:
while True:
obj=pickle.load(f)
if obj.id==Id.id:
pickle.dump(Id,f2)
continue
pickle.dump(obj,f2)
except:
f2.close()
os.remove("Users.txt")
os.rename("temp.txt","Users.txt")
def render(ids):
A=[]
if ids==[]:
#print("khali h bhai ")
return []
ids=set(ids)
try:
with open("Users.txt","rb") as f:
while True:
obj=pickle.load(f)
if obj.id in ids:
ids-={obj.id}
A.append(obj)
except:
return A