def query_data(): print 'start query data' db = mysqldb.connect(host=config.read_config('database', 'host'), user=config.read_config('database', 'user'), passwd=config.read_config('database', 'passwd'), db=config.read_config('database', 'db')) cursor = db.cursor() cursor.execute(config.read_config('database', 'sql')) # 重置游标的位置 cursor.scroll(0, mode='absolute') # 搜取所有结果 results = cursor.fetchall() # 获取MYSQL里面的数据字段名称 fields = cursor.description db.close() return results, fields
def send_mail_by_xls(): print 'start send mail' _user = config.read_config('email', 'user') _pwd = config.read_config('email', 'pwd') _to = config.read_config('email', 'to') try: msg = MIMEMultipart() msg['From'] = _format_addr(u'Python爱好者 <%s>' % _user) msg['To'] = _format_addr(u'管理员 <%s>' % _to) msg['Subject'] = Header(u'来自SMTP的问候……', 'utf-8').encode() # 邮件正文是MIMEText: msg.attach(MIMEText('send with file...', 'plain', 'utf-8')) # 添加附件就是加上一个MIMEBase,从本地读取一个图片: with open( '/Users/apple/code/python/python_script/test.xls', 'rb') as f: # 设置附件的MIME和文件名,这里是png类型: # mime = MIMEBase('xls', 'xls', filename='test.xls') mime = MIMEBase('application', 'octet-stream') # 加上必要的头信息: mime.add_header('Content-Disposition', 'attachment', filename='test.xls') mime.add_header('Content-ID', '<0>') mime.add_header('X-Attachment-Id', '0') # 把附件的内容读进来: mime.set_payload(f.read()) # 用Base64编码: encoders.encode_base64(mime) # 添加到MIMEMultipart: msg.attach(mime) server = smtplib.SMTP_SSL("smtp.qq.com", 465) server.login(_user, _pwd) server.sendmail(_user, _to, msg.as_string()) server.quit() except smtplib.SMTPException, e: print "Falied,%s" % e
def main(): # Enable automatic garbage collector gc.enable() config.read_config() # Get defaults ssid = config.get_config('ssid') pwd = config.get_config('pwd') # Connect to Network and save if sta_if = do_connect(ssid, pwd) chipid = hexlify(machine.unique_id()) config.set_config('chipid', chipid) # Turn on Access Point only if AP PWD is present apssid = 'YoT-%s' % bytes.decode(chipid) appwd = config.get_config('appwd') do_accesspoint(apssid, appwd) # To have time to press ^c time.sleep(2) # Update config with new values # Get Network Parameters if sta_if != None: (address, mask, gateway, dns) = sta_if.ifconfig() config.set_config('address', address) config.set_config('mask', mask) config.set_config('gateway', gateway) config.set_config('dns', dns) config.set_config('mac', hexlify(sta_if.config('mac'), ':')) # Ok now we save configuration! config.set_time() config.save_config() # Registering register_url = config.get_config('register') authorization = config.get_config('authorization') if register_url != '' and authorization != '': from register import register # When it starts send a register just to know we're alive tim = machine.Timer(-1) print('register init 5min') tim.init(period=300000, mode=machine.Timer.PERIODIC, callback=lambda t: register(register_url, authorization)) # Free some memory ssid = pwd = None apssid = appwd = None address = mask = gateway = dns = None gc.collect() # Launch Server from httpserver import Server s = Server(8805) # construct server object s.activate() # server activate with try: s.wait_connections() # activate and run except KeyboardInterrupt: pass except Exception: machine.reset() pass
def main(): # Enable automatic garbage collector gc.enable() if machine.reset_cause() == machine.DEEPSLEEP_RESET: print('wake from deep sleep') hard_reset = False else: hard_reset = True print('wake from hard reset') # Read from file the whole configuration config.read_config() # Get WiFi defaults and connect ssid = config.get_config('ssid') pwd = config.get_config('pwd') interface = do_connect(ssid, pwd, network.STA_IF, hard_reset) if not interface: # Turn on Access Point only with passw apssid = 'YoT-%s' % bytes.decode(chipid) appwd = config.get_config('appwd') interface = do_connect(apssid, appwd, network.AP_IF) if not interface: print('Restart 10"') time.sleep(10.0) machine.reset() # Set Parameters (address, mask, gateway, dns) = interface.ifconfig() chipid = hexlify(machine.unique_id()) config.set_config('address', address) config.set_config('mask', mask) config.set_config('gateway', gateway) config.set_config('dns', dns) config.set_config('mac', hexlify(interface.config('mac'), ':')) config.set_config('chipid', chipid) # We can set the time now # Set Time RTC from ntptime import settime try: settime() (y, m, d, h, mm, s, c, u) = time.localtime() starttime = '%d-%d-%d %d:%d:%d UTC' % (y, m, d, h, mm, s) except: starttime = '2061-01-01 00:00:00' print('Cannot set time') if hard_reset: config.set_config('starttime', starttime) # Set hostname interface.config(dhcp_hostname=chipid) config.set_config('hostname', interface.config('dhcp_hostname')) # We will save new configuration only at powerup if hard_reset: config.save_config() # Free some memory ssid = pwd = None apssid = appwd = None address = mask = gateway = dns = None gc.collect() # The application hook from application import application application() # Restart print('Restarting') time.sleep(5.0) # If everything was ok we go to sleep for a while sleep = config.get_config('sleep') if sleep: from gotosleep import gotosleep gotosleep(int(sleep)) machine.reset()
from config import config from config import generate from static.StaticHandler import StaticHandler generate.generate_config() config = config.read_config("firstprojectflash") # dummy name # If project_type is static, call the following functions. if config.project_type == "static": bucket = StaticHandler(config) bucket.create_bucket() bucket.set_public_policy() bucket.configure_website_hosting() # bucket.upload_files("./upload")
from flask import Flask, Response from flask_cors import CORS from gevent.pywsgi import WSGIServer import requests from config.config import read_config from ml.yolo import Yolo, Prediction from util.encoding import encode_image_base64 from util.image import image_from_json, draw_rectangles from PIL import Image from util.mock import handle_mock_room app = Flask(__name__) CORS(app) server_config = read_config('./resources/server_config.json') yolo_config = read_config('./resources/yolo_config.json') model = Yolo(yolo_config['weights_path'], yolo_config['config_path'], yolo_config['labels_path']) def draw_rectangles_from_predictions(image: Image, predictions: List[Prediction]) -> Image: bounding_boxes = [prediction.bounding_box for prediction in predictions] return draw_rectangles(image, bounding_boxes) def get_room_image_for_prediction(room_address) -> Tuple[str, any]: """ Returns the image to be used for the prediction from the raspberry pi server. :return: The image to be used for the prediction. """
# おまじない : パスの追加 import os import sys path = os.path.join(os.path.abspath(os.curdir), '../') sys.path.append(path) from config.config import read_config config = read_config('../config/config.ini')
def _create_config(self): """Set up config""" self.config = read_config()
def get_model() -> Yolo: yolo_config = read_config('resources/yolo_config.json') model = Yolo(yolo_config['weights_path'], yolo_config['config_path'], yolo_config['labels_path']) return model
from typing import Tuple, List, Optional from flask import Flask, Response from flask_cors import CORS from gevent.pywsgi import WSGIServer import requests from config.config import read_config from ml.yolo import Yolo from util.encoding import encode_image_base64 from util.image import image_from_json, draw_rectangles app = Flask(__name__) CORS(app) server_config = read_config('config/server_config.json') yolo_config = read_config('config/yolo_config.json') model = Yolo(yolo_config['weights_path'], yolo_config['config_path'], yolo_config['labels_path']) def get_room_image_for_prediction(room_address) -> Tuple[str, any]: """ Returns the image to be used for the prediction from the raspberry pi server. :return: The image to be used for the prediction. """ image_server_rest = room_address + server_config['image_rest_api'] result = requests.get(image_server_rest) result = result.json() if 'image' in result: return result['room_name'], image_from_json(result)