Skip to content

Instantly share code, notes, and snippets.

View wwj718's full-sized avatar

wwj718

View GitHub Profile
cookiecutter https://github.com/pydanny/cookiecutter-django
project_name [My Awesome Project]: cx_backend
project_slug [cx_backend]:
description [Behold My Awesome Project!]: changxue backend
author_name [Daniel Roy Greenfeld]: wwj718
domain_name [example.com]: istemedu.com
email [wwj718@example.com]: wuwenjie718@gmail.com
version [0.1.0]:
Select open_source_license:
@wwj718
wwj718 / event_demo.py
Created June 4, 2018 08:29
使用hass.bus.fire和listen
# https://developers.home-assistant.io/docs/en/dev_101_events.html
@wwj718
wwj718 / light_main_on.py
Created June 4, 2018 07:10
使用python来定制hass
# https://www.home-assistant.io/components/python_script/
entity_id = data.get('entity_id')
rgb_color = data.get('rgb_color', [255, 255, 255])
if entity_id is not None:
service_data = {'entity_id': entity_id, 'rgb_color': rgb_color, 'brightness': 255 }
hass.services.call('light', 'turn_on', service_data, False)
else:
service_data = {'rgb_color': rgb_color, 'brightness': 255 }
hass.services.call('light', 'turn_on',service_data,False)
@wwj718
wwj718 / lpr_demo.py
Created June 4, 2018 06:26
批量打印
# 打印lpr
import subprocess
import pathlib
p = pathlib.Path('.')
# 列出目录下所有png图片名
imgs = list(p.glob('**/*.png'))[:2]
for i in imgs:
cmd = "lpr {}".format(i)
print(cmd)
subprocess.call(cmd,shell=True)
from microbit import * # sleep, uart, button_a, display
import random
uart.init(115200)
def display_handler(data):
''' : String -> None '''
convert = {
@wwj718
wwj718 / mpy_iot.py
Created May 5, 2018 01:38
垃圾onenet
import asyncio
from hbmqtt.client import MQTTClient, ConnectException
from hbmqtt.mqtt.constants import QOS_1, QOS_2
#产品ID
username='135585'
#产品APIKey:
password = "to do"
# [mqtt|ws][s]://[username][:password]@host.domain[:port]
localhost
push
browse
log access.log
proxy / 127.0.0.1:8123 {
websocket
transparent
}
header / Access-Control-Allow-Origin *
pc程序
```
while True:
data = {"a":i}
# data = "topic-sensor-data-x" + "\r\n"
data = json.dumps(data) + "\r\n"
# data = "a" + "\r\n"
data_bytes = data.encode("utf-8")
ser.write(data_bytes)
@wwj718
wwj718 / strip.py
Created April 20, 2018 12:09
strip bug
from microbit import *
def get_topic_and_data(b):
try:
c = b.rstrip()
sleep(10)
# c = b.split(b"\r\n")[0]
# uart.write(b)
# uart.write(b'{"a": 18}\r\n') # 稳定
uart.write(c + b'\r\n')