This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: '******', | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=[ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 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'), |