Compare commits
4 Commits
af95f7af33
...
01254a6e17
Author | SHA1 | Date | |
---|---|---|---|
01254a6e17 | |||
668804f94e | |||
da6c22d1f4 | |||
2ed360e42b |
6
.env.sample
Normal file
6
.env.sample
Normal file
@ -0,0 +1,6 @@
|
||||
# lurker.vibe
|
||||
API_URL="https://localhost/api/presences"
|
||||
API_TOKEN="Bearer token"
|
||||
|
||||
# dbmate
|
||||
DATABASE_URL=""
|
14
README.md
14
README.md
@ -1 +1,13 @@
|
||||
# lurker.py
|
||||
# lurker.vibe
|
||||
Collects Spotify presences from Discord and sends them in batches to a given endpoint.
|
||||
|
||||
## Usage
|
||||
Using Python:
|
||||
```sh
|
||||
# Copy and modify .env
|
||||
cp .env.sample .env
|
||||
|
||||
# Install deps and run
|
||||
python -m pip install -r requirements.txt
|
||||
python lurker/bot.py
|
||||
```
|
||||
|
@ -1,4 +1,5 @@
|
||||
CREATE OR REPLACE TABLE test.spotify_albums (
|
||||
-- migrate:up
|
||||
CREATE OR REPLACE TABLE spotify_albums (
|
||||
album_id BIGINT UNSIGNED auto_increment NOT NULL,
|
||||
artist varchar(100) NULL,
|
||||
name varchar(100) NULL,
|
||||
@ -9,25 +10,30 @@ ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb4
|
||||
COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE test.spotify_tracks (
|
||||
CREATE TABLE spotify_tracks (
|
||||
track_id varchar(100) NOT NULL,
|
||||
album_id BIGINT UNSIGNED NOT NULL,
|
||||
title varchar(100) NULL,
|
||||
duration INT NULL,
|
||||
CONSTRAINT spotify_tracks_PK PRIMARY KEY (track_id),
|
||||
CONSTRAINT spotify_tracks_FK FOREIGN KEY (album_id) REFERENCES test.spotify_albums(album_id)
|
||||
CONSTRAINT spotify_tracks_FK FOREIGN KEY (album_id) REFERENCES spotify_albums(album_id)
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb4
|
||||
COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE test.spotify_plays (
|
||||
CREATE TABLE spotify_plays (
|
||||
user_id BIGINT UNSIGNED NOT NULL,
|
||||
track_id varchar(100) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
CONSTRAINT spotify_plays_PK PRIMARY KEY (user_id,created_at),
|
||||
CONSTRAINT spotify_plays_FK FOREIGN KEY (track_id) REFERENCES test.spotify_tracks(track_id)
|
||||
CONSTRAINT spotify_plays_FK FOREIGN KEY (track_id) REFERENCES spotify_tracks(track_id)
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb4
|
||||
COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE spotify_plays;
|
||||
DROP TABLE spotify_tracks;
|
||||
DROP TABLE spotify_albums;
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
import typing
|
||||
from datetime import datetime
|
||||
@ -10,8 +11,8 @@ from loguru import logger
|
||||
T = typing.TypeVar("T")
|
||||
FlushFunc = typing.Callable[[list[T]], typing.Coroutine[typing.Any, typing.Any, bool]]
|
||||
|
||||
API_URL = "https://requestbin.io/17ifjd71"
|
||||
API_TOKEN = ""
|
||||
API_URL = os.getenv("API_URL")
|
||||
API_TOKEN = os.getenv("API_TOKEN")
|
||||
|
||||
|
||||
class SpotifyRecord(typing.NamedTuple):
|
||||
@ -102,7 +103,11 @@ class Bot(discord.Client):
|
||||
|
||||
def main(argv: typing.Sequence[str]):
|
||||
if len(argv) == 0:
|
||||
print("Usage: lurker.py <token>")
|
||||
print("Usage: lurker.py <token>", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if not API_URL:
|
||||
print("Missing `API_URL` environment variable.", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
Bot().run(argv[0])
|
||||
|
Reference in New Issue
Block a user