-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_achieve.py
50 lines (44 loc) · 1.36 KB
/
add_achieve.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
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import pickle
import os
import datetime
import sys
if (not os.uname()[1] in ['iPhone','iPad']):
import readline
else:
import save_sync
ACHIEVEFILE = ''
def set_achievefile_env():
if os.environ.get('TODOACHIEVE') == None:
print('環境変数"TODOACHIEVE"を設定してください\n(相対パスだと動かない?)')
sys.exit(1)
else:
global ACHIEVEFILE
ACHIEVEFILE = os.environ.get('TODOACHIEVE') + 'todo.achieve'
def save(data_list):
global ACHIEVEFILE
with open(ACHIEVEFILE, 'wb') as achievefile:
pickle.dump(data_list,achievefile)
def load():
global ACHIEVEFILE
if os.path.isfile(ACHIEVEFILE):
with open(ACHIEVEFILE, 'rb') as achievefile:
data_list = pickle.load(achievefile)
return data_list
else:
save([])
return []
def add_achieve(achieve):
set_achievefile_env()
dt = datetime.date.today()
data_dict = {'name':achieve,'date':dt}
data_list = []
data_list = load()
data_list.append(data_dict)
save(data_list)
if __name__ == '__main__':
if (os.uname()[1] in ['iPhone','iPad']):
save_sync.load()
os.environ['TODOACHIEVE'] = '/private/var/mobile/Containers/Shared/AppGroup/BD1DA245-5619-467F-B9B5-34FF6EFCCDE2/Pythonista3/Documents/todo/'
set_achievefile_env()