-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpPredict.py
More file actions
51 lines (38 loc) · 1.64 KB
/
expPredict.py
File metadata and controls
51 lines (38 loc) · 1.64 KB
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
import json
from datetime import datetime, timedelta
# load the predicted expiration times dataset
with open('expirationPredictions.json', 'r') as file:
expiration_data = json.load(file)
user_input = input("Enter food item name: ")
# variables to keep track of the best match
best_match = None
best_score = 0
# search for a product that best matches the user input
for product_id, product_info in expiration_data.items():
keywords = product_info.get('Keywords', [])
# calculate match score for current product
score = sum(1 for keyword in keywords if keyword in user_input)
# update best match if current product has higher score
if score > best_score:
best_match = product_info
best_score = score
# output results
if best_match:
print("Match found!")
print("Name:", best_match['Name'])
print("Subtitle:", best_match['Name_subtitle'])
print("Keywords:", best_match['Keywords'])
print("Expiration time:", best_match['Expiration_time'], best_match['Expiration_metric'])
print("")
# calculate predicted expiration date
expiration_time_days = best_match['Expiration_time_DAYS']
current_date = datetime.now().date()
print("Current date:", current_date.strftime("%Y-%m-%d"))
expiration_date = current_date + timedelta(days=expiration_time_days)
print("Predicted expiration date:", expiration_date.strftime("%Y-%m-%d"))
# convert to unix timestamp format
expiration_datetime = datetime.combine(expiration_date, datetime.min.time())
expiration_timestamp = expiration_datetime.timestamp()
print(int(expiration_timestamp))
else:
print("No matching products found.")