Compare commits
10 Commits
430892a512
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a4cfeb8496 | |||
| 17d4dca0c9 | |||
| d947557373 | |||
| 4418e009e0 | |||
| edaf4583a0 | |||
| 7e5baa96e8 | |||
| 6f78073431 | |||
| 955ac89c1a | |||
| 1786100052 | |||
| 34d1088d9d |
@@ -28,3 +28,5 @@ htmlcov/
|
||||
.coverage
|
||||
.coverage.*
|
||||
*,cover
|
||||
tmp/
|
||||
docker.env
|
||||
@@ -3,10 +3,13 @@
|
||||
All notable change notes in this project will be documented in this file.
|
||||
|
||||
## [0.1.0-2] - 2023-04-09
|
||||
|
||||
### Changed
|
||||
|
||||
- `docker-compose.yml`: Changed the volume path for the `init.sql` file:
|
||||
- From: `./schema.sql:/docker-entrypoint-initdb.d/schema.sql`
|
||||
- To: `./init.sql:/docker-entrypoint-initdb.d/init.sql`
|
||||
|
||||
### Removed
|
||||
|
||||
- `docker/schema.sql`: The file has been removed. The schema configuration has been moved to the `init.sql` file.
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
GO ?= go
|
||||
GOFMT ?= gofmt "-s"
|
||||
GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
||||
PACKAGES ?= $(shell $(GO) list ./...)
|
||||
VETPACKAGES ?= $(shell $(GO) list ./...)
|
||||
GOFILES := $(shell find . -name "*.go")
|
||||
CORE_DIR := ./core
|
||||
UI_DIR := ./ui
|
||||
DOCS_DIR := ./docs
|
||||
LIBRARIES_DIR := ./../libraries
|
||||
PG_VERSION := 16.4-alpine3.20
|
||||
DB_NAME := rating
|
||||
MOD_NAME := rating-orama
|
||||
|
||||
.PHONY: sayhello
|
||||
# Print Hello World
|
||||
sayhello:
|
||||
@echo "Hello World"
|
||||
|
||||
.PHONY: dockerize
|
||||
# Creates a development database.
|
||||
dockerize:
|
||||
docker run --name $(DB_NAME)-db-dev -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=developer -e POSTGRES_DB=$(DB_NAME) -p 5432:5432 -d postgres:$(PG_VERSION)
|
||||
|
||||
.PHONY: dockerize-test
|
||||
# Creates a test database.
|
||||
dockerize-test:
|
||||
docker run --name $(DB_NAME)-db-test -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=developer -e POSTGRES_DB=$(DB_NAME) -p 5433:5432 -d postgres:$(PG_VERSION)
|
||||
|
||||
.PHONY: undockerize
|
||||
# Destroy a development database.
|
||||
undockerize:
|
||||
docker rm -f $(DB_NAME)-db-dev
|
||||
|
||||
.PHONY: undockerize-test
|
||||
# Destroy a test database.
|
||||
undockerize-test:
|
||||
docker rm -f $(DB_NAME)-db-test
|
||||
|
||||
.PHONY: restart-db
|
||||
# Restart a development database.
|
||||
restart-db:
|
||||
make undockerize
|
||||
make dockerize
|
||||
|
||||
.PHONY: restart-db-test
|
||||
# Restart a test database.
|
||||
restart-db-test:
|
||||
make undockerize-test
|
||||
make dockerize-test
|
||||
|
||||
.PHONY: migrateup
|
||||
# Migrate all schemas, triggers and data located in database/migrations.
|
||||
migrateup:
|
||||
migrate -path $(CORE_DIR)/cmd/database/migrations -database "postgresql://developer:secret@localhost:5432/$(DB_NAME)?sslmode=disable" -verbose up
|
||||
|
||||
.PHONY: migratedown
|
||||
# Migrate all schemas, triggers and data located in database/migrations.
|
||||
migratedown:
|
||||
migrate -path $(CORE_DIR)/cmd/database/migrations -database "postgresql://developer:secret@localhost:5432/$(DB_NAME)?sslmode=disable" -verbose down
|
||||
|
||||
.PHONY: pg-dump
|
||||
# Dump database to file.
|
||||
pg-dump:
|
||||
docker exec -e PGPASSWORD=secret $(DB_NAME)-db-dev pg_dump -U developer --column-inserts --data-only $(DB_NAME) > $(CORE_DIR)/cmd/database/data/data.sql
|
||||
sed -i '1iSET session_replication_role = '\''replica'\'';' $(CORE_DIR)/cmd/database/data/data.sql
|
||||
sed -i '$$aSET session_replication_role = '\''origin'\'';' $(CORE_DIR)/cmd/database/data/data.sql
|
||||
|
||||
.PHONY: pg-restore
|
||||
# Restore database from file.
|
||||
pg-restore:
|
||||
docker cp $(CORE_DIR)/cmd/database/data/data.sql $(DB_NAME)-db-dev:/data.sql
|
||||
docker exec -e PGPASSWORD=secret $(DB_NAME)-db-dev psql -U developer -d $(DB_NAME) -f data.sql
|
||||
|
||||
.PHONY: pg-docs
|
||||
# Generate docs from database.
|
||||
pg-docs:
|
||||
java -jar $(LIBRARIES_DIR)/schemaspy-6.2.4.jar -t pgsql -dp $(LIBRARIES_DIR)/postgresql-42.7.4.jar -db $(DB_NAME) -host localhost -port 5432 -u developer -p secret -o $(DOCS_DIR)/database -vizjs
|
||||
|
||||
.PHONY: sqlc
|
||||
# Generate or recreate SQLC queries.
|
||||
sqlc:
|
||||
cd $(CORE_DIR) && sqlc generate
|
||||
|
||||
.PHONY: test
|
||||
# Test all files and generate coverage file.
|
||||
test:
|
||||
cd $(CORE_DIR) && $(GO) test ./... -v -covermode=count -coverprofile=./benchmark/coverage.out $(PACKAGES)
|
||||
|
||||
.PHONY: gomock
|
||||
# Generate mock files.
|
||||
gomock:
|
||||
cd $(CORE_DIR) && mockgen -package mock -destination internal/repository/mock/querier.go $(MOD_NAME)/internal/repository ExtendedQuerier
|
||||
|
||||
.PHONY: run
|
||||
# Run project.
|
||||
run:
|
||||
cd $(CORE_DIR) && $(GO) run ./cmd/.
|
||||
|
||||
.PHONY: bench
|
||||
# Run benchmarks.
|
||||
bench:
|
||||
cd $(CORE_DIR) && test -f benchmark/new_benchmark.txt && mv benchmark/new_benchmark.txt benchmark/old_benchmark.txt || true
|
||||
cd $(CORE_DIR) && $(GO) test ./... -bench=. -count=10 -benchmem > benchmark/new_benchmark.txt
|
||||
cd $(CORE_DIR) && benchstat benchmark/old_benchmark.txt benchmark/new_benchmark.txt > benchmark/benchstat.txt
|
||||
|
||||
.PHONY: recreate
|
||||
# Destroy development DB and generate ones.
|
||||
recreate:
|
||||
echo "y" | make migratedown
|
||||
make migrateup
|
||||
|
||||
.PHONY: tidy
|
||||
# Runs a go mod tidy
|
||||
tidy:
|
||||
cd $(CORE_DIR) && $(GO) mod tidy
|
||||
|
||||
.PHONY: build-linux
|
||||
# Build and generate linux executable.
|
||||
build-linux:
|
||||
cd $(CORE_DIR) && go mod tidy
|
||||
cd $(CORE_DIR) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./tmp/$(MOD_NAME) ./cmd/.
|
||||
|
||||
|
||||
|
||||
.PHONY: pack-docker
|
||||
# Run docker build for pack binary and assets to Docker container.
|
||||
pack-docker:
|
||||
make build-linux
|
||||
cd $(CORE_DIR) && docker build -t $(MOD_NAME):${version} -t $(MOD_NAME):latest .
|
||||
|
||||
.PHONY: remove-debug
|
||||
# Remove all debug entries for reduce size binary.
|
||||
remove-debug:
|
||||
cd $(CORE_DIR) && find . -name "*.go" -type f -exec sed -i '/slog\.Debug/d' {} +
|
||||
|
||||
.PHONY: fmt
|
||||
# Ensure consistent code formatting.
|
||||
fmt:
|
||||
cd $(CORE_DIR) && $(GOFMT) -w $(GOFILES)
|
||||
|
||||
.PHONY: fmt-check
|
||||
# format (check only).
|
||||
fmt-check:
|
||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||
if [ -n "$$diff" ]; then \
|
||||
echo "Please run 'make fmt' and commit the result:"; \
|
||||
echo "$${diff}"; \
|
||||
exit 1; \
|
||||
fi;
|
||||
|
||||
.PHONY: vet
|
||||
# Examine packages and report suspicious constructs if any.
|
||||
vet:
|
||||
cd $(CORE_DIR) && $(GO) vet $(VETPACKAGES)
|
||||
|
||||
.PHONY: tools
|
||||
# Install tools (migrate and sqlc).
|
||||
tools:
|
||||
@if [ $(GO_VERSION) -gt 16 ]; then \
|
||||
cd $(CORE_DIR) && $(GO) install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest; \
|
||||
cd $(CORE_DIR) && $(GO) install github.com/sqlc-dev/sqlc/cmd/sqlc@latest; \
|
||||
fi
|
||||
|
||||
.PHONY: env
|
||||
# Copy .env.example to .env if .env does not already exist
|
||||
env:
|
||||
cd $(CORE_DIR) && @if [ ! -f .env ]; then \
|
||||
cp .env.example .env; \
|
||||
echo ".env file created from .env.example"; \
|
||||
else \
|
||||
echo ".env file already exists"; \
|
||||
fi
|
||||
|
||||
|
||||
.PHONY: first-run
|
||||
# Runs for the first time
|
||||
first-run:
|
||||
make tools
|
||||
make env
|
||||
make recreate
|
||||
make run
|
||||
|
||||
.PHONY: help
|
||||
# Help.
|
||||
help:
|
||||
@echo ''
|
||||
@echo 'Usage:'
|
||||
@echo ' make [target]'
|
||||
@echo ''
|
||||
@echo 'Targets:'
|
||||
@awk '/^[a-zA-Z\-\0-9]+:/ { \
|
||||
helpMessage = match(lastLine, /^# (.*)/); \
|
||||
if (helpMessage) { \
|
||||
helpCommand = substr($$1, 0, index($$1, ":")-1); \
|
||||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
|
||||
printf " - \033[36m%-20s\033[0m %s\n", helpCommand, helpMessage; \
|
||||
} \
|
||||
} \
|
||||
{ lastLine = $$0 }' $(MAKEFILE_LIST)
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
@@ -4,8 +4,8 @@ Rating Orama is a web application for displaying TV show ratings and statistics.
|
||||
It is composed of 2 main parts:
|
||||
|
||||
1. **Core**: Written in Go and Fiber, responsible for orchestrating everything
|
||||
and displaying the data using a template engine.
|
||||
3. **Database**: PostgreSQL for storing data.
|
||||
and displaying the data using a template engine.
|
||||
2. **Database**: PostgreSQL for storing data.
|
||||
|
||||
## Running the project
|
||||
|
||||
@@ -14,7 +14,7 @@ building the Dockerfile and running it using Docker Compose. Here's an example
|
||||
of the `docker-compose.yml` file for the latter option:
|
||||
|
||||
```yaml
|
||||
version: '3'
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
core:
|
||||
|
||||
@@ -3,3 +3,15 @@ MIGRATE=true
|
||||
DATASOURCE=postgresql://developer:secret@localhost:5432/db?sslmode=disable
|
||||
ASYMMETRICKEY=
|
||||
DURATION=
|
||||
|
||||
# scraper
|
||||
TITLE_SELECTOR=
|
||||
SEASON_SELECTOR=
|
||||
EPISODE_CARD_SELECTOR=
|
||||
SEASON_EPISODE_AND_TITLE_SELECTOR=
|
||||
RELEASED_DATE_SELECTOR=
|
||||
PLOT_SELECTOR=
|
||||
STAR_RATING_SELECTOR=
|
||||
VOTE_COUNT_SELECTOR=
|
||||
IMDB_EPISODES_URL=
|
||||
VISIT_URL=
|
||||
+2
-3
@@ -2,7 +2,6 @@ FROM alpine:3.20
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./database ./database
|
||||
COPY ./tmp/rating .
|
||||
COPY ../tmp/rating-orama .
|
||||
|
||||
CMD ["/app/rating"]
|
||||
CMD ["/app/rating-orama"]
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
GO ?= go
|
||||
GOFMT ?= gofmt "-s"
|
||||
GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
||||
PACKAGES ?= $(shell $(GO) list ./...)
|
||||
VETPACKAGES ?= $(shell $(GO) list ./...)
|
||||
GOFILES := $(shell find . -name "*.go")
|
||||
|
||||
.PHONY: sayhello
|
||||
# Print Hello World
|
||||
sayhello:
|
||||
@echo "Hello World"
|
||||
|
||||
.PHONY: dockerize
|
||||
# Creates a development database.
|
||||
dockerize:
|
||||
docker run --name rating-db-dev -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=developer -e POSTGRES_DB=rating -p 5432:5432 -d postgres:16.3-alpine3.20
|
||||
|
||||
.PHONY: undockerize
|
||||
# Destroy a development database.
|
||||
undockerize:
|
||||
docker rm -f rating-db-dev
|
||||
|
||||
.PHONY: migrateup
|
||||
# Migrate all schemas, triggers and data located in cmd/database/migrations.
|
||||
migrateup:
|
||||
migrate -path cmd/database/migrations -database "postgresql://developer:secret@localhost:5432/rating?sslmode=disable" -verbose up
|
||||
|
||||
.PHONY: sqlc
|
||||
# Generate or recreate SQLC queries.
|
||||
sqlc:
|
||||
sqlc generate
|
||||
|
||||
.PHONY: test
|
||||
# Test all files and generate coverage file.
|
||||
test:
|
||||
$(GO) test -v -covermode=count -coverprofile=coverage.out $(PACKAGES)
|
||||
|
||||
.PHONY: gomock
|
||||
# Generate mock files.
|
||||
gomock:
|
||||
mockgen -package mock -destination internal/repository/mock/querier.go rating-orama/internal/repository ExtendedQuerier
|
||||
|
||||
.PHONY: run
|
||||
# Run project.
|
||||
run:
|
||||
$(GO) run ./cmd/.
|
||||
|
||||
.PHONY: recreate
|
||||
# Destroy development DB and generate ones.
|
||||
recreate:
|
||||
make undockerize
|
||||
make dockerize
|
||||
sleep 2
|
||||
make migrateup
|
||||
|
||||
.PHONY: tidy
|
||||
# Runs a go mod tidy
|
||||
tidy:
|
||||
$(GO) mod tidy
|
||||
|
||||
.PHONY: build-linux
|
||||
# Build and generate linux executable.
|
||||
build-linux:
|
||||
make tidy
|
||||
make remove-debug
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./tmp/arena ./cmd/.
|
||||
|
||||
.PHONY: pack-docker
|
||||
# Run docker build for pack binary and assets to Docker container.
|
||||
pack-docker:
|
||||
make test
|
||||
make build-linux
|
||||
docker build -t rating-orama:${version} -t rating-orama:latest .
|
||||
|
||||
.PHONY: remove-debug
|
||||
# Remove all debug entries for reduce size binary.
|
||||
remove-debug:
|
||||
find . -name "*.go" -type f -exec sed -i '/slog\.Debug/d' {} +
|
||||
|
||||
.PHONY: fmt
|
||||
# Ensure consistent code formatting.
|
||||
fmt:
|
||||
$(GOFMT) -w $(GOFILES)
|
||||
|
||||
.PHONY: fmt-check
|
||||
# format (check only).
|
||||
fmt-check:
|
||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||
if [ -n "$$diff" ]; then \
|
||||
echo "Please run 'make fmt' and commit the result:"; \
|
||||
echo "$${diff}"; \
|
||||
exit 1; \
|
||||
fi;
|
||||
|
||||
.PHONY: vet
|
||||
# Examine packages and report suspicious constructs if any.
|
||||
vet:
|
||||
$(GO) vet $(VETPACKAGES)
|
||||
|
||||
.PHONY: tools
|
||||
# Install tools (migrate and sqlc).
|
||||
tools:
|
||||
@if [ $(GO_VERSION) -gt 16 ]; then \
|
||||
$(GO) install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest; \
|
||||
$(GO) install github.com/sqlc-dev/sqlc/cmd/sqlc@latest; \
|
||||
fi
|
||||
|
||||
.PHONY: env
|
||||
# Copy .env.example to .env if .env does not already exist
|
||||
env:
|
||||
@if [ ! -f .env ]; then \
|
||||
cp .env.example .env; \
|
||||
echo ".env file created from .env.example"; \
|
||||
else \
|
||||
echo ".env file already exists"; \
|
||||
fi
|
||||
|
||||
|
||||
.PHONY: first-run
|
||||
# Runs for the first time
|
||||
first-run:
|
||||
make tools
|
||||
make env
|
||||
make recreate
|
||||
make run
|
||||
|
||||
.PHONY: help
|
||||
# Help.
|
||||
help:
|
||||
@echo ''
|
||||
@echo 'Usage:'
|
||||
@echo ' make [target]'
|
||||
@echo ''
|
||||
@echo 'Targets:'
|
||||
@awk '/^[a-zA-Z\-\0-9]+:/ { \
|
||||
helpMessage = match(lastLine, /^# (.*)/); \
|
||||
if (helpMessage) { \
|
||||
helpCommand = substr($$1, 0, index($$1, ":")-1); \
|
||||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
|
||||
printf " - \033[36m%-20s\033[0m %s\n", helpCommand, helpMessage; \
|
||||
} \
|
||||
} \
|
||||
{ lastLine = $$0 }' $(MAKEFILE_LIST)
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
+24
-13
@@ -3,40 +3,51 @@ package main
|
||||
import (
|
||||
"embed"
|
||||
"encoding/gob"
|
||||
"gopher-toolbox/app"
|
||||
"gopher-toolbox/db"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/template/html/v2"
|
||||
"github.com/zepyrshut/rating-orama/internal/app"
|
||||
"github.com/zepyrshut/rating-orama/internal/handlers"
|
||||
"github.com/zepyrshut/rating-orama/internal/repository"
|
||||
)
|
||||
|
||||
//go:embed database/migrations
|
||||
var database embed.FS
|
||||
|
||||
const version = "0.2.0-beta.20241116-4"
|
||||
const version = "0.2.3-beta.20250128-27"
|
||||
const appName = "rating-orama"
|
||||
|
||||
func init() {
|
||||
gob.Register(map[string]string{})
|
||||
}
|
||||
|
||||
//go:embed database/migrations
|
||||
var database embed.FS
|
||||
|
||||
//go:embed templates
|
||||
var templates embed.FS
|
||||
|
||||
func main() {
|
||||
app := app.New(version)
|
||||
r := fiber.New(fiber.Config{
|
||||
engine := html.NewFileSystem(http.FS(templates), ".html")
|
||||
engine.Directory = "templates"
|
||||
|
||||
app := app.NewExtendedApp(appName, version, ".env")
|
||||
app.Migrate(database)
|
||||
f := fiber.New(fiber.Config{
|
||||
AppName: appName,
|
||||
Views: engine,
|
||||
})
|
||||
|
||||
dbPool := db.NewPGXPool(app.Database.DataSource)
|
||||
defer dbPool.Close()
|
||||
pgxPool := db.NewPGXPool(app.Database.DataSource)
|
||||
defer pgxPool.Close()
|
||||
|
||||
q := repository.NewPGXRepo(dbPool)
|
||||
h := handlers.New(app, q)
|
||||
router(h, r)
|
||||
r := repository.NewPGXRepo(pgxPool, app)
|
||||
h := handlers.New(r, app)
|
||||
router(h, f)
|
||||
|
||||
slog.Info("server started", "port", "8080", "version", version)
|
||||
if err := r.Listen(":8080"); err != nil {
|
||||
err := f.Listen(":8080")
|
||||
if err != nil {
|
||||
slog.Error("cannot start server", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
func router(h *handlers.Handlers, r *fiber.App) {
|
||||
|
||||
r.Get("/", h.GetIndex)
|
||||
r.Get("/tvshow", h.GetTVShow)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<div class="flex flex-col justify-center min-h-screen">
|
||||
<form class="max-w-md mx-auto w-full" action="/tvshow" method="get">
|
||||
<label for="default-search" class="mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white">Buscar</label>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="lucide lucide-search">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
</div>
|
||||
<input type="search" id="default-search"
|
||||
class="block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
||||
placeholder="IMDb ID" required
|
||||
name="ttid"
|
||||
/>
|
||||
<button type="submit"
|
||||
class="text-white absolute end-2.5 bottom-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ .Title }}</title>
|
||||
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
|
||||
</head>
|
||||
|
||||
<body class="min-h-screen bg-slate-50">
|
||||
|
||||
{{ embed }}
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
<footer class="bg-slate-200" aria-label="Site Footer">
|
||||
<ul class="mt-12 flex justify-center gap-6 p-12">
|
||||
<li>
|
||||
<a
|
||||
class="text-slate-700 transition hover:text-slate-700/75"
|
||||
href="https://www.instagram.com/modelektor/"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Instagram</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-instagram"><rect width="20" height="20" x="2" y="2" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" x2="17.51" y1="6.5" y2="6.5"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a
|
||||
class="text-slate-700 transition hover:text-slate-700/75"
|
||||
href="https://github.com/zepyrshut"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">GitHub</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a
|
||||
class="text-slate-700 transition hover:text-slate-700/75"
|
||||
href="https://pedroperez.dev/"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Website</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-globe"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="text-slate-700 transition hover:text-slate-700/75"
|
||||
href="https://github.com/zepyrshut/rating-orama"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Source</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-xml"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</footer>
|
||||
@@ -0,0 +1,334 @@
|
||||
<div class="flex flex-col items-center gap-4 mb-8 p-2">
|
||||
<!-- Card header -->
|
||||
<div class="flex flex-col items-center mt-4 bg-white p-4 rounded-lg shadow-md w-1/2">
|
||||
<div class="flex flex-col items-center space-y-4 w-full">
|
||||
<!-- Title section -->
|
||||
<div class="text-center">
|
||||
<h1 class="text-3xl font-bold text-gray-800">{{ .tvshow.Name }}</h1>
|
||||
<div class="mt-1 flex items-center justify-center space-x-2">
|
||||
<a href="https://www.imdb.com/title/{{ .tvshow.TtImdb }}" target="_blank"
|
||||
class="text-amber-500 hover:text-amber-600 flex items-center space-x-1">
|
||||
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path
|
||||
d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
|
||||
</svg>
|
||||
<span class="font-semibold text-sm">{{ .tvshow.TtImdb }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ratings section -->
|
||||
<div class="grid grid-cols-2 gap-4 w-full">
|
||||
<div class="bg-gray-50 rounded-lg p-2 text-center">
|
||||
<span class="text-xs text-gray-500 uppercase">Average</span>
|
||||
<div class="text-2xl font-bold text-gray-800">{{ printf "%.2f" .avg_rating_show }}</div>
|
||||
</div>
|
||||
<div class="bg-gray-50 rounded-lg p-2 text-center">
|
||||
<span class="text-xs text-gray-500 uppercase">Median</span>
|
||||
<div class="text-2xl font-bold text-gray-800">{{ printf "%.2f" .median_rating_show }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats section -->
|
||||
<div class="flex justify-around w-full px-3 py-2 bg-gray-50 rounded-lg">
|
||||
<div class="text-center">
|
||||
<span class="text-xs text-gray-500">Vote count</span>
|
||||
<div class="text-lg font-bold text-gray-800">{{ .total_vote_count }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<span class="text-xs text-gray-500">Times searched</span>
|
||||
<div class="text-lg font-bold text-gray-800">{{ .tvshow.Popularity }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="w-4/5 mx-6">
|
||||
|
||||
|
||||
<h2 class="mb-6 text-center text-2xl font-bold">Seasons overall</h2>
|
||||
<canvas id="seasons"></canvas>
|
||||
</div>
|
||||
<div class="w-4/5">
|
||||
|
||||
<h2 class="mb-6 text-center text-2xl font-bold">Season <span id="seasonNumber">1</span></h2>
|
||||
<div id="seasonButtons" class="mb-4 flex flex-wrap items-center justify-center gap-2"></div>
|
||||
<canvas id="episodes"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{{ template "partials/footer" . }}
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js"
|
||||
integrity="sha512-ZwR1/gSZM3ai6vCdI+LVF1zSq/5HznD3ZSTk7kajkaj4D292NLuduDCO1c/NT8Id+jE58KYLKT7hXnbtryGmMg=="
|
||||
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script type="module">
|
||||
|
||||
const episodes = JSON.parse("{{ .episodes }}")
|
||||
|
||||
function groupEpisodesBySeason(episodes) {
|
||||
const seasons = {};
|
||||
episodes.forEach(episode => {
|
||||
if (!seasons[episode.season]) {
|
||||
seasons[episode.season] = {
|
||||
number: episode.season,
|
||||
episodes: [],
|
||||
avg_rating: 0,
|
||||
median_rating: 0,
|
||||
votes: 0
|
||||
};
|
||||
}
|
||||
seasons[episode.season].episodes.push({
|
||||
number: episode.episode,
|
||||
title: episode.name,
|
||||
avg_rating: episode.avg_rating,
|
||||
votes: episode.vote_count,
|
||||
aired: episode.released
|
||||
});
|
||||
});
|
||||
|
||||
Object.values(seasons).forEach(season => {
|
||||
const ratings = season.episodes.map(ep => ep.avg_rating);
|
||||
season.avg_rating = ratings.reduce((a, b) => a + b, 0) / ratings.length;
|
||||
season.median_rating = ratings.sort((a, b) => a - b)[Math.floor(ratings.length / 2)];
|
||||
season.votes = season.episodes.reduce((sum, ep) => sum + ep.votes, 0);
|
||||
});
|
||||
|
||||
return {
|
||||
seasons: Object.values(seasons).sort((a, b) => a.number - b.number)
|
||||
};
|
||||
}
|
||||
|
||||
function createSeasonButtons() {
|
||||
const maxSeason = Math.max(...episodes.map(ep => ep.season));
|
||||
const buttonContainer = document.getElementById('seasonButtons');
|
||||
const seasonNumberSpan = document.getElementById('seasonNumber');
|
||||
|
||||
for (let i = 1; i <= maxSeason; i++) {
|
||||
const button = document.createElement('button');
|
||||
button.textContent = `S${i}`;
|
||||
button.className = 'rounded-md border-2 border-black px-4 py-2 font-semibold transition-colors duration-200 hover:bg-black hover:text-white';
|
||||
if (i === 1) button.classList.add('bg-black', 'text-white');
|
||||
|
||||
button.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
buttonContainer.querySelectorAll('button').forEach(btn => {
|
||||
btn.classList.remove('bg-black', 'text-white');
|
||||
btn.classList.add('text-black');
|
||||
});
|
||||
|
||||
button.classList.remove('text-black');
|
||||
button.classList.add('bg-black', 'text-white');
|
||||
|
||||
seasonNumberSpan.textContent = i;
|
||||
|
||||
const formattedData = groupEpisodesBySeason(episodes);
|
||||
loadSpecificSeason(formattedData, i);
|
||||
});
|
||||
|
||||
buttonContainer.appendChild(button);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const formattedData = groupEpisodesBySeason(episodes);
|
||||
initCharts(formattedData);
|
||||
createSeasonButtons();
|
||||
});
|
||||
|
||||
function loadSeason(seasonNumber) {
|
||||
const formattedData = groupEpisodesBySeason(episodes);
|
||||
loadSpecificSeason(formattedData, seasonNumber);
|
||||
}
|
||||
|
||||
function initCharts(tvShowParsed) {
|
||||
new EpisodeChart(tvShowParsed, "episodes", 0);
|
||||
new SeasonsChart(tvShowParsed, "seasons");
|
||||
}
|
||||
|
||||
function loadSpecificSeason(tvShowParsed, seasonId) {
|
||||
// Guardamos la posición actual del scroll
|
||||
const currentScroll = window.scrollY;
|
||||
|
||||
new EpisodeChart(tvShowParsed, "episodes", seasonId - 1);
|
||||
|
||||
// Restauramos la posición del scroll
|
||||
window.scrollTo(0, currentScroll);
|
||||
}
|
||||
|
||||
|
||||
let chartInstance;
|
||||
class SeasonsChart {
|
||||
constructor(tvShowParsed, canvasId) {
|
||||
this.tvShowParsed = tvShowParsed;
|
||||
this.canvasId = canvasId;
|
||||
this.createChart();
|
||||
}
|
||||
|
||||
createChart() {
|
||||
const seasons = this.tvShowParsed.seasons;
|
||||
const labels = seasons.map((season) => `Season ${season.number}`);
|
||||
const averageRating = seasons.map((season) => season.avg_rating);
|
||||
const medianRating = seasons.map((season) => season.median_rating);
|
||||
const votes = seasons.map((season) => season.votes);
|
||||
const title = "Seasons"
|
||||
const ctx = document.getElementById(this.canvasId);
|
||||
|
||||
new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Average rating",
|
||||
data: averageRating,
|
||||
backgroundColor: "rgba(75, 192, 192, 0.5)",
|
||||
borderColor: "rgba(75, 192, 192, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
},
|
||||
{
|
||||
label: "Median rating",
|
||||
data: medianRating,
|
||||
backgroundColor: "rgba(255, 206, 86, 0.5)",
|
||||
borderColor: "rgba(255, 206, 86, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
|
||||
},
|
||||
{
|
||||
label: "Votes",
|
||||
data: votes,
|
||||
type: "line",
|
||||
tension: 0.4,
|
||||
fill: false,
|
||||
borderColor: "rgba(255, 99, 132, 1)",
|
||||
borderWidth: 2,
|
||||
yAxisID: "y-axis-votes",
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
animation: {
|
||||
duration: 0,
|
||||
},
|
||||
y: {
|
||||
stacked: true,
|
||||
},
|
||||
scales: {
|
||||
"y-axis-ratings": {
|
||||
min: 0,
|
||||
max: 10,
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "left",
|
||||
beginAtZero: true,
|
||||
},
|
||||
"y-axis-votes": {
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "right",
|
||||
beginAtZero: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
title: {
|
||||
display: true,
|
||||
text: title,
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class EpisodeChart {
|
||||
constructor(tvShowParsed, canvasId, seasonId) {
|
||||
this.tvShowParsed = tvShowParsed;
|
||||
this.canvasId = canvasId;
|
||||
this.seasonId = seasonId;
|
||||
this.createChart();
|
||||
}
|
||||
|
||||
createChart() {
|
||||
if (chartInstance) {
|
||||
chartInstance.destroy();
|
||||
}
|
||||
|
||||
const episodes = this.tvShowParsed.seasons[this.seasonId].episodes;
|
||||
const labels = episodes.map((episode) => `Ep. ${episode.number}`);
|
||||
const ratings = episodes.map((episode) => episode.avg_rating);
|
||||
const votes = episodes.map((episode) => episode.votes);
|
||||
const title = `Episodes of season ${this.seasonId + 1}`
|
||||
const ctx = document.getElementById(this.canvasId);
|
||||
|
||||
chartInstance = new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Average rating",
|
||||
data: ratings,
|
||||
backgroundColor: "rgba(75, 192, 192, 0.5)",
|
||||
borderColor: "rgba(75, 192, 192, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
},
|
||||
{
|
||||
label: "Votes",
|
||||
data: votes,
|
||||
type: "line",
|
||||
tension: 0.4,
|
||||
fill: false,
|
||||
borderColor: "rgba(255, 99, 132, 1)",
|
||||
borderWidth: 2,
|
||||
yAxisID: "y-axis-votes",
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
animation: {
|
||||
duration: 0,
|
||||
},
|
||||
scales: {
|
||||
"y-axis-ratings": {
|
||||
min: 0,
|
||||
max: 10,
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "left",
|
||||
beginAtZero: true,
|
||||
},
|
||||
"y-axis-votes": {
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "right",
|
||||
beginAtZero: true,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
title: function (context) {
|
||||
const index = context[0].dataIndex;
|
||||
const episode = episodes[index];
|
||||
return `${episode.title} (${episode.aired.split("T")[0]})`;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -1,28 +0,0 @@
|
||||
version: '3'
|
||||
|
||||
// TODO: update docker-compose
|
||||
services:
|
||||
core:
|
||||
container_name: core-ratingorama
|
||||
image: core:0.1.0
|
||||
environment:
|
||||
DATASOURCE: ${DATASOURCE}
|
||||
HARVESTER_API: ${HARVESTER_API}
|
||||
IS_PRODUCTION: ${IS_PRODUCTION}
|
||||
ports:
|
||||
- "8086:8080"
|
||||
networks:
|
||||
- ratingorama
|
||||
db:
|
||||
container_name: db-ratingorama
|
||||
image: postgres:15.2-alpine
|
||||
environment:
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- ./init.sql:/docker-entrypoint-initdb.d/schema.sql
|
||||
- ./data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- ratingorama
|
||||
|
||||
networks:
|
||||
ratingorama:
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
module github.com/zepyrshut/rating-orama
|
||||
|
||||
go 1.23.2
|
||||
go 1.23.5
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.10.0
|
||||
@@ -18,6 +18,8 @@ require (
|
||||
github.com/antchfx/xpath v1.3.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.5.0 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // indirect
|
||||
github.com/gofiber/template v1.8.3 // indirect
|
||||
github.com/gofiber/utils v1.1.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
@@ -45,6 +47,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/gocolly/colly v1.2.0
|
||||
github.com/gofiber/template/html/v2 v2.1.3
|
||||
github.com/golang-migrate/migrate/v4 v4.18.1 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
@@ -54,7 +57,7 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.19.0 // indirect
|
||||
gopher-toolbox v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
+10
-4
@@ -45,6 +45,12 @@ github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI=
|
||||
github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA=
|
||||
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
|
||||
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
|
||||
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
|
||||
github.com/gofiber/template/html/v2 v2.1.3 h1:n1LYBtmr9C0V/k/3qBblXyMxV5B0o/gpb6dFLp8ea+o=
|
||||
github.com/gofiber/template/html/v2 v2.1.3/go.mod h1:U5Fxgc5KpyujU9OqKzy6Kn6Qup6Tm7zdsISR+VpnHRE=
|
||||
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
|
||||
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang-migrate/migrate/v4 v4.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y=
|
||||
@@ -119,8 +125,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
|
||||
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
@@ -168,8 +174,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"gopher-toolbox/app"
|
||||
)
|
||||
|
||||
type ExtendedApp struct {
|
||||
app.App
|
||||
}
|
||||
|
||||
func NewExtendedApp(appName, version, envDirectory string) *ExtendedApp {
|
||||
app := app.New(appName, version, envDirectory)
|
||||
return &ExtendedApp{
|
||||
App: *app,
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,18 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gopher-toolbox/app"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/zepyrshut/rating-orama/internal/app"
|
||||
"github.com/zepyrshut/rating-orama/internal/repository"
|
||||
)
|
||||
|
||||
type Handlers struct {
|
||||
app *app.App
|
||||
app *app.ExtendedApp
|
||||
queries repository.ExtendedQuerier
|
||||
}
|
||||
|
||||
func New(app *app.App, q repository.ExtendedQuerier) *Handlers {
|
||||
func New(r repository.ExtendedQuerier, app *app.ExtendedApp) *Handlers {
|
||||
return &Handlers{
|
||||
app: app,
|
||||
queries: q,
|
||||
queries: r,
|
||||
}
|
||||
}
|
||||
|
||||
func (hq *Handlers) ToBeImplemented(c *fiber.Ctx) error {
|
||||
return c.Status(http.StatusNotImplemented).JSON("not implemented")
|
||||
}
|
||||
|
||||
func (hq *Handlers) Ping(c *fiber.Ctx) error {
|
||||
return c.JSON("pong")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
@@ -10,18 +11,30 @@ import (
|
||||
"github.com/zepyrshut/rating-orama/internal/sqlc"
|
||||
)
|
||||
|
||||
func (hq *Handlers) GetIndex(c *fiber.Ctx) error {
|
||||
return c.Render("index", fiber.Map{
|
||||
"Title": "Rating Orama",
|
||||
}, "layouts/main")
|
||||
}
|
||||
|
||||
func (hq *Handlers) GetTVShow(c *fiber.Ctx) error {
|
||||
ttShowID := c.Query("ttid")
|
||||
|
||||
if ttShowID == "" {
|
||||
return c.SendStatus(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var title string
|
||||
var scraperEpisodes []scraper.Episode
|
||||
var sqlcTvShow sqlc.TvShow
|
||||
var sqlcEpisodes []sqlc.Episode
|
||||
var totalVoteCount int32
|
||||
|
||||
tvShow, err := hq.queries.CheckTVShowExists(c.Context(), ttShowID)
|
||||
sqlcTvShow, err := hq.queries.CheckTVShowExists(c.Context(), ttShowID)
|
||||
if err != nil {
|
||||
title, scraperEpisodes = scraper.ScrapeEpisodes(ttShowID)
|
||||
// TODO: make transactional
|
||||
ttShow, err := hq.queries.CreateTVShow(c.Context(), sqlc.CreateTVShowParams{
|
||||
//TODO: make transactional
|
||||
sqlcTvShow, err = hq.queries.CreateTVShow(c.Context(), sqlc.CreateTVShowParams{
|
||||
TtImdb: ttShowID,
|
||||
Name: title,
|
||||
})
|
||||
@@ -30,34 +43,69 @@ func (hq *Handlers) GetTVShow(c *fiber.Ctx) error {
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
slog.Info("ttshowid", "id", ttShow.ID)
|
||||
slog.Info("ttshowid", "id", sqlcTvShow.ID)
|
||||
for _, episode := range scraperEpisodes {
|
||||
sqlcEpisodesParams := episode.ToEpisodeParams(ttShow.ID)
|
||||
sqlcEpisodesParams := episode.ToEpisodeParams(sqlcTvShow.ID)
|
||||
sqlcEpisode, err := hq.queries.CreateEpisodes(c.Context(), sqlcEpisodesParams)
|
||||
if err != nil {
|
||||
slog.Error("failed to create episodes", "ttid", ttShowID, "error", err)
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
totalVoteCount += int32(episode.VoteCount)
|
||||
sqlcEpisodes = append(sqlcEpisodes, sqlcEpisode)
|
||||
}
|
||||
|
||||
slog.Info("scraped seasons", "ttid", ttShowID, "title", title)
|
||||
} else {
|
||||
title = tvShow.Name
|
||||
sqlcEpisodes, err = hq.queries.GetEpisodes(c.Context(), tvShow.ID)
|
||||
title = sqlcTvShow.Name
|
||||
sqlcEpisodes, err = hq.queries.GetEpisodes(c.Context(), sqlcTvShow.ID)
|
||||
if err != nil {
|
||||
slog.Error("failed to get episodes", "ttid", ttShowID, "error", err)
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
hq.queries.IncreasePopularity(c.Context(), ttShowID)
|
||||
slog.Info("tv show exists", "ttid", ttShowID, "title", tvShow.Name)
|
||||
for _, episode := range sqlcEpisodes {
|
||||
totalVoteCount += episode.VoteCount
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"popularity": tvShow.Popularity,
|
||||
"title": title,
|
||||
"seasons": sqlcEpisodes,
|
||||
hq.queries.IncreasePopularity(c.Context(), ttShowID)
|
||||
slog.Info("tv show exists", "ttid", ttShowID, "title", sqlcTvShow.Name)
|
||||
}
|
||||
|
||||
episodesJSON, err := json.Marshal(sqlcEpisodes)
|
||||
if err != nil {
|
||||
slog.Error("failed to marshal episodes", "ttid", ttShowID, "error", err)
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
avgRatingShow, err := hq.queries.TvShowAverageRating(c.Context(), sqlcTvShow.ID)
|
||||
if err != nil {
|
||||
slog.Error("failed to calculate avg rating for the show", "ttid", ttShowID, "error", err)
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
medianRatingShow, err := hq.queries.TvShowMedianRating(c.Context(), sqlcTvShow.ID)
|
||||
if err != nil {
|
||||
slog.Error("failed to calculate median rating for the show", "ttid", ttShowID, "error", err)
|
||||
return c.SendStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
seasongAvgRatings, err := hq.queries.SeasonAverageRating(c.Context(), sqlc.SeasonAverageRatingParams{
|
||||
TvShowID: sqlcTvShow.ID,
|
||||
})
|
||||
|
||||
seasonMedianRatings, err := hq.queries.SeasonMedianRating(c.Context(), sqlc.SeasonMedianRatingParams{
|
||||
TvShowID: sqlcTvShow.ID,
|
||||
})
|
||||
|
||||
return c.Render("tvshow", fiber.Map{
|
||||
"Title": sqlcTvShow.Name,
|
||||
"tvshow": sqlcTvShow,
|
||||
"episodes": string(episodesJSON),
|
||||
"avg_rating_show": avgRatingShow,
|
||||
"median_rating_show": medianRatingShow,
|
||||
"season_avg_ratings": seasongAvgRatings,
|
||||
"season_median_ratings": seasonMedianRatings,
|
||||
"total_vote_count": totalVoteCount,
|
||||
}, "layouts/main")
|
||||
}
|
||||
|
||||
@@ -2,39 +2,44 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/zepyrshut/rating-orama/internal/app"
|
||||
"github.com/zepyrshut/rating-orama/internal/sqlc"
|
||||
)
|
||||
|
||||
type pgxRepository struct {
|
||||
*sqlc.Queries
|
||||
db *pgxpool.Pool
|
||||
pool *pgxpool.Pool
|
||||
app *app.ExtendedApp
|
||||
}
|
||||
|
||||
func NewPGXRepo(db *pgxpool.Pool) ExtendedQuerier {
|
||||
var _ ExtendedQuerier = &pgxRepository{}
|
||||
|
||||
func NewPGXRepo(pgx *pgxpool.Pool, app *app.ExtendedApp) ExtendedQuerier {
|
||||
return &pgxRepository{
|
||||
Queries: sqlc.New(db),
|
||||
db: db,
|
||||
Queries: sqlc.New(pgx),
|
||||
pool: pgx,
|
||||
app: app,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *pgxRepository) execTx(ctx context.Context, txFunc func(tx pgx.Tx) error) error {
|
||||
slog.Info("starting transaction", "txFunc", txFunc)
|
||||
tx, err := r.db.Begin(ctx)
|
||||
func (r *pgxRepository) execTx(ctx context.Context, fn func(*sqlc.Queries) error) error {
|
||||
tx, err := r.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
slog.Error("failed to start transaction", "error", err)
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
|
||||
if err := txFunc(tx); err != nil {
|
||||
slog.Error("failed to execute transaction", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Info("committing transaction", "txFunc", txFunc)
|
||||
q := sqlc.New(tx)
|
||||
|
||||
err = fn(q)
|
||||
if err != nil {
|
||||
if rbErr := tx.Rollback(ctx); rbErr != nil {
|
||||
return fmt.Errorf("tx err: %v, rb err: %v", err, rbErr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zepyrshut/rating-orama/internal/scraper"
|
||||
|
||||
"github.com/zepyrshut/rating-orama/internal/scraper"
|
||||
"github.com/zepyrshut/rating-orama/internal/sqlc"
|
||||
)
|
||||
|
||||
type ExtendedQuerier interface {
|
||||
sqlc.Querier
|
||||
CreateTvShowWithEpisodes(ctx context.Context, tvShow sqlc.CreateTVShowParams, episodes []scraper.Episode) ([]sqlc.Episode, error)
|
||||
CreateTvShowWithEpisodesTX(ctx context.Context, tvShow sqlc.CreateTVShowParams, episodes []scraper.Episode) ([]sqlc.Episode, error)
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/zepyrshut/rating-orama/internal/scraper"
|
||||
"github.com/zepyrshut/rating-orama/internal/sqlc"
|
||||
)
|
||||
|
||||
func (r *pgxRepository) CreateTvShowWithEpisodes(ctx context.Context, tvShow sqlc.CreateTVShowParams, episodes []scraper.Episode) ([]sqlc.Episode, error) {
|
||||
var sqlcEpisodes []sqlc.Episode
|
||||
err := r.execTx(ctx, func(tx pgx.Tx) error {
|
||||
qtx := r.WithTx(tx)
|
||||
tvShow, err := qtx.CreateTVShow(ctx, tvShow)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, episode := range episodes {
|
||||
sqlcEpisodeParams := episode.ToEpisodeParams(tvShow.ID)
|
||||
episode, err := qtx.CreateEpisodes(ctx, sqlcEpisodeParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sqlcEpisodes = append(sqlcEpisodes, episode)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return sqlcEpisodes, err
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zepyrshut/rating-orama/internal/scraper"
|
||||
"github.com/zepyrshut/rating-orama/internal/sqlc"
|
||||
)
|
||||
|
||||
func (r *pgxRepository) CreateTvShowWithEpisodesTX(ctx context.Context, tvShow sqlc.CreateTVShowParams, episodes []scraper.Episode) ([]sqlc.Episode, error) {
|
||||
var err error
|
||||
var episodesSqlc []sqlc.Episode
|
||||
|
||||
err = r.execTx(ctx, func(tx *sqlc.Queries) error {
|
||||
tvShow, err := tx.CreateTVShow(ctx, tvShow)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, episode := range episodes {
|
||||
sqlcEpisodeParams := episode.ToEpisodeParams(tvShow.ID)
|
||||
episode, err := tx.CreateEpisodes(ctx, sqlcEpisodeParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
episodesSqlc = append(episodesSqlc, episode)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return episodesSqlc, err
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package scraper
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -43,20 +44,6 @@ func (e Episode) ToEpisodeParams(tvShowID int32) sqlc.CreateEpisodesParams {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
titleSelector = "h2.sc-b8cc654b-9.dmvgRY"
|
||||
seasonsSelector = "ul.ipc-tabs a[data-testid='tab-season-entry']"
|
||||
episodeCardSelector = "article.sc-f8507e90-1.cHtpvn.episode-item-wrapper"
|
||||
seasonEpisodeAndTitleSelector = "div.ipc-title__text"
|
||||
releasedDateSelector = "span.sc-f2169d65-10.bYaARM"
|
||||
plotSelector = "div.ipc-html-content-inner-div"
|
||||
starRatingSelector = "span.ipc-rating-star--rating"
|
||||
voteCountSelector = "span.ipc-rating-star--voteCount"
|
||||
imdbEpisodesURL = "https://www.imdb.com/title/%s/episodes/?season=%d"
|
||||
visitURL = "https://www.imdb.com/title/%s/episodes"
|
||||
)
|
||||
|
||||
|
||||
func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
||||
c := colly.NewCollector(
|
||||
colly.AllowedDomains("imdb.com", "www.imdb.com"),
|
||||
@@ -70,7 +57,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
||||
var seasons []int
|
||||
var title string
|
||||
|
||||
c.OnHTML(seasonsSelector, func(e *colly.HTMLElement) {
|
||||
c.OnHTML(os.Getenv("SEASON_SELECTOR"), func(e *colly.HTMLElement) {
|
||||
seasonText := strings.TrimSpace(e.Text)
|
||||
seasonNum, err := strconv.Atoi(seasonText)
|
||||
if err == nil {
|
||||
@@ -78,7 +65,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
||||
}
|
||||
})
|
||||
|
||||
c.OnHTML(titleSelector, func(e *colly.HTMLElement) {
|
||||
c.OnHTML(os.Getenv("TITLE_SELECTOR"), func(e *colly.HTMLElement) {
|
||||
title = e.Text
|
||||
})
|
||||
|
||||
@@ -103,7 +90,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
||||
})
|
||||
|
||||
for _, seasonNum := range uniqueSeasons {
|
||||
seasonURL := fmt.Sprintf(imdbEpisodesURL, ttImdb, seasonNum)
|
||||
seasonURL := fmt.Sprintf(os.Getenv("IMDB_EPISODES_URL"), ttImdb, seasonNum)
|
||||
slog.Info("visiting season", "url", seasonURL)
|
||||
_ = episodeCollector.Visit(seasonURL)
|
||||
}
|
||||
@@ -111,7 +98,7 @@ func ScrapeEpisodes(ttImdb string) (string, []Episode) {
|
||||
episodeCollector.Wait()
|
||||
})
|
||||
|
||||
_ = c.Visit(fmt.Sprintf(visitURL, ttImdb))
|
||||
_ = c.Visit(fmt.Sprintf(os.Getenv("VISIT_URL"), ttImdb))
|
||||
c.Wait()
|
||||
|
||||
slog.Info("scraped all seasons", "length", len(allSeasons))
|
||||
@@ -126,26 +113,26 @@ func extractEpisodesFromSeason(data string) []Episode {
|
||||
}
|
||||
|
||||
var episodes []Episode
|
||||
doc.Find(episodeCardSelector).Each(func(i int, s *goquery.Selection) {
|
||||
doc.Find(os.Getenv("EPISODE_CARD_SELECTOR")).Each(func(i int, s *goquery.Selection) {
|
||||
var episode Episode
|
||||
|
||||
seasonEpisodeTitle := s.Find(seasonEpisodeAndTitleSelector).Text()
|
||||
seasonEpisodeTitle := s.Find(os.Getenv("SEASON_EPISODE_AND_TITLE_SELECTOR")).Text()
|
||||
episode.Season, episode.Episode, episode.Name = parseSeasonEpisodeTitle(seasonEpisodeTitle)
|
||||
|
||||
releasedDate := s.Find(releasedDateSelector).Text()
|
||||
releasedDate := s.Find(os.Getenv("RELEASED_DATE_SELECTOR")).Text()
|
||||
episode.Released = parseReleasedDate(releasedDate)
|
||||
|
||||
plot := s.Find(plotSelector).Text()
|
||||
plot := s.Find(os.Getenv("PLOT_SELECTOR")).Text()
|
||||
if plot == "Add a plot" {
|
||||
episode.Plot = ""
|
||||
} else {
|
||||
episode.Plot = plot
|
||||
}
|
||||
|
||||
starRating := s.Find(starRatingSelector).Text()
|
||||
starRating := s.Find(os.Getenv("STAR_RATING_SELECTOR")).Text()
|
||||
episode.Rate = parseStarRating(starRating)
|
||||
|
||||
voteCount := s.Find(voteCountSelector).Text()
|
||||
voteCount := s.Find(os.Getenv("VOTE_COUNT_SELECTOR")).Text()
|
||||
episode.VoteCount = parseVoteCount(voteCount)
|
||||
|
||||
episodes = append(episodes, episode)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package transfers
|
||||
|
||||
type EpisodePayload struct {
|
||||
Title string
|
||||
Season int
|
||||
Episode int
|
||||
Description string
|
||||
Rating float64
|
||||
}
|
||||
@@ -13,4 +13,3 @@ sql:
|
||||
emit_json_tags: true
|
||||
rename:
|
||||
uuid: "UUID"
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
{{template "partials/header" .}}
|
||||
|
||||
<div class="flex w-full flex-col items-center">
|
||||
<h1 class="mb-6 text-3xl font-bold">{{ .TvShow.Title }}</h1>
|
||||
|
||||
<div class="mb-6 rounded-lg bg-white p-6 shadow-md">
|
||||
<div class="mb-4 text-center">
|
||||
<span class="text-gray-600">IMDb ID:</span>
|
||||
<span class="font-semibold text-gray-800">{{ .TvShow.ShowID }}</span>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-8">
|
||||
<ul class="space-y-2">
|
||||
<li>
|
||||
<span class="text-gray-600">Title:</span>
|
||||
<span class="font-semibold text-gray-800">{{ .TvShow.Title }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="text-gray-600">Runtime:</span>
|
||||
<span class="font-semibold text-gray-800"
|
||||
>{{ .TvShow.Runtime }} min</span
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span class="text-gray-600">Seasons:</span>
|
||||
<span class="font-semibold text-gray-800">{{len .TvShow.Seasons }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="space-y-2">
|
||||
<li>
|
||||
<span class="text-gray-600">Total votes:</span>
|
||||
<span class="font-semibold text-gray-800">{{ .TvShow.Votes }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="text-gray-600">Average rating:</span>
|
||||
<span class="font-semibold text-gray-800"
|
||||
>{{printf "%.2f" .TvShow.AvgRating }}</span
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span class="text-gray-600">Median rating:</span>
|
||||
<span class="font-semibold text-gray-800"
|
||||
>{{printf "%.2f" .TvShow.MedianRating }}</span
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 w-2/3">
|
||||
<h2 class="mb-6 text-center text-2xl font-bold">Seasons overall</h2>
|
||||
<canvas id="seasons"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 w-2/3">
|
||||
<div x-data="{ selectedSeasonNumber: 1}">
|
||||
<h2 class="mb-6 text-center text-2xl font-bold">
|
||||
Season <span x-text="selectedSeasonNumber"></span>
|
||||
</h2>
|
||||
<canvas id="episodes"></canvas>
|
||||
<div class="mt-4 flex items-center justify-center space-x-2">
|
||||
{{ range .TvShow.Seasons }}
|
||||
<button
|
||||
class="rounded-md border-2 border-black px-4 py-2 font-semibold text-black hover:bg-black hover:text-white"
|
||||
:class="selectedSeasonNumber === {{ .Number }} ? 'bg-black text-white' : 'text-black'"
|
||||
x-on:click="selectedSeasonNumber = {{ .Number }}; loadSeason({{ .Number }})"
|
||||
>
|
||||
S{{ .Number }}
|
||||
</button>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "partials/footer" .}}
|
||||
<script
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.2.1/chart.umd.js"
|
||||
integrity="sha512-vCUbejtS+HcWYtDHRF2T5B0BKwVG/CLeuew5uT2AiX4SJ2Wff52+kfgONvtdATqkqQMC9Ye5K+Td0OTaz+P7cw=="
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
></script>
|
||||
<script type="module">
|
||||
import { initCharts, loadSpecificSeason } from "/js/components/charts.js";
|
||||
|
||||
let tvShow = "{{ .TvShowJSON }}";
|
||||
let tvShowParsed = JSON.parse(tvShow);
|
||||
|
||||
function loadSeason(season) {
|
||||
const currentScrollY = window.scrollY;
|
||||
loadSpecificSeason(tvShowParsed, season);
|
||||
window.scrollTo(0, currentScrollY);
|
||||
}
|
||||
|
||||
window.loadSeason = loadSeason;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
initCharts(tvShowParsed);
|
||||
});
|
||||
</script>
|
||||
File diff suppressed because one or more lines are too long
@@ -1,55 +0,0 @@
|
||||
{{template "partials/header" .}}
|
||||
<div class="flex min-h-screen flex-col items-center justify-center">
|
||||
<h1 class="mb-6 text-3xl font-bold">Rating Orama</h1>
|
||||
<div class="w-full max-w-md">
|
||||
<form x-data="search" @submit.prevent="submit" class="flex items-center gap-3" >
|
||||
<input
|
||||
x-model="ttID"
|
||||
class="rounded-md border-2 border-black bg-white px-4 py-2 w-11/12"
|
||||
id="search"
|
||||
name="search"
|
||||
type="text"
|
||||
placeholder="tt0903747"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
:disabled="isLoading"
|
||||
class="rounded-md border-2 border-black bg-white px-4 py-2 font-bold text-black w-2/12"
|
||||
type="submit"
|
||||
:class="isLoading ? '' : 'hover:bg-black hover:text-white'"
|
||||
>
|
||||
<div class="flex items-center justify-center">
|
||||
<template x-if="isLoading">
|
||||
<div role="status">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-6 w-6 animate-spin fill-black text-white"
|
||||
aria-hidden="true"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Cargando...</span>
|
||||
</div>
|
||||
</template>
|
||||
<template x-if="!isLoading" class="lorem">
|
||||
<span>Go!</span>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
</button>
|
||||
</form>
|
||||
<p class="mt-2">
|
||||
Please input <span class="font-bold">tt id</span> from IDMb
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
export function initCharts(tvShowParsed) {
|
||||
new EpisodeChart(tvShowParsed, "episodes", 0);
|
||||
new SeasonsChart(tvShowParsed, "seasons");
|
||||
}
|
||||
|
||||
export function loadSpecificSeason(tvShowParsed, seasonId) {
|
||||
new EpisodeChart(tvShowParsed, "episodes", seasonId - 1);
|
||||
}
|
||||
|
||||
let chartInstance;
|
||||
|
||||
class SeasonsChart {
|
||||
constructor(tvShowParsed, canvasId) {
|
||||
this.tvShowParsed = tvShowParsed;
|
||||
this.canvasId = canvasId;
|
||||
this.createChart();
|
||||
}
|
||||
|
||||
createChart() {
|
||||
const seasons = this.tvShowParsed.seasons;
|
||||
const labels = seasons.map((season) => `Season ${season.number}`);
|
||||
const averageRating = seasons.map((season) => season.avg_rating);
|
||||
const medianRating = seasons.map((season) => season.median_rating);
|
||||
const votes = seasons.map((season) => season.votes);
|
||||
const title = "Seasons"
|
||||
const ctx = document.getElementById(this.canvasId);
|
||||
|
||||
new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Average rating",
|
||||
data: averageRating,
|
||||
backgroundColor: "rgba(75, 192, 192, 0.5)",
|
||||
borderColor: "rgba(75, 192, 192, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
},
|
||||
{
|
||||
label: "Median rating",
|
||||
data: medianRating,
|
||||
backgroundColor: "rgba(255, 206, 86, 0.5)",
|
||||
borderColor: "rgba(255, 206, 86, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
|
||||
},
|
||||
{
|
||||
label: "Votes",
|
||||
data: votes,
|
||||
type: "line",
|
||||
tension: 0.4,
|
||||
fill: false,
|
||||
borderColor: "rgba(255, 99, 132, 1)",
|
||||
borderWidth: 2,
|
||||
yAxisID: "y-axis-votes",
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
animation: {
|
||||
duration: 0,
|
||||
},
|
||||
y: {
|
||||
stacked: true,
|
||||
},
|
||||
scales: {
|
||||
"y-axis-ratings": {
|
||||
min: 0,
|
||||
max: 10,
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "left",
|
||||
beginAtZero: true,
|
||||
},
|
||||
"y-axis-votes": {
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "right",
|
||||
beginAtZero: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
title: {
|
||||
display: true,
|
||||
text: title,
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class EpisodeChart {
|
||||
constructor(tvShowParsed, canvasId, seasonId) {
|
||||
this.tvShowParsed = tvShowParsed;
|
||||
this.canvasId = canvasId;
|
||||
this.seasonId = seasonId;
|
||||
this.createChart();
|
||||
}
|
||||
|
||||
createChart() {
|
||||
if (chartInstance) {
|
||||
chartInstance.destroy();
|
||||
}
|
||||
|
||||
const episodes = this.tvShowParsed.seasons[this.seasonId].episodes;
|
||||
const labels = episodes.map((episode) => `Ep. ${episode.number}`);
|
||||
const ratings = episodes.map((episode) => episode.avg_rating);
|
||||
const votes = episodes.map((episode) => episode.votes);
|
||||
const title = `Episodes of season ${this.seasonId + 1}`
|
||||
const ctx = document.getElementById(this.canvasId);
|
||||
|
||||
chartInstance = new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{
|
||||
label: "Average rating",
|
||||
data: ratings,
|
||||
backgroundColor: "rgba(75, 192, 192, 0.5)",
|
||||
borderColor: "rgba(75, 192, 192, 1)",
|
||||
borderWidth: 1,
|
||||
Range: 10,
|
||||
yAxisID: "y-axis-ratings",
|
||||
},
|
||||
{
|
||||
label: "Votes",
|
||||
data: votes,
|
||||
type: "line",
|
||||
tension: 0.4,
|
||||
fill: false,
|
||||
borderColor: "rgba(255, 99, 132, 1)",
|
||||
borderWidth: 2,
|
||||
yAxisID: "y-axis-votes",
|
||||
},
|
||||
],
|
||||
},
|
||||
options: {
|
||||
animation: {
|
||||
duration: 0,
|
||||
},
|
||||
scales: {
|
||||
"y-axis-ratings": {
|
||||
min: 0,
|
||||
max: 10,
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "left",
|
||||
beginAtZero: true,
|
||||
},
|
||||
"y-axis-votes": {
|
||||
type: "linear",
|
||||
display: true,
|
||||
position: "right",
|
||||
beginAtZero: true,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
title: function (context) {
|
||||
const index = context[0].dataIndex;
|
||||
const episode = episodes[index];
|
||||
return `${episode.title} (${episode.aired.split("T")[0]})`;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
export function search() {
|
||||
return {
|
||||
url: '/tv-show?id=',
|
||||
ttID: '',
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
submit() {
|
||||
this.isLoading = true;
|
||||
fetch(this.url+this.ttID).then(response => {
|
||||
if (response.ok) {
|
||||
window.location.href = this.url+this.ttID;
|
||||
} else {
|
||||
this.isLoading = false;
|
||||
this.isError = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
import Alpine from "https://cdn.jsdelivr.net/npm/alpinejs@3.12.0/dist/module.esm.js";
|
||||
import { search } from "./components/search.js";
|
||||
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.data('search', search)
|
||||
|
||||
Alpine.start();
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link type="image/svg+xml" href="/vite.svg" rel="icon" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link href="/css/index.css" rel="stylesheet" />
|
||||
<title>Rating Orama</title>
|
||||
{{block "css" .}} {{end}}
|
||||
</head>
|
||||
<body class="min-h-screen bg-gray-100">
|
||||
{{embed}}
|
||||
|
||||
<script type="module" src="/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,96 +0,0 @@
|
||||
<footer class="bg-gray-200" aria-label="Site Footer">
|
||||
<ul class="mt-12 flex justify-center gap-6 p-12">
|
||||
<li>
|
||||
<a
|
||||
class="text-gray-700 transition hover:text-gray-700/75"
|
||||
href="https://www.instagram.com/zepyrshut/"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Instagram</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
aria-hidden="true"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M12.315 2c2.43 0 2.784.013 3.808.06 1.064.049 1.791.218 2.427.465a4.902 4.902 0 011.772 1.153 4.902 4.902 0 011.153 1.772c.247.636.416 1.363.465 2.427.048 1.067.06 1.407.06 4.123v.08c0 2.643-.012 2.987-.06 4.043-.049 1.064-.218 1.791-.465 2.427a4.902 4.902 0 01-1.153 1.772 4.902 4.902 0 01-1.772 1.153c-.636.247-1.363.416-2.427.465-1.067.048-1.407.06-4.123.06h-.08c-2.643 0-2.987-.012-4.043-.06-1.064-.049-1.791-.218-2.427-.465a4.902 4.902 0 01-1.772-1.153 4.902 4.902 0 01-1.153-1.772c-.247-.636-.416-1.363-.465-2.427-.047-1.024-.06-1.379-.06-3.808v-.63c0-2.43.013-2.784.06-3.808.049-1.064.218-1.791.465-2.427a4.902 4.902 0 011.153-1.772A4.902 4.902 0 015.45 2.525c.636-.247 1.363-.416 2.427-.465C8.901 2.013 9.256 2 11.685 2h.63zm-.081 1.802h-.468c-2.456 0-2.784.011-3.807.058-.975.045-1.504.207-1.857.344-.467.182-.8.398-1.15.748-.35.35-.566.683-.748 1.15-.137.353-.3.882-.344 1.857-.047 1.023-.058 1.351-.058 3.807v.468c0 2.456.011 2.784.058 3.807.045.975.207 1.504.344 1.857.182.466.399.8.748 1.15.35.35.683.566 1.15.748.353.137.882.3 1.857.344 1.054.048 1.37.058 4.041.058h.08c2.597 0 2.917-.01 3.96-.058.976-.045 1.505-.207 1.858-.344.466-.182.8-.398 1.15-.748.35-.35.566-.683.748-1.15.137-.353.3-.882.344-1.857.048-1.055.058-1.37.058-4.041v-.08c0-2.597-.01-2.917-.058-3.96-.045-.976-.207-1.505-.344-1.858a3.097 3.097 0 00-.748-1.15 3.098 3.098 0 00-1.15-.748c-.353-.137-.882-.3-1.857-.344-1.023-.047-1.351-.058-3.807-.058zM12 6.865a5.135 5.135 0 110 10.27 5.135 5.135 0 010-10.27zm0 1.802a3.333 3.333 0 100 6.666 3.333 3.333 0 000-6.666zm5.338-3.205a1.2 1.2 0 110 2.4 1.2 1.2 0 010-2.4z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a
|
||||
class="text-gray-700 transition hover:text-gray-700/75"
|
||||
href="https://github.com/zepyrshut"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">GitHub</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
aria-hidden="true"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a
|
||||
class="text-gray-700 transition hover:text-gray-700/75"
|
||||
href="https://pedroperez.dev/"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Website</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M12 21a9.004 9.004 0 008.716-6.747M12 21a9.004 9.004 0 01-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 017.843 4.582M12 3a8.997 8.997 0 00-7.843 4.582m15.686 0A11.953 11.953 0 0112 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0121 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0112 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 013 12c0-1.605.42-3.113 1.157-4.418"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="text-gray-700 transition hover:text-gray-700/75"
|
||||
href="https://github.com/zepyrshut/rating-orama"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Source</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M17.25 6.75L22.5 12l-5.25 5.25m-10.5 0L1.5 12l5.25-5.25m7.5-3l-4.5 16.5"
|
||||
/>
|
||||
</svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</footer>
|
||||
@@ -1,3 +0,0 @@
|
||||
<p class="mb-6 bg-yellow-400">
|
||||
Work in progress - API 0.1.0 / Harvester 0.1.0 / Views 0.1.0 <a href="mailto:hola@pedroperez.dev" class="text-blue-800">Have you found any bugs or is it not working with a specific tv show?</a>
|
||||
</p>
|
||||
@@ -0,0 +1,45 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
core:
|
||||
container_name: rating-orama
|
||||
image: rating-orama:latest
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_started
|
||||
environment:
|
||||
DRIVERNAME: pgx
|
||||
DATASOURCE: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable
|
||||
MIGRATE: true
|
||||
TITLE_SELECTOR: ${TITLE_SELECTOR}
|
||||
SEASON_SELECTOR: ${SEASON_SELECTOR}
|
||||
EPISODE_CARD_SELECTOR: ${EPISODE_CARD_SELECTOR}
|
||||
SEASON_EPISODE_AND_TITLE_SELECTOR: ${SEASON_EPISODE_AND_TITLE_SELECTOR}
|
||||
RELEASED_DATE_SELECTOR: ${RELEASED_DATE_SELECTOR}
|
||||
PLOT_SELECTOR: ${PLOT_SELECTOR}
|
||||
STAR_RATING_SELECTOR: ${STAR_RATING_SELECTOR}
|
||||
VOTE_COUNT_SELECTOR: ${VOTE_COUNT_SELECTOR}
|
||||
IMDB_EPISODES_URL: ${IMDB_EPISODES_URL}
|
||||
VISIT_URL: ${VISIT_URL}
|
||||
ports:
|
||||
- "8086:8080"
|
||||
networks:
|
||||
- ratingorama
|
||||
db:
|
||||
container_name: db-ratingorama
|
||||
image: postgres:16.4-alpine3.20
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
volumes:
|
||||
- ratingorama_data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- ratingorama
|
||||
|
||||
networks:
|
||||
ratingorama:
|
||||
|
||||
volumes:
|
||||
ratingorama_data:
|
||||
|
||||
+19
-66
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -7,22 +7,18 @@
|
||||
<title>Inicio</title>
|
||||
</head>
|
||||
|
||||
<body class="min-h-screen bg-gray-100">
|
||||
<p class="mb-6 bg-yellow-400">
|
||||
Work in progress - API 0.1.0 / Harvester 0.1.0 / Views 0.1.0
|
||||
<a class="text-blue-800" href="mailto:hola@pedroperez.dev"
|
||||
>Have you found any bugs or is it not working with a specific tv
|
||||
show?</a
|
||||
>
|
||||
</p>
|
||||
<body class="min-h-screen bg-slate-50 p-2">
|
||||
|
||||
<div class="flex w-full flex-col items-center">
|
||||
<h1 class="mb-6 text-3xl font-bold">Breaking Bad</h1>
|
||||
|
||||
<div class="mb-6 rounded-lg bg-white p-6 shadow-md">
|
||||
|
||||
|
||||
<div class="flex w-full flex-col items-center mt-6">
|
||||
<h1 class="mb-6 text-4xl font-bold">Breaking Bad</h1>
|
||||
|
||||
<div class="mb-6 rounded-lg bg-white p-6 shadow-sm border border-gray-200">
|
||||
<div class="mb-4 text-center">
|
||||
<span class="text-gray-600">IMDb ID:</span>
|
||||
<span class="font-semibold text-gray-800">0903747</span>
|
||||
<span class="text-gray-600">IMDb ID: </span>
|
||||
<span class="font-semibold text-gray-800">tt0903747</span>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-8">
|
||||
@@ -115,23 +111,12 @@
|
||||
<li>
|
||||
<a
|
||||
class="text-gray-700 transition hover:text-gray-700/75"
|
||||
href="https://www.instagram.com/zepyrshut/"
|
||||
href="https://www.instagram.com/modelektor/"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Instagram</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
aria-hidden="true"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M12.315 2c2.43 0 2.784.013 3.808.06 1.064.049 1.791.218 2.427.465a4.902 4.902 0 011.772 1.153 4.902 4.902 0 011.153 1.772c.247.636.416 1.363.465 2.427.048 1.067.06 1.407.06 4.123v.08c0 2.643-.012 2.987-.06 4.043-.049 1.064-.218 1.791-.465 2.427a4.902 4.902 0 01-1.153 1.772 4.902 4.902 0 01-1.772 1.153c-.636.247-1.363.416-2.427.465-1.067.048-1.407.06-4.123.06h-.08c-2.643 0-2.987-.012-4.043-.06-1.064-.049-1.791-.218-2.427-.465a4.902 4.902 0 01-1.772-1.153 4.902 4.902 0 01-1.153-1.772c-.247-.636-.416-1.363-.465-2.427-.047-1.024-.06-1.379-.06-3.808v-.63c0-2.43.013-2.784.06-3.808.049-1.064.218-1.791.465-2.427a4.902 4.902 0 011.153-1.772A4.902 4.902 0 015.45 2.525c.636-.247 1.363-.416 2.427-.465C8.901 2.013 9.256 2 11.685 2h.63zm-.081 1.802h-.468c-2.456 0-2.784.011-3.807.058-.975.045-1.504.207-1.857.344-.467.182-.8.398-1.15.748-.35.35-.566.683-.748 1.15-.137.353-.3.882-.344 1.857-.047 1.023-.058 1.351-.058 3.807v.468c0 2.456.011 2.784.058 3.807.045.975.207 1.504.344 1.857.182.466.399.8.748 1.15.35.35.683.566 1.15.748.353.137.882.3 1.857.344 1.054.048 1.37.058 4.041.058h.08c2.597 0 2.917-.01 3.96-.058.976-.045 1.505-.207 1.858-.344.466-.182.8-.398 1.15-.748.35-.35.566-.683.748-1.15.137-.353.3-.882.344-1.857.048-1.055.058-1.37.058-4.041v-.08c0-2.597-.01-2.917-.058-3.96-.045-.976-.207-1.505-.344-1.858a3.097 3.097 0 00-.748-1.15 3.098 3.098 0 00-1.15-.748c-.353-.137-.882-.3-1.857-.344-1.023-.047-1.351-.058-3.807-.058zM12 6.865a5.135 5.135 0 110 10.27 5.135 5.135 0 010-10.27zm0 1.802a3.333 3.333 0 100 6.666 3.333 3.333 0 000-6.666zm5.338-3.205a1.2 1.2 0 110 2.4 1.2 1.2 0 010-2.4z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-instagram"><rect width="20" height="20" x="2" y="2" rx="5" ry="5"/><path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z"/><line x1="17.5" x2="17.51" y1="6.5" y2="6.5"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -143,18 +128,7 @@
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">GitHub</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
aria-hidden="true"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -166,19 +140,7 @@
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Website</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M12 21a9.004 9.004 0 008.716-6.747M12 21a9.004 9.004 0 01-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 017.843 4.582M12 3a8.997 8.997 0 00-7.843 4.582m15.686 0A11.953 11.953 0 0112 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0121 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0112 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 013 12c0-1.605.42-3.113 1.157-4.418"
|
||||
/>
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-globe"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
@@ -189,19 +151,7 @@
|
||||
target="_blank"
|
||||
>
|
||||
<span class="sr-only">Source</span>
|
||||
<svg
|
||||
class="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M17.25 6.75L22.5 12l-5.25 5.25m-10.5 0L1.5 12l5.25-5.25m7.5-3l-4.5 16.5"
|
||||
/>
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-xml"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -215,7 +165,10 @@
|
||||
referrerpolicy="no-referrer"
|
||||
></script>
|
||||
<script type="module">
|
||||
import { initCharts, loadSpecificSeason } from "./src/components/charts.js";
|
||||
import {
|
||||
initCharts,
|
||||
loadSpecificSeason,
|
||||
} from "./src/components/charts.js";
|
||||
import { data } from "./src/data/breaking-bad.js";
|
||||
|
||||
const tvShowParsed = data;
|
||||
|
||||
+24
-61
@@ -1,80 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link href="./src/styles/index.css" rel="stylesheet" />
|
||||
<title>Inicio</title>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body class="min-h-screen bg-gray-100">
|
||||
<p class="mb-6 bg-yellow-400">
|
||||
Work in progress - API 0.1.0 / Harvester 0.1.0 / Views 0.1.0
|
||||
<a class="text-blue-800" href="mailto:hola@pedroperez.dev"
|
||||
>Have you found any bugs or is it not working with a specific tv
|
||||
show?</a
|
||||
>
|
||||
</p>
|
||||
<body class="min-h-screen bg-slate-50 p-2">
|
||||
|
||||
|
||||
|
||||
<div class="flex min-h-screen flex-col items-center justify-center">
|
||||
<h1 class="mb-6 text-3xl font-bold">Rating Orama</h1>
|
||||
|
||||
|
||||
<div class="w-full max-w-md">
|
||||
<form x-data="search" @submit.prevent="submit" class="flex items-center gap-3" >
|
||||
<input
|
||||
x-model="ttID"
|
||||
class="rounded-md border-2 border-black bg-white px-4 py-2 w-11/12"
|
||||
id="search"
|
||||
name="search"
|
||||
type="text"
|
||||
placeholder="tt0903747"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
:disabled="isLoading"
|
||||
class="rounded-md border-2 border-black bg-white px-4 py-2 font-bold text-black w-2/12"
|
||||
type="submit"
|
||||
:class="isLoading ? '' : 'hover:bg-black hover:text-white'"
|
||||
>
|
||||
<div class="flex items-center justify-center">
|
||||
<template x-if="isLoading">
|
||||
<div role="status">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="h-6 w-6 animate-spin fill-black text-white"
|
||||
aria-hidden="true"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
|
||||
<div class="flex flex-col justify-center min-h-screen">
|
||||
<form class="max-w-md mx-auto w-full">
|
||||
<label for="default-search" class="mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white">Buscar</label>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||
class="lucide lucide-search">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
<span class="sr-only">Cargando...</span>
|
||||
</div>
|
||||
</template>
|
||||
<template x-if="!isLoading" class="lorem">
|
||||
<span>Go!</span>
|
||||
</template>
|
||||
<input type="search" id="default-search"
|
||||
class="block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
|
||||
placeholder="IMDb ID" required />
|
||||
<button type="submit"
|
||||
class="text-white absolute end-2.5 bottom-2.5 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-4 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Search</button>
|
||||
</div>
|
||||
|
||||
</button>
|
||||
</form>
|
||||
<p class="mt-2">
|
||||
Please input <span class="font-bold">tt id</span> from IDMb
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="./src/main.js" type="module"></script>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+11
-10
@@ -8,18 +8,16 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/forms": "^0.5.3",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"postcss": "^8.4.21",
|
||||
"prettier": "^2.8.7",
|
||||
"prettier-plugin-organize-attributes": "^0.0.5",
|
||||
"prettier-plugin-tailwindcss": "^0.2.7",
|
||||
"standard": "^17.0.0",
|
||||
"tailwindcss": "^3.3.1",
|
||||
"vite": "^4.2.1"
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-organize-attributes": "^1.0.0",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
"standard": "^17.1.2",
|
||||
"tailwindcss": "^4.0.0",
|
||||
"vite": "^6.0.11"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
@@ -27,5 +25,8 @@
|
||||
"dist",
|
||||
"*.config.js"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+2780
-1631
File diff suppressed because it is too large
Load Diff
@@ -1,6 +0,0 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@import "tailwindcss";
|
||||
|
||||
@@ -5,7 +5,5 @@ module.exports = {
|
||||
theme: {
|
||||
extend: {}
|
||||
},
|
||||
plugins: [require('@tailwindcss/forms')({
|
||||
strategy: 'class'
|
||||
})]
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
export default defineConfig({
|
||||
base: './'
|
||||
base: './',
|
||||
plugins: [
|
||||
tailwindcss()
|
||||
]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user