I have a python program that can collect information about books from html files. The information includes weight, size, shape author etc. How would I go about writing a piece of code that could "package" x number of books in n boxes with each box having no more than 10lb?
I imagine there are two ways to go about this, one way is to package each box sequentially unitl it was <= 10. The second way is to package the books most effieciently so that there only the fewest number ok boxes was required.
Here is my algorithm for collecting the information:
import glob
import json
from bs4 import BeautifulSoup
def main():
data = []
for filename in glob.iglob('*.html'):
with open(filename) as f:
soup = BeautifulSoup(f)
title = soup.find("span", id="btAsinTitle")
data.append({
"title": title.get_text(),
"author": title.find_next("a", href=True).get_text(),
"isbn": soup.find('b', text='ISBN-10:').next_sibling,
"weight": soup.find('b', text='Shipping Weight:').next_sibling,
"price": soup.find('span', {"class":'bb_price'}).get_text()
})
with open("my_output.json", "w") as outf:
json.dump(data, outf, indent = 1)
main()