Dudes of 708's knowledge base for getting started and tools we use
Back to homepage • software development guides
This is currently a work-in-progress guide. Please feel free to contribute to it.
The server runs on localhost, port 5050 when run in development mode. This means you can navigate to http://localhost:5050 to see your server in action.
To install, you’ll need Python 3.7 or newer. If you can’t figure out how to install Python, maybe it’s time to reevalulate if you know what you’re doing. (Just kidding, Google it or message the Discord channel.)
For the purposes of this guide, Python will be referred to as python
. You may have your bindings set to python3
or python3.7
if you’re using macOS or Linux, or py -3
or py -3.7
if you’re using Windows.
ChompChomp-server
with git. If you don’t know how, see this guide.Create a virtual environment:
python -m venv venv
Activate the virtual environment. On Windows, run:
.\venv\Scripts\activate
or on Linux or macOS, run:
source venv/bin/activate
Install required dependencies with pip
. You may need to use pip3
depending on how you have Python installed.
pip install -r requirements.txt
You can test your routes however you want, including by opening a custom build of the app pointing at your computer, but I reccommend Postman. It’s easy to use and easy to set up.
There are six routes
GET
Check ItemGET
Get ItemPOST
New ItemPOST
Edit ItemPOST
Observe ItemPOST
Add ImageGET
Get ImagesGET
/items/exists
: Checks if an item exists in the database
Requirements:
barcode
Provide a barcode to the database and it will tell you if it exists.
Returns:
If the item exists: status code 200 OK
and:
{
"exists": true
}
If the item does not exist: status code 404 NOT FOUND
and:
{
"exists": false
}
GET
/items/get
: Gets an item from the database
Requirements:
barcode
Provide a barcode to the database and it will respond with the corresponding object.
Returns:
On success, it returns status code 200 OK
with the corresponding item, except the images is replaced with the number of images:
{
"barcode": "00000000",
...
"images": 3
}
On error, it returns status code 400 BAD REQUEST
if no barcode was provided or 404 NOT FOUND
if the barcode does not exist.
{
"error": true
}
POST
/items/new
: Takes a new item as a JSON object.
Requirements:
Content-Header
header with data application/json
is required.The input schema is:
date
: ISO 8601-compatiable timestampstore
: String containing store number, city, and state codename
: String containing name of productprice
: String containing float value of priceweight
: String containing float value of weight in oz.barcode
: String value containing EAN-8 or EAN-13 barcode valueAs an example, the input looks something like this:
{
"date": "2021-04-12T02:48:56.813Z",
"store": "7 West Los Angeles, CA",
"name": "Cheese Wheel",
"price": "1.99",
"weight": "16",
"barcode": "00000000"
}
Returns:
On success, it returns status code 200 OK
with a success message:
{
"success": true
}
On error, it returns 400 BAD REQUEST
or 500 INTERNAL SERVER ERROR
depending on the error, with a corresponding error message:
{
"error": "Something happened!"
}
POST
/item/edit
: Edits an item
Requirements:
Content-Header
header with data application/json
is required.The input schema is:
barcode
: String value containing EAN-8 or EAN-13 barcode value to updatename
: (optional) Name to updateunit
: (optional) Update unitsweight
: (optional) New weight to update toAs an example, here is something you can provide:
{
"barcode": "00000000",
"weight": "16"
}
Returns:
The server returns status code 200 OK
with the new item (sans images) if successful, like so:
{
"barcode": "00000000",
...
"images": 3
}
If the input was invalid, the server returns 400 BAD REQUEST
with the corresponding error message or 500 SERVER ERROR
if the input was unexpected. If the barcode does not exist, the server returns 404 NOT FOUND
instead.
Example:
{
"error": "Something happened!"
}
POST
/item/observe
: Adds a price observation to an item
Requirements:
Content-Header
header with data application/json
is required.The input schema is:
barcode
: String value containing EAN-8 or EAN-13 barcode value to observestore
: Store string name as described in the appdate
: Timestamp in ISO 8601 format of observationprice
: Observed priceAll inputs are strings. Additional data is ignored.
Returns:
The new item is returned with 200 OK
on success (sans images). Example:
{
"barcode": "00000000",
...
"images": 3
}
You may get a 500 INTERNAL SERVER ERROR
if the server can’t interpret the data, or 400 BAD REQUEST
if you pass bad data to the server, or a 404 NOT FOUND
if the barcode doesn’t already exist in the server. The corresponding return data is a descriptive error of what went wrong, like:
{
"error": "Something happened!"
}
POST
/item/images/add
: Add an image to the database
This endpoint hasn’t been implemented yet.
GET
/item/images/get
: Get images from the database
Requirements:
barcode
Provide the barcode to the database and it will return an array of images according to the spec as they are stored in the database.
Returns:
On success, it returns status code 200 OK
with images. Example:
[
{
"type": "base64/png",
"data": "data:image/png;base64,..."
},
{
"type": "base64/jpeg",
"data": "data:image/jpeg;base64,..."
},
{
"type": "uri",
"data": "https://i.imgur.com/2dn06CW.png"
}
]
It may return 404 NOT FOUND
if the barcode doesn’t exist and 400 BAD REQUEST
if no barcode was provided. If there are no images, it returns an empty array.
Although there are different ways to store the data, i.e. a custom rolled database structure, document-like structure as with no-SQL databases, or tables as with SQL-like databases, it will be documented here as a document-like structure. This makes it easier to read.
Click here to read about descriptions or here to see an example.
This is the schema of database objects stored on the server.
Some notes:
Schema:
barcode
: A string of Trader Joe’s internal barcode - according to the International Article Number spec, this should be made up of only integersbarcode_type
: EAN8
, EAN13
or Unknown
, if there are other types found, this will be updatedname
: String name of product - prefer the long name on tags rather than the short name on receipts due to searachabilityprice
: Most recent price observedunit
: What unit the price is sold in, one of EA
for each, OZ
for ounces, LB
for poundsweight
: Floating point net weight of product in ouncesprices
: Observed prices of products - array of dictionaries
store
: Integer Trader Joe’s store number, or -1 if unknown or not assigneddate
: String representation of date when this price was observed in YYYY/MM/DD
formatprice
: Floating point priceimages
: Array of dictionaries
type
: One of base64/png
, base64/jpeg
, or uri
data
: If type
is base64
, contains base 64 data of the image itself. If type
is uri
, contains a direct link to the image. Please try to pre-compress the image to save storage on the serverThis example follows the schema described above in schema descriptions.
{
"barcode": "00000000",
"barcode_type": "EAN8",
"name": "Cheese Wheel",
"price": 1.99,
"unit": "EA",
"weight": 16,
"prices": [
{
"store": 100,
"date": "2021/01/01",
"price": 1.99
}
],
"images": [
{
"type": "base64/png",
"data": "data:image/png;base64,..."
},
{
"type": "base64/jpeg",
"data": "data:image/jpeg;base64,..."
},
{
"type": "uri",
"data": "https://i.imgur.com/2dn06CW.png"
}
]
}
So you want to contribute code, that’s great! Here’s a brief overview of the project…
This section is WIP.