-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_new_task.py
executable file
·70 lines (63 loc) · 2.11 KB
/
add_new_task.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
66
67
68
69
70
#!/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
SAVEFILE = ''
def set_savefile_env():
if os.environ.get('TODOSAVE') == None:
print('環境変数"TODOSAVE"を設定してください\n(相対パスだと動かない?)')
sys.exit(1)
else:
global SAVEFILE
SAVEFILE = os.environ.get('TODOSAVE') + 'todo.save'
def create_new_task():
name = input('タスク名を入力: ')
print('期限の入力↓')
limit = {'year':0, 'month':0, 'date':0, 'hour':0}
limit['year'] = int(input('year: '))
limit['month'] = int(input('month: '))
limit['date'] = int(input('date: '))
limit['hour'] = int(input('hour: '))
dt = datetime.datetime(limit['year'],limit['month'],limit['date'],limit['hour'])
data_dict = {'name':name,'datetime':dt}
return data_dict
def save(data_list):
global SAVEFILE
with open(SAVEFILE, 'wb') as savefile:
pickle.dump(data_list,savefile)
def load():
global SAVEFILE
if os.path.isfile(SAVEFILE):
with open(SAVEFILE, 'rb') as savefile:
data_list = pickle.load(savefile)
return data_list
else:
save([])
return []
def add_new_task():
data_dict = create_new_task()
data_list = []
data_list = load()
data_list.append(data_dict)
save(data_list)
if __name__ == '__main__':
if (os.uname()[1] in ['iPhone','iPad']):
savefiles_on_dropbox = ['/todo/todo.save']
savefiles_on_device = ['./todo.save']
save_sync.load(savefiles_on_device,savefiles_on_dropbox)
os.environ['TODOSAVE'] = '/private/var/mobile/Containers/Shared/AppGroup/BD1DA245-5619-467F-B9B5-34FF6EFCCDE2/Pythonista3/Documents/todo/'
set_savefile_env()
while True:
add_new_task()
if input('続けてタスクを登録しますか? y/n :') == 'n':
if (os.uname()[1] in ['iPhone','iPad']):
save_sync.save(savefiles_on_device,savefiles_on_dropbox)
sys.exit()
else:
pass