import qrcode
import sqlite3
from datetime import datetime
# สร้างฐานข้อมูล SQLite
conn = sqlite3.connect("cow_feeding.db")
c = conn.cursor()
# ตารางเก็บข้อมูลวัว
c.execute('''CREATE TABLE IF NOT EXISTS cows (
id TEXT PRIMARY KEY,
name TEXT,
breed TEXT,
dob TEXT,
weight INTEGER
)''')
# ตารางเก็บข้อมูลอาหาร
c.execute('''CREATE TABLE IF NOT EXISTS food (
id TEXT PRIMARY KEY,
type TEXT,
production_date TEXT,
ingredients TEXT,
cost REAL
)''')
# ตารางบันทึกการกินอาหาร
c.execute('''CREATE TABLE IF NOT EXISTS feeding_logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
cow_id TEXT,
food_id TEXT,
date TEXT,
given_amount REAL,
leftover_amount REAL,
consumed_amount REAL,
FOREIGN KEY(cow_id) REFERENCES cows(id),
FOREIGN KEY(food_id) REFERENCES food(id)
)''')
conn.commit()
# ฟังก์ชันสร้าง QR Code
def generate_qr(data, filename):
qr = qrcode.make(data)
qr.save(filename)
print(f"QR Code saved as {filename}")
# ตัวอย่างการสร้าง QR Code ให้วัวและอาหาร
cow_data = "{\"id\": \"W-01\", \"name\": \"วัวแดง\", \"breed\": \"โคนม\", \"dob\": \"2023-05-10\", \"weight\": 450}"
generate_qr(cow_data, "cow_W-01.png")
food_data = "{\"id\": \"F-20250331-01\", \"type\": \"หญ้าเนเปียร์\", \"production_date\": \"2025-03-31\", \"ingredients\": \"หญ้าสด 100%\", \"cost\": 5.0}"
generate_qr(food_data, "food_F-20250331-01.png")
# ปิดฐานข้อมูล
conn.close()
}
aW1wb3J0IHFyY29kZQppbXBvcnQgc3FsaXRlMwpmcm9tIGRhdGV0aW1lIGltcG9ydCBkYXRldGltZQoKIyDguKrguKPguYnguLLguIfguJDguLLguJnguILguYnguK3guKHguLnguKUgU1FMaXRlCmNvbm4gPSBzcWxpdGUzLmNvbm5lY3QoImNvd19mZWVkaW5nLmRiIikKYyA9IGNvbm4uY3Vyc29yKCkKCiMg4LiV4Liy4Lij4Liy4LiH4LmA4LiB4LmH4Lia4LiC4LmJ4Lit4Lih4Li54Lil4Lin4Lix4LinCmMuZXhlY3V0ZSgnJydDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBjb3dzICgKICAgICAgICAgICAgICAgIGlkIFRFWFQgUFJJTUFSWSBLRVksCiAgICAgICAgICAgICAgICBuYW1lIFRFWFQsCiAgICAgICAgICAgICAgICBicmVlZCBURVhULAogICAgICAgICAgICAgICAgZG9iIFRFWFQsCiAgICAgICAgICAgICAgICB3ZWlnaHQgSU5URUdFUgogICAgICAgICAgICApJycnKQoKIyDguJXguLLguKPguLLguIfguYDguIHguYfguJrguILguYnguK3guKHguLnguKXguK3guLLguKvguLLguKMKYy5leGVjdXRlKCcnJ0NSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIGZvb2QgKAogICAgICAgICAgICAgICAgaWQgVEVYVCBQUklNQVJZIEtFWSwKICAgICAgICAgICAgICAgIHR5cGUgVEVYVCwKICAgICAgICAgICAgICAgIHByb2R1Y3Rpb25fZGF0ZSBURVhULAogICAgICAgICAgICAgICAgaW5ncmVkaWVudHMgVEVYVCwKICAgICAgICAgICAgICAgIGNvc3QgUkVBTAogICAgICAgICAgICApJycnKQoKIyDguJXguLLguKPguLLguIfguJrguLHguJnguJfguLbguIHguIHguLLguKPguIHguLTguJnguK3guLLguKvguLLguKMKYy5leGVjdXRlKCcnJ0NSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIGZlZWRpbmdfbG9ncyAoCiAgICAgICAgICAgICAgICBsb2dfaWQgSU5URUdFUiBQUklNQVJZIEtFWSBBVVRPSU5DUkVNRU5ULAogICAgICAgICAgICAgICAgY293X2lkIFRFWFQsCiAgICAgICAgICAgICAgICBmb29kX2lkIFRFWFQsCiAgICAgICAgICAgICAgICBkYXRlIFRFWFQsCiAgICAgICAgICAgICAgICBnaXZlbl9hbW91bnQgUkVBTCwKICAgICAgICAgICAgICAgIGxlZnRvdmV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liq4LiUIDEwMCVcIiwgXCJjb3N0XCI6IDUuMH0iCmdlbmVyYXRlX3FyKGZvb2RfZGF0YSwgImZvb2RfRi0yMDI1MDMzMS0wMS5wbmciKQoKIyDguJvguLTguJTguJDguLLguJnguILguYnguK3guKHguLnguKUKY29ubi5jbG9zZSgpCgoKfQ==
import qrcode
import sqlite3
from datetime import datetime
# สร้างฐานข้อมูล SQLite
conn = sqlite3.connect("cow_feeding.db")
c = conn.cursor()
# ตารางเก็บข้อมูลวัว
c.execute('''CREATE TABLE IF NOT EXISTS cows (
id TEXT PRIMARY KEY,
name TEXT,
breed TEXT,
dob TEXT,
weight INTEGER
)''')
# ตารางเก็บข้อมูลอาหาร
c.execute('''CREATE TABLE IF NOT EXISTS food (
id TEXT PRIMARY KEY,
type TEXT,
production_date TEXT,
ingredients TEXT,
cost REAL
)''')
# ตารางบันทึกการกินอาหาร
c.execute('''CREATE TABLE IF NOT EXISTS feeding_logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
cow_id TEXT,
food_id TEXT,
date TEXT,
given_amount REAL,
leftover_amount REAL,
consumed_amount REAL,
FOREIGN KEY(cow_id) REFERENCES cows(id),
FOREIGN KEY(food_id) REFERENCES food(id)
)''')
conn.commit()
# ฟังก์ชันสร้าง QR Code
def generate_qr(data, filename):
qr = qrcode.make(data)
qr.save(filename)
print(f"QR Code saved as {filename}")
# ตัวอย่างการสร้าง QR Code ให้วัวและอาหาร
cow_data = "{\"id\": \"W-01\", \"name\": \"วัวแดง\", \"breed\": \"โคนม\", \"dob\": \"2023-05-10\", \"weight\": 450}"
generate_qr(cow_data, "cow_W-01.png")
food_data = "{\"id\": \"F-20250331-01\", \"type\": \"หญ้าเนเปียร์\", \"production_date\": \"2025-03-31\", \"ingredients\": \"หญ้าสด 100%\", \"cost\": 5.0}"
generate_qr(food_data, "food_F-20250331-01.png")
# ปิดฐานข้อมูล
conn.close()
}