-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicItems.py
67 lines (57 loc) · 1.32 KB
/
basicItems.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
import os
from load import load
class basic(object):
@staticmethod
def storeFood(name, energy, keywords=""):
fp = open("./files/basicItems.csv", 'a+')
fp.write("\"" + name + "\",\"")
for i in range(len(keywords)):
fp.write(d[i])
if i is not len(keywords) - 1:
fp.write(":")
fp.write("\",\"" + energy +"\"\n")
fp.close()
@staticmethod
def readFood(name):
fp = open("./files/basicItems.csv", 'r+')
for line in fp:
copy = line
l = line.split(',')
l = l[0].split("\"")
if l[1] == name:
print copy
return
print "No match found!!!"
fp.close()
@staticmethod
def deleteFood(name):
ans = ""
fp = open("./files/basicItems.csv", 'r+')
for line in fp:
copy = line
l = line.split(',')
l = l[0].split("\"")
if l[1] != name:
ans = ans + copy
else:
print "Match Found!!! Entry Deleted!!!"
fp.close()
os.remove("./files/basicItems.csv")
fp = open("./files/basicItems.csv", 'w+')
fp.write(ans)
fp.close()
@staticmethod
def search(keyword):
print "Entries Found:"
fp = open("./files/basicItems.csv", 'r+')
for line in fp:
l = line.split(',')[1].split('\"')[1].split(':')
if any(keyword in s for s in l):
print line,
fp.close()
a = basic()
a.search("fruit")
#a.storeFood("ddsd", "122")
#a.readFood("jam")
#a.deleteFood("jam")
b = load()