Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
var cnt = 0;
module.exports = new Tp.ChannelClass({
Name: 'TestChannel',
Extends: Tp.PollingTrigger,
interval: 5000,
_init: function() {
this.parent();
cnt++;
console.log('Created Test channel #' + cnt);
},
_onTick: function() {
this.emitEvent([42 + Math.floor(Math.random() * 42)]);
},
_doOpen: function() {
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna
//
// See LICENSE for details
const Tp = require('thingpedia');
var cnt = 0;
module.exports = new Tp.ChannelClass({
Name: 'TestChannel',
Extends: Tp.PollingTrigger,
interval: 5000,
_init: function() {
this.parent();
cnt++;
console.log('Created Test channel #' + cnt);
},
_onTick: function() {
this.emitEvent([42 + Math.floor(Math.random() * 42)]);
},
_doOpen: function() {
return this.parent();
},
await Promise.all(images.map(async (img) => {
const src = await img.getAttribute('src');
// small optimization: we only check an image once
// (we don't have dynamic images)
// (we still need to use selenium to check images rather than
// a linkchecker-style approach to make sure we catch JS-added
// images)
if (_checkedImages.has(src))
return;
_checkedImages.add(src);
// this is not exactly what the browser does
const res = await Tp.Helpers.Http.getStream(src, { extraHeaders: {
Referrer: currentUrl
}});
assert(res.headers['content-type'].startsWith('image/'),
`expected image/* content type for image, found ${res['content-type']}`);
res.resume();
}));
}
// This file is part of Almond
//
// Copyright 2019 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna
//
// See COPYING for details
"use strict";
const Tp = require('thingpedia');
const ThingTalk = require('thingtalk');
const path = require('path');
const getExampleName = require('../../util/example_names');
const _schemaRetriever = new ThingTalk.SchemaRetriever(new Tp.FileClient({
thingpedia: path.resolve(path.dirname(module.filename), './thingpedia.tt')
}), null, true);
const TEST_CASES = [
[`query := @com.twitter.search();`, `Search`],
[`query (p_hashtag : Entity(tt:hashtag)) := @com.twitter.search(), contains(hashtags, p_hashtag);`, `SearchByHashtags`],
[`query (p_author : Entity(tt:username)) := @com.twitter.search(), author == p_author;`, `SearchByAuthor`],
[`query (p_author1 : Entity(tt:username), p_author2 : Entity(tt:username)) := @com.twitter.search(), in_array(author, [p_author1, p_author2]);`,
`SearchByAuthor`],
[`query () := @thermostat.get_temperature();`, 'GetTemperature'],
[`query (p_value : Measure(C)) := @thermostat.get_temperature(), value >= p_value;`, 'GetTemperatureByValueGreaterThan'],
[`query (p_value : Measure(C)) := @thermostat.get_temperature(), value <= p_value;`, 'GetTemperatureByValueLessThan'],
return process.env.XDG_CONFIG_HOME;
return os.homedir() + '/.config';
}
function getUserCacheDir() {
if (process.env.XDG_CACHE_HOME)
return process.env.XDG_CACHE_HOME;
return os.homedir() + '/.cache';
}
function getFilesDir() {
if (process.env.THINGENGINE_HOME)
return path.resolve(process.env.THINGENGINE_HOME);
else
return path.resolve(getUserConfigDir(), 'almond-test');
}
class Platform extends Tp.BasePlatform {
// Initialize the platform code
// Will be called before instantiating the engine
constructor(homedir) {
super();
homedir = homedir || getFilesDir();
this._assistant = null;
this._gettext = new Gettext();
this._filesDir = homedir;
safeMkdirSync(this._filesDir);
this._locale = 'en-US';
this._gettext.setLocale(this._locale);
this._timezone = 'America/Los_Angeles';
this._prefs = new MemoryPreferences();
function getGitConfig(key, _default) {
try {
const args = ['config', '--get', '--default', _default || '', key];
const stdout = child_process.execFileSync('git', args);
return String(stdout).trim() || _default;
} catch(e) {
// ignore error if git is not installed
if (e.code !== 'ENOENT')
throw e;
// also ignore error if the key
return _default;
}
}
class TestPlatform extends Tp.BasePlatform {
constructor() {
super();
this._thingpedia = new ThingpediaClient(this);
this._developerKey = getGitConfig('thingpedia.developer-key', process.env.THINGENGINE_DEVELOPER_KEY || null);
}
getDeveloperKey() {
return this._developerKey;
}
get type() {
return 'test';
}
get locale() {
return 'en-US';
// See COPYING for details
"use strict";
const Tp = require('thingpedia');
const { getBestEntityMatch } = require('../lib/dialogs/entity_lookup');
const THINGPEDIA_URL = 'https://almond-dev.stanford.edu/thingpedia';
const _mockPlatform = {
locale: 'en-US',
getDeveloperKey() {
return null;
}
};
const _thingpediaClient = new Tp.HttpClient(_mockPlatform, THINGPEDIA_URL);
const TEST_CASES = [
['tt:cryptocurrency_code', 'bitcoin', 'btc', 'Bitcoin'],
['tt:cryptocurrency_code', 'bitcoin cash', 'bch', 'Bitcoin Cash'],
['tt:cryptocurrency_code', 'ethereum', 'eth', 'Ethereum'],
['sportradar:eu_soccer_team', 'juventus', 'juv', 'Juventus Turin'],
['sportradar:eu_soccer_team', 'inter', 'int', 'Inter Milan'],
['sportradar:eu_soccer_team', 'arsenal', 'ars', 'Arsenal FC'],
['sportradar:eu_soccer_team', 'barcelona', 'bar', 'FC Barcelona'],
['sportradar:us_soccer_team', 'san jose earthquakes', 'sje', "San Jose Earthquakes"],
['sportradar:us_soccer_team', 'sj earthquakes', 'sje', "San Jose Earthquakes"],
['sportradar:ncaafb_team', 'stanford cardinals', 'sta', 'Stanford Cardinal'],
// Copyright 2018-2019 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna
//
// See COPYING for details
"use strict";
const assert = require('assert');
const ThingTalk = require('thingtalk');
const Tp = require('thingpedia');
const fs = require('fs');
const path = require('path');
const util = require('util');
const ThingpediaDeviceFactories = require('./thingpedia-device-factories.json');
class MockThingpediaClient extends Tp.BaseClient {
constructor() {
super(null);
this._devices = null;
this._entities = null;
this._thingpediafilename = path.resolve(path.dirname(module.filename), 'thingpedia.tt');
this._loaded = null;
}
get developerKey() {
return null;
}
get locale() {
return this._locale;
}
//
// This file is part of Genie
//
// Copyright 2018-2019 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna
//
// See COPYING for details
"use strict";
const ThingTalk = require('thingtalk');
const Tp = require('thingpedia');
const fs = require('fs');
const util = require('util');
module.exports = class FileThingpediaClient extends Tp.BaseClient {
constructor(args) {
super({ locale: args.locale, getDeveloperKey() { return null; } });
this._locale = args.locale;
this._devices = null;
this._entities = null;
this._thingpediafilename = args.thingpedia;
this._entityfilename = args.entities;
this._datasetfilename = args.dataset;
this._loaded = null;
}
get developerKey() {
return null;
}
get locale() {
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna
//
// See COPYING for details
"use strict";
const Q = require('q');
const WebSocket = require('ws');
const Tp = require('thingpedia');
class GenericRSSTrigger extends Tp.RSSPollingTrigger {
static get requiredCapabilities() {
return ['channel-state'];
}
constructor(engine, state, device, params) {
super(engine, state, device);
var ast = this.device.constructor.metadata;
this.auth = this._makeAuth(ast);
this.useOAuth2 = this.device;
}
_lateInit() {
var id = this.name;
console.log('Initializing generic RSS channel ' + id);
var ast = this.device.constructor.metadata;