-
Notifications
You must be signed in to change notification settings - Fork 0
/
iBelieve.py
157 lines (132 loc) · 3.97 KB
/
iBelieve.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import numpy as np
from Entry import Entry
import os
################################################################################
root = "C:\\Users\\Tanner\\Documents\\\"Python Scripts\"\\iBelieve\\data.txt"
help_text = '''
add - (applied to current entry)
author
file
source
tag
backup -
create
restore - (make sure there is a confirmation message)
current -
print the ID of the current Entry
echo - print echo. (temp)
edit -
author -
body -
file -
source -
summary -
tag -
new - create a new Entry
open - (applied to current Entry)
file - (if it exists)
source - (if it's a website)
quit - exit the program. You will be asked if you want to save the session
remove - (make sure there is a confirmation message)
author -
body -
file -
source -
summary -
tag -
search -
author -
date -
keyword - (search everything. This will take a while)
tag -
ID -
select ID - make the Entry of with matching ID the current Entry. Prints the ID
and the summary of the current Entry.
set - change the directory to the new location. Move the whole folder to
that new location. (make sure there is a confirmation message)
(also ask if the user would like to save their session first)
show all - print the ID and summary for all entries
view - (for debugging)
write -
'''
current_entry = 0
master_dictionary = {} #pairs IDs and Entries
# confirmation message
def confirmed():
response = raw_input("Are you sure? (Y/n)")
if response in ("Y", "y", ""):
return True
else:
return False
def init_data():
file = open("data.txt",'r')
my_list = []
doit = True
while doit:
summary = file.readline().strip()
author = file.readline().strip()
body = file.readline().strip()
tags = file.readline().strip().split()
source = file.readline().strip()
date = file.readline()
link = file.readline().strip()
files = file.readline().strip()
master_dictionary[len(master_dictionary) + 1] = Entry(
summary,author,body,tags,source,date,link=link,files=files)
peek = peek_line(file)
if peek == "end":
doit = False
return my_list
# add a new entry to the master_list
def new_entry():
summary = raw_input("Summary: ")
author = raw_input("Author: ")
body = raw_input("Body: ")
tags = raw_input("Tags: ")
source = raw_input("Source: ")
entry = Entry(summary, author, body, tags.split(), source, "date") #TODO
master_dictionary[len(master_dictionary) + 1] = entry
return len(master_dictionary)
def peek_line(f):
pos = f.tell()
line = f.readline().strip()
f.seek(pos)
return line
def write_file():
file = open("data.txt","w")
for i in master_dictionary.values():
file.write(i.print_write())
if __name__ == "__main__":
file = open("data.txt", 'r')
data = init_data()
while True:
print ""
command = raw_input(">>> ")
# current
if command == "current":
print current_entry
# echo
elif command == "echo":
print "echo"
# new
elif command == "new":
current_entry = new_entry() #sets the ID of the new entry to current_entry
# quit
elif command == "quit":
if confirmed():
save = raw_input("Save current session? (Y/n) ")
if save in ("Y", "y", ""):
#call saving function
print "saving..."
break
# view (for debug)
elif command == "view":
print data
print master_dictionary
elif command == "write":
write_file()
# ?
elif command == "?":
print help_text
else:
print "invalid command"