Skip to content

Instantly share code, notes, and snippets.

View blacklight's full-sized avatar

Fabio Manganiello blacklight

View GitHub Profile
// Sample Platypush user script to cast the current tab or any media item selected
// on the page to the default Chromecast device configured in Platypush.
async (app, args) => {
const baseURL = await app.getURL();
// Default URL to cast: current page URL
let url = baseURL;
if (args.target) {
// The user executed the action from a context menu
// Platypush user script to translate a web page through the Google Translate API
async (app, args) => {
const dom = await app.getDOM();
// Translate the page through the Platypush Google Translate plugin
// (https://platypush.readthedocs.io/en/latest/platypush/plugins/google.translate.html).
// The plugin also splits the HTML in multiple requests if too long
// to circumvent Google's limit on maximum input text.
const response = await app.run({
action: 'google.translate.translate',
// Sample Platypush user script to save the current URL to Instapaper
async (app, args) => {
const url = await app.getURL();
const response = await app.axios.get('https://www.instapaper.com/api/add', {
params: {
url: url,
username: '********@****.***',
password: '******',
},
});
// Platypush user script to play the current URL
// on the Chromecast if it is a YouTube URL.
async (app, args) => {
const url = await app.getURL();
if (!url.startsWith('https://www.youtube.com/watch?v=')) {
return;
}
const response = await app.run({
action: 'media.chromecast.play',
@blacklight
blacklight / example.js
Last active July 4, 2020 23:22
A sample script showing the capabilities of the Platypush web extension web scripts API
/**
* This script shows some of the capabilities of the Platypush Script API, and how
* you can leverage the provided API to create custom scripts that can be executed
* from anywhere in your browser.
*
* In order to create a new script:
*
* 1. Make sure that you have added at least one Platypush device in the extension
* configuration.
*
async (app, host, browser, tab, target, ...args) => {
let url = null;
const baseURL = await app.getURL();
if (target) {
switch (target.tagName.toLowerCase()) {
case 'img':
url = target.attributes.src.value;
break;
case 'a':
@blacklight
blacklight / surfingkeys.js
Last active August 29, 2020 23:36
surfingkeys
// an example to create a new mapping `ctrl-y`
mapkey('<Ctrl-y>', 'Show me the money', function() {
Front.showPopup('a well-known phrase uttered by characters in the 1996 film Jerry Maguire (Escape to close).');
});
// an example to replace `T` with `gt`, click `Default mappings` to see how `T` works.
map('gt', 'T');
// an example to remove mapkey `Ctrl-i`
unmap('<Ctrl-i>');
from platypush.event.hook import hook
from platypush.message.event.covid19 import Covid19UpdateEvent
from platypush.utils import run
@hook(Covid19UpdateEvent)
def on_covid19_update(event, **context):
db_engine = 'postgresql+pg8000://user:password@db_ip_address/covid19'
run('db.insert', table='tmp_covid19_data', engine=db_engine, records=[
{
from platypush.utils import run
def main():
db_engine = 'postgresql+pg8000://user:password@db_ip_address/covid19'
# List of country codes you want to monitor
countries = ['nl', 'it', 'us', 'es', 'gb', 'cn', 'fr', 'ru']
# Pull the historical data
@blacklight
blacklight / fill_covid19_db.sql
Last active May 6, 2020 22:41
Fill Covid19 stats database
--
-- tmp_covid19_data table setup
--
drop sequence if exists tmp_covid19_data_seq cascade;
create sequence tmp_covid19_data_seq;
drop table if exists tmp_covid19_data cascade;
create table tmp_covid19_data(
id integer not null default nextval('tmp_covid19_data_seq'),