Skip to content

Instantly share code, notes, and snippets.

View blacklight's full-sized avatar

Fabio Manganiello blacklight

View GitHub Profile
import os
from sqlalchemy import create_engine
from sqlalchemy.sql import text
def main():
### Replace this with the SQLAlchemy URL associated to your database
db_string = 'postgresql+pg8000://postgres@localhost/mastodon_production'
### Replace this with the base directory of your Mastodon instance
mastodon_basedir = '/opt/mastodon/live'
# ~/.config/platypush/scripts/music/releases.py
import html
import logging
import re
import threading
from datetime import date, timedelta
from typing import Iterable, List
from platypush.context import get_plugin
>>> import os
>>>
>>> # Move to the Platypush config directory
>>> path = os.path.join(os.path.expanduser('~'), '.config', 'platypush')
>>> os.chdir(path)
>>>
>>> # Import and run the cron function
>>> from scripts.music.discovery import refresh_discover_weekly_cron
>>> refresh_discover_weekly_cron()
# ~/.config/platypush/scripts/music/discovery.py
import logging
from datetime import date, timedelta
from platypush.context import get_plugin
from platypush.cron import cron
from scripts.music.db import (
get_db_session, Track, TrackActivity, TrackSimilar,
# ~/.config/platypush/scripts/music/suggestions.py
import logging
from sqlalchemy import tuple_
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.sql.expression import bindparam
from platypush.context import get_plugin, Variable
from platypush.cron import cron
# ~/.config/platypush/scripts/music/db.py
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import sessionmaker, scoped_session
music_db_engine = 'postgresql+pg8000://dbuser:dbpass@dbhost/dbname'
engine = create_engine(music_db_engine)
Base = automap_base()
# ~/.config/platypush/scripts/music/sync.py
from logging import getLogger
from platypush.context import get_plugin
from platypush.event.hook import hook
from platypush.message.event.music import NewPlayingTrackEvent
logger = getLogger('music_sync')
# ~/.config/platypush/scripts/music/sync.py
from logging import getLogger
from platypush.context import get_plugin
from platypush.event.hook import hook
from platypush.message.event.music import NewPlayingTrackEvent
logger = getLogger('music_sync')
-- New listened tracks will be pushed to the tmp_music table, and normalized by
-- a trigger.
drop table if exists tmp_music cascade;
create table tmp_music(
id serial not null,
artist varchar(255) not null,
title varchar(255) not null,
album varchar(255),
created_at timestamp with time zone default CURRENT_TIMESTAMP,
primary key(id)
music.tidal:
# No configuration required
# Or, if you use Spotify, create an app at https://developer.spotify.com and
# add its credentials here
# music.spotify:
# client_id: client_id
# client_secret: client_secret
lastfm: