Compare commits

...

5 Commits

Author SHA1 Message Date
5465dcd8f3 Added LICENSE 2022-09-24 16:02:13 +02:00
01254a6e17 Updated README.md 2022-09-24 15:57:23 +02:00
668804f94e Log errors to stderr 2022-09-24 15:53:23 +02:00
da6c22d1f4 Add env configuration for lurker.vibe 2022-09-24 15:48:30 +02:00
2ed360e42b Added dbmate 2022-09-24 15:38:32 +02:00
5 changed files with 62 additions and 9 deletions

6
.env.sample Normal file
View File

@ -0,0 +1,6 @@
# lurker.vibe
API_URL="https://localhost/api/presences"
API_TOKEN="Bearer token"
# dbmate
DATABASE_URL=""

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View File

@ -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
```

View File

@ -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, album_id BIGINT UNSIGNED auto_increment NOT NULL,
artist varchar(100) NULL, artist varchar(100) NULL,
name varchar(100) NULL, name varchar(100) NULL,
@ -9,25 +10,30 @@ ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci; COLLATE=utf8mb4_general_ci;
CREATE TABLE test.spotify_tracks ( CREATE TABLE spotify_tracks (
track_id varchar(100) NOT NULL, track_id varchar(100) NOT NULL,
album_id BIGINT UNSIGNED NOT NULL, album_id BIGINT UNSIGNED NOT NULL,
title varchar(100) NULL, title varchar(100) NULL,
duration INT NULL, duration INT NULL,
CONSTRAINT spotify_tracks_PK PRIMARY KEY (track_id), 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 ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci; COLLATE=utf8mb4_general_ci;
CREATE TABLE test.spotify_plays ( CREATE TABLE spotify_plays (
user_id BIGINT UNSIGNED NOT NULL, user_id BIGINT UNSIGNED NOT NULL,
track_id varchar(100) NOT NULL, track_id varchar(100) NOT NULL,
created_at TIMESTAMP NOT NULL, created_at TIMESTAMP NOT NULL,
CONSTRAINT spotify_plays_PK PRIMARY KEY (user_id,created_at), 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 ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4 DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci; COLLATE=utf8mb4_general_ci;
-- migrate:down
DROP TABLE spotify_plays;
DROP TABLE spotify_tracks;
DROP TABLE spotify_albums;

View File

@ -1,3 +1,4 @@
import os
import sys import sys
import typing import typing
from datetime import datetime from datetime import datetime
@ -10,8 +11,8 @@ from loguru import logger
T = typing.TypeVar("T") T = typing.TypeVar("T")
FlushFunc = typing.Callable[[list[T]], typing.Coroutine[typing.Any, typing.Any, bool]] FlushFunc = typing.Callable[[list[T]], typing.Coroutine[typing.Any, typing.Any, bool]]
API_URL = "https://requestbin.io/17ifjd71" API_URL = os.getenv("API_URL")
API_TOKEN = "" API_TOKEN = os.getenv("API_TOKEN")
class SpotifyRecord(typing.NamedTuple): class SpotifyRecord(typing.NamedTuple):
@ -102,7 +103,11 @@ class Bot(discord.Client):
def main(argv: typing.Sequence[str]): def main(argv: typing.Sequence[str]):
if len(argv) == 0: 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 return 1
Bot().run(argv[0]) Bot().run(argv[0])