Skip to content

Commit

Permalink
chore: add seed script
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmaynes committed Jan 9, 2024
1 parent 74f725d commit e714b9c
Show file tree
Hide file tree
Showing 13 changed files with 1,305 additions and 11 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -42,10 +42,15 @@ deploy_cloudflare_page:

deploy: install build ensure_cloudflare_infra_exists deploy_cloudflare_page

seed:
node ./script/seed.js \
--cloudflare-kv-binding-id "5df82e748f494385a2aeaf2912cbb359" \
--seed-file "./data/seed.json"

clean:
rm -rf .next/ .vercel/ build/

define add_cloudflare_secret
chmod +x ./script/cloudflare/ensure-cloudflare-secret-exists.sh
./script/cloudflare/ensure-cloudflare-secret-exists.sh "$(1)" "$(2)" "$(3)"
endef
endef
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -26,4 +26,9 @@ make test
To deploy the application, run the following command:
```bash
make deploy
```

To seed the database, run the following command:
```bash
make seed
```
46 changes: 46 additions & 0 deletions data/seed.json
@@ -0,0 +1,46 @@
{
"last_updated_timestamp": "2024-01-09T06:40:41.346Z",
"length": 10,
"data": [
{
"imageClass": "tench, Tinca tinca",
"description": "A tench, scientifically known as Tinca tinca, is a freshwater fish species that belongs to the family Cyprinidae. It is native to Europe and parts of Asia. Tench have a slender and elongated body covered in dark green or olive-colored scales. They have a pair of barbels near their mouth that helps them detect food in the muddy bottom of lakes and slow-flowing rivers. Tench prefer slow-moving or stagnant waters with lots of vegetation and mud. They can tolerate low oxygen levels and are known for their ability to survive in heavily fertilized and eutrophic waters. Tench are mostly known for their bottom-feeding habit, primarily feeding on worms, insects, snails, aquatic plants, and detritus.These fish are popular among anglers due to their challenging nature and strong fighting ability when hooked. Tench can grow up to around 3-4 pounds in weight and live for up to 15-20 years. They are also occasionally stocked in fishing ponds and lakes for recreational fishing."
},
{
"imageClass": "goldfish, Carassius auratus",
"description": "A goldfish, Carassius auratus, is a freshwater fish species that is commonly kept as a pet. It belongs to the carp family, Cyprinidae, and is native to East Asia. Goldfish are known for their vibrant colors and long, flowing fins. They have been selectively bred for centuries to create a wide variety of color patterns and body shapes. Goldfish are typically small in size, with the average adult reaching about 6 to 8 inches (15 to 20 centimeters) in length, although some varieties can grow larger. They are peaceful and social animals that can be kept in aquariums or outdoor ponds. Goldfish are also popular as decorative fish in ornamental ponds and water gardens."
},
{
"imageClass": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",
"description": "A great white shark (Carcharodon carcharias) is a species of shark known for its large size and powerful jaws. It is one of the most recognized and feared predators in the ocean. Great white sharks are characterized by their grayish-white body coloration, a streamlined shape, and rows of sharp, serrated teeth. They inhabit coastal and offshore waters around the world, predominantly in temperate and cooler regions. Great white sharks are apex predators, meaning they are at the top of the ocean food chain. While they primarily feed on marine mammals such as seals and sea lions, they are opportunistic and may occasionally attack humans, leading to the terms 'man-eater' or 'man-eating shark.' However, such instances are rare, with the majority of encounters being non-fatal."
},
{
"imageClass": "tiger shark, Galeocerdo cuvieri",
"description": "A tiger shark, scientifically known as Galeocerdo cuvieri, is a large and highly adaptable species of shark found in tropical and subtropical waters around the world. It is named for the characteristic dark, vertical stripes along its body, which resemble the pattern of a tiger. Tiger sharks are known for their voracious appetite and are often referred to as 'garbage cans of the sea' due to their reputation as opportunistic predators.Tiger sharks have a broad, stout body and can grow up to 16 feet in length, weighing over 1,400 pounds. They have a unique set of serrated, triangular teeth which help them to prey on a wide range of marine animals, including fish, sea turtles, seals, dolphins, and even other sharks. They are known to be curious and have been found with a variety of objects in their stomachs, earning them another nickname, 'wastebaskets of the sea.'These sharks have excellent senses, including a keen sense of smell and excellent vision. They are known for their ability to migrate long distances and inhabit various marine habitats, from shallow coastal waters to deep oceanic regions. Tiger sharks are also known for being both solitary and social animals, depending on the circumstances.While tiger sharks are apex predators, they also face various threats. Overfishing, habitat degradation, pollution, and accidental capture in fishing gear are some of the major challenges they confront. Conservation efforts are aimed at protecting their populations and the overall health of marine ecosystems."
},
{
"imageClass": "hammerhead, hammerhead shark",
"description": "A hammerhead shark, often referred to as just 'hammerhead,' is a type of shark known for its distinctive head shape. The head of a hammerhead shark is flattened and broadened, forming a structure called a cephalofoil, which resembles a hammer or a 'T' shape. This unique head design provides the shark with several advantages, such as enhanced vision and improved maneuverability.The hammerhead, hammerhead shark you mentioned seems to be a repetition of the term 'hammerhead' in its name. There is no specific species called the 'hammerhead, hammerhead shark.' However, there are several different species of hammerhead sharks, such as the Great Hammerhead, Scalloped Hammerhead, and Smooth Hammerhead, among others. Each species varies in size, behavior, and distribution, but they share the characteristic hammer-shaped head."
},
{
"imageClass": "electric ray, crampfish, numbfish, torpedo",
"description": "An electric ray, crampfish, numbfish, or torpedo is a type of fish that belongs to the family Torpedinidae. These rays are known for their ability to produce an electric discharge, which they use primarily for defense and stunning prey. They have specialized electric organs located on either side of their heads. When threatened or when hunting, electric rays can generate a strong electric shock that can immobilize or deter other animals.Electric rays have a flattened body and typically dwell on the seafloor in coastal waters. They are capable of delivering an electric shock ranging from a few volts to several hundred volts, depending on the species. This electric shock is not fatal to humans but can cause discomfort or muscle spasms.It's important to note that electric rays are distinct from the more well-known stingrays that use venomous spines for defense rather than electric shocks."
},
{
"imageClass": "stingray",
"description": "A stingray is a type of marine fish that belongs to the same family as sharks. They have a flattened body with a long, whip-like tail that has a barbed stinger at the end. Stingrays use their stingers for self-defense when they feel threatened. These creatures are typically found in warm, shallow coastal waters around the world. They have a unique and fascinating appearance, often with a round or diamond-shaped body and distinctive patterns on their backs. Stingrays are known for their graceful swimming motion, gliding through the water by flapping their wing-like pectoral fins."
},
{
"imageClass": "cock",
"description": "A 'cock' is a colloquial term used to refer to a rooster, which is a male chicken. The term can also be used informally to refer to the male organ of certain animals, particularly in reference to the male reproductive organ of a chicken. It's important to note that this term can be considered vulgar or offensive when applied to humans."
},
{
"imageClass": "hen",
"description": "A hen is an adult female chicken. Chickens are domesticated birds that are typically raised for meat and eggs. Hens are known to lay eggs, making them an important source of food for humans. They are also social creatures and often live in flocks."
},
{
"imageClass": "ostrich, Struthio camelus",
"description": "An ostrich, scientifically known as Struthio camelus, is a large flightless bird native to Africa. It is the largest living bird species, characterized by its long neck, long legs, and distinctive feathers. Ostriches are known for their ability to run at high speeds, making them the fastest birds on land. They have strong legs with two toes, where each foot has a powerful claw used for defense and attack. Ostriches have a unique feature in the avian world—they have the largest eyes of any land vertebrate, measuring around 2 inches (5 centimeters) in diameter. They primarily inhabit the savannas and desert regions of Africa and are well-adapted to survive in arid environments. Ostriches are also known for their reproductive behaviors, such as communal nesting, where multiple females lay eggs in a single nest. They have been domesticated in some parts of the world for their meat, feathers, and leather."
}
]
}
28 changes: 23 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,7 +20,6 @@
"@tensorflow-models/mobilenet": "^2.1.1",
"@tensorflow/tfjs": "^4.13.0",
"next": "^14.0.3",
"openai": "^4.19.1",
"react": "^18",
"react-dom": "^18"
},
Expand All @@ -37,6 +36,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-next-on-pages": "^1.8.2",
"eslint-plugin-prettier": "^5.0.1",
"openai": "^4.24.1",
"prettier": "^3.1.1",
"sass": "^1.69.6",
"sharp": "^0.32.6",
Expand Down
40 changes: 40 additions & 0 deletions script/cloudflare/add-cloudflare-kv-value.sh
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e

CLOUDFLARE_KV_BINDING_ID=$1
CLOUDFLARE_KV_KEY=$2
CLOUDFLARE_KV_VALUE=$3

function check_requirements() {
if [[ -z "$(command -v node)" ]]; then
echo "Please install 'node' program before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_ACCOUNT_ID" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_ACCOUNT_ID' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_API_TOKEN' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_KV_BINDING_ID" ]]; then
echo "Arg 1 for script 'CLOUDFLARE_KV_BINDING_ID' was not given..."
exit 1
elif [[ -z "$CLOUDFLARE_KV_KEY" ]]; then
echo "Arg 2 for script 'CLOUDFLARE_KV_KEY' was not given..."
exit 1
elif [[ -z "$CLOUDFLARE_KV_VALUE" ]]; then
echo "Arg 3 for script 'CLOUDFLARE_KV_VALUE' was not given..."
exit 1
fi
}

function main() {
check_requirements

if ! ./node_modules/.bin/wrangler kv:key get "$CLOUDFLARE_KV_KEY" --namespace-id="$CLOUDFLARE_KV_BINDING_ID" > /dev/null 2>&1; then
echo "Adding Cloudflare KV key '$CLOUDFLARE_KV_KEY' and value '$CLOUDFLARE_KV_VALUE' to KV '$CLOUDFLARE_KV_NAME'..."
./node_modules/.bin/wrangler kv:key put "$CLOUDFLARE_KV_KEY" "$CLOUDFLARE_KV_VALUE" --namespace-id="$CLOUDFLARE_KV_BINDING_ID"
fi
}

main
2 changes: 1 addition & 1 deletion script/cloudflare/cloudflare-page-deploy.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-kv-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-pages-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion script/cloudflare/ensure-cloudflare-secret-exists.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

Expand Down

0 comments on commit e714b9c

Please sign in to comment.