Skip to content

Instantly share code, notes, and snippets.

View johnlpage's full-sized avatar

John Page johnlpage

  • MongoDB Inc.
  • Glasgow
View GitHub Profile
import requests
from pprint import pprint
import json
import pymongo
with open("/home/pi/.mongo_uri.txt") as f:
uri = f.readline().strip()
mongoclient = pymongo.MongoClient(uri)
from phue import Bridge
from pprint import pprint
import pymongo
b = Bridge("192.168.1.214")
# If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
b.connect()
# Get the bridge state (This returns the full dictionary that you can explore)
import aiohttp
import pysmartthings
import pymongo
import json
import asyncio
from pprint import pprint
import datetime
with open("/home/pi/.smartthing_token") as f:
from PyP100 import PyP110
import json
from pprint import pprint
import pymongo
with open("/home/pi/.mongo_uri.txt") as f:
uri = f.readline().strip()
mongoclient = pymongo.MongoClient(uri)
tapoplugs = {
[
{ $match: { type: "electric" } },
{
$setWindowFields:
{
sortBy: { date: 1 },
output: {
smoothsumusage: {
$expMovingAvg: { input: { $sum: "$devices.watts"} , alpha: 0.9}
}
[
{ $match: { type: "electric" } },
{ $unwind: "$devices" },
{ $match: { "devices.watts": { $gt: 0 } } },
{ $setWindowFields: { sortBy: { date: 1 }, partitionBy: "$devices.name",
output: { totalUsage: { $integral: { input: "$devices.watts", unit: "hour" } } } }},
]
exports = async function() {
let APIKEY = context.values.get('ifftkey_value')
const collection = context.services.get("mongodb-atlas").db("energy").collection("meter");
const docs = await collection.find({ type: "electric" }).sort({_id:-1}).limit(1).toArray();
if(docs.length == 1)
{
if(docs[0].solarwatts > 800) {
console.log("turning off lights")
const response = context.http.get({ url: `https://maker.ifttt.com/trigger/AllLightsOff/with/key/${APIKEY}` })
}
{
CustomerId: 123,
Name : { First: "John", Last: "Page"},
TotalSpend: 261,
Purchases: [
{ PurchaseID: 519, Item: 25, Quantity: 2, Price: 50 },
{ PurchaseID: 530, Item: 25, Quantity: 1, Price: 180 },
{ PurchaseId: 640, Item: 9, Quantity: 1, Price: 31 }
]
}
//Query From https://data.dft.gov.uk/anonymised-mot-test/MOT_user_guide_v4.docx
private final String getlatestByVehicleSQL = "select " +
"tr.*, " +
"ft.FUEL_TYPE, " +
"tt.TESTTYPE AS TYPENAME, " +
"to2.RESULT, " +
"ti.*, " +
"fl.*, " + "tid.MINORITEM,tid.RFRDESC,tid.RFRLOCMARKER,tid.RFRINSPMANDESC,tid.RFRADVISORYTEXT,tid.TSTITMSETSECID, " +
"b.ITEMNAME AS LEVEL1, " +
"c.ITEMNAME AS LEVEL2, " +
public String getMOTResultInJSON(String identifier) {
long identifierLong;
try {
identifierLong = Long.valueOf(identifier);
Bson byIdQuery = Filters.eq("vehicleid", identifierLong);
testObj = testresults.find(byIdQuery).limit(1).first();
if (testObj != null) {
return testObj.toJson();
}
} catch (Exception e) {