File permissions, optimized db access
This commit is contained in:
parent
f716b4ab96
commit
a74d257506
28
botany.py
28
botany.py
@ -225,22 +225,24 @@ class Plant(object):
|
|||||||
if os.path.isfile(visitor_filepath):
|
if os.path.isfile(visitor_filepath):
|
||||||
with open(visitor_filepath, 'r') as visitor_file:
|
with open(visitor_filepath, 'r') as visitor_file:
|
||||||
data = json.load(visitor_file)
|
data = json.load(visitor_file)
|
||||||
for element in data:
|
if data:
|
||||||
if element['user'] not in self.visitors:
|
for element in data:
|
||||||
self.visitors.append(element['user'])
|
if element['user'] not in self.visitors:
|
||||||
if element['user'] not in visitors_this_check:
|
self.visitors.append(element['user'])
|
||||||
visitors_this_check.append(element['user'])
|
if element['user'] not in visitors_this_check:
|
||||||
if element['timestamp'] > latest_timestamp:
|
visitors_this_check.append(element['user'])
|
||||||
latest_timestamp = element['timestamp']
|
if element['timestamp'] > latest_timestamp:
|
||||||
with open(visitor_filepath, 'w') as visitor_file:
|
latest_timestamp = element['timestamp']
|
||||||
visitor_file.write('[]')
|
try:
|
||||||
try:
|
self.update_visitor_db(visitors_this_check)
|
||||||
self.update_visitor_db(visitors_this_check)
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
with open(visitor_filepath, 'w') as visitor_file:
|
||||||
|
visitor_file.write('[]')
|
||||||
else:
|
else:
|
||||||
with open(visitor_filepath, mode='w') as f:
|
with open(visitor_filepath, mode='w') as f:
|
||||||
json.dump([], f)
|
json.dump([], f)
|
||||||
|
os.chmod(visitor_filepath, 0666)
|
||||||
return latest_timestamp
|
return latest_timestamp
|
||||||
|
|
||||||
def water_check(self):
|
def water_check(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user