-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpocketBook.py
103 lines (85 loc) · 2.21 KB
/
pocketBook.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
def num_of_entries(i):
"""
Counts number of entries
this is used to count how many times user has entered something compared to how many entries he would like to make
"""
count = 0
i = int(i)
if i != 0:
count = i
return i
def str_to_list(string):
li = list(string.split(" "))
return li
def file_creator(f, l):
"""
Looks for filename in directory,
if not found will create and write
if found will append
"""
import os
filename = f
answ=os.path.exists(filename)
with open(filename, 'a' if answ else "w") as file:
if(answ):
file.write("\n")
file.write(l)
def file_reader(f):
with open(f, 'r') as fh:
return fh.read()
def line_count(f, e):
"""
Uses basic file reading func above.
f = file
e = element to be counted
"""
count = 0
file_reader(f)
for e in f:
count+=1
return count
#def count_newline(newlist):
# """
# This is used to count number of \n
# in order to index selection of entries
# as a whole, not as words
# """
# return str.count('\n')
##Need something for encryption as well as removing items from text/crossing off or ticking. Whichever is possible.
##Also some sort of reminder function that works with time in OS module
item = []
c = num_of_entries(input("How many entries?\n#:"))
c-=1
print("Please input each task")
# Compares amount entered to user input
while len(item) <= c:
iapp = input("$:")
item.append(iapp + ".")
# Seperates each new line inputted into a new line in a string
item = '\n'.join(item)
file_creator("entries.txt", item)
lc = line_count("entries.txt", '.')
read = file_reader('entries.txt')
print(read)
#print(type(item))
#itemCount = item.count('\n')
#itemCount+=1
#itemCount = str(itemCount)
#print(itemCount)
##print(itemCount.append(item))
#print(type(item))
#istr = str(item)
#nl = "\n".join(item)
#print(nl)
#print(type(nl))
#ilist = str_to_list(istr)
#print(ilist)
#print(count_newline(ilist))
#file_creator("entries.txt", istr)
#print(ilist)
#filename = "entries.txt"
#answ=os.path.exists(filename)
#with open(filename, 'a' if answ else "w") as f:
# if(answ):
# f.write("\n")
# f.write(istr)