-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_redis.py
55 lines (38 loc) · 1.01 KB
/
load_redis.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
import redis
import yaml
redis_server = [HOST]
port = 6379
db=1
data_file= [DATA_JSON_FILE]
def load_dishes():
with open(data_file,"r") as file:
data = yaml.safe_load(file)
dishes = data['dishes']
return dishes
#for dish in dishes['dishes']:
# summary = dish['summary']
# if not counts.has_key(summary):
# counts[summary]=1
# else:
# counts[summary]+=1
def uniq(redis,dish):
if redis.get(dish) == None:
return True
return False
def valid(dish):
if not dish.has_key('ingredients'):
return False
if not dish.has_key('summary'):
return False
return True
def main():
client = redis.StrictRedis(host=redis_server, port=port,db=db)
dishes = load_dishes()
for dish in dishes:
print(dish)
if valid(dish) and (uniq(client, dish['summary'])):
client.set(dish['summary'],dish['ingredients'])
client.get(dish['summary'])
print(dish)
if __name__ == "__main__":
main()