├── .gitignore ├── .provision ├── hosts ├── playbook.yml ├── readme.md ├── roles │ ├── autohome │ │ ├── files │ │ │ ├── cmdb.sh │ │ │ ├── config.py │ │ │ ├── nginx │ │ │ │ └── cmdb.conf │ │ │ └── supervisor │ │ │ │ └── cmdb.conf │ │ └── tasks │ │ │ └── main.yml │ ├── common │ │ ├── files │ │ │ └── sources.list │ │ └── tasks │ │ │ └── main.yml │ ├── env │ │ └── tasks │ │ │ └── main.yml │ └── soft │ │ ├── files │ │ └── pip.conf │ │ └── tasks │ │ └── main.yml └── vars │ └── common.yml ├── README.md ├── docs ├── cmd.md ├── install.md ├── reg.md └── static │ ├── 1.png │ └── 2.png └── src ├── cmd ├── __init__.py ├── readme.md └── weather.py ├── config.ini ├── core ├── __init__.py ├── config.py └── functions.py ├── input ├── __init__.py └── readme.md ├── main.py └── recognize ├── __init__.py ├── cat.py └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.wav 3 | env/* 4 | src/myapp.log 5 | myapp.log -------------------------------------------------------------------------------- /.provision/hosts: -------------------------------------------------------------------------------- 1 | [auto_cmdb] 2 | 192.168.22.10 ansible_ssh_pass=vagrant -------------------------------------------------------------------------------- /.provision/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | user: vagrant 4 | sudo: yes 5 | vars_files: 6 | - ["vars/common.yml"] 7 | roles: 8 | - common 9 | - env 10 | - soft 11 | - autohome -------------------------------------------------------------------------------- /.provision/readme.md: -------------------------------------------------------------------------------- 1 | 等待完善 -------------------------------------------------------------------------------- /.provision/roles/autohome/files/cmdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | `ps -ef | grep '/home/www/virpython/bin/uwsgi -s /tmp/uwsgi.sock' | awk '{print $2}' | xargs kill -9` 3 | RELEASE_VERSION=`cat /home/www/config/RELEASE_VERSION_GA` 4 | cd /home/www/release/$RELEASE_VERSION/src/cmdb/ 5 | /home/www/virpython/bin/uwsgi -s /tmp/uwsgi.sock -w manage:app -p 4 --chmod-socket=662 --buffer-size=32768 --post-buffering=1 -------------------------------------------------------------------------------- /.provision/roles/autohome/files/config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | SQLALCHEMY_DATABASE_URI = 'mysql://root:@127.0.0.1:3306/cmdb' 4 | SSHKEY_DATABASE_URI = 'mysql://root:anjuke@10.10.3.165:3306/sshkey?charset=utf8' 5 | SQLALCHEMY_ENCODING = "utf-8" 6 | SQLALCHEMY_ECHO = False 7 | DEBUG = True 8 | 9 | PRODUCT_CONFIG = '/home/www/config.py' 10 | -------------------------------------------------------------------------------- /.provision/roles/autohome/files/nginx/cmdb.conf: -------------------------------------------------------------------------------- 1 | server{ 2 | listen 80; 3 | server_name 192.168.22.10; 4 | location / { 5 | try_files $uri @yourapplication; 6 | } 7 | location @yourapplication{ 8 | include uwsgi_params; 9 | uwsgi_pass unix:/tmp/uwsgi.sock; 10 | uwsgi_connect_timeout 10; 11 | uwsgi_read_timeout 10; 12 | uwsgi_send_timeout 10; 13 | uwsgi_param UWSGI_PYHOME /home/www/virpython; 14 | } 15 | } -------------------------------------------------------------------------------- /.provision/roles/autohome/files/supervisor/cmdb.conf: -------------------------------------------------------------------------------- 1 | [program:cmdb] 2 | command=/bin/sh /home/www/cmdb_shells/cmdb.sh 3 | 4 | stdout_logfile = /var/log/uwsgi_access.log -------------------------------------------------------------------------------- /.provision/roles/autohome/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: git clone cmdb 3 | git: repo=http://gitlab.corp.anjuke.com/Vincentguo/cmdb.git dest={{ codepath }}/release/{{ version }} 4 | 5 | - name: virtualenv virpython 6 | command: chdir={{ codepath }} /usr/bin/virtualenv virpython 7 | 8 | - name: pip install module 9 | pip: name={{ item }} virtualenv=/home/www/virpython 10 | with_items: 11 | - flask 12 | - Flask-Script 13 | - Flask-Assets 14 | - sqlalchemy 15 | - Flask-SQLAlchemy 16 | - flask-login 17 | - mysql-python 18 | - IPy 19 | - PyPages 20 | - celery-with-redis 21 | - ply 22 | - cssmin 23 | - jsmin 24 | - xlwt 25 | - requests 26 | - uwsgi 27 | 28 | 29 | - name: cp supervisor file 30 | copy: src=supervisor/cmdb.conf dest=/etc/supervisor/conf.d/ 31 | 32 | - name: cp cmdb shell 33 | copy: src=cmdb.sh dest={{ codepath }}/cmdb_shells/ 34 | 35 | - name: cp config 36 | copy: src=config.py dest={{ codepath }}/release/{{ version }}/src/cmdb 37 | 38 | - name: touch ga 39 | shell: echo '{{ version }}' > {{ codepath }}/config/RELEASE_VERSION_GA 40 | 41 | - name: cp nginx for cmdb 42 | copy: src=nginx/cmdb.conf dest=/etc/nginx/conf.d/ 43 | 44 | - name: restart nginx 45 | service: name=nginx state=restarted 46 | 47 | - name: creat database cmdb 48 | mysql_db: db=cmdb state=present login_user=root login_password= encoding=utf8 collation=utf8_general_ci 49 | 50 | - name: create tables 51 | shell: cd {{ codepath }}/release/{{ version }}/src/cmdb && /home/www/virpython/bin/python manage.py create_data 52 | -------------------------------------------------------------------------------- /.provision/roles/common/files/sources.list: -------------------------------------------------------------------------------- 1 | deb http://mirrors.163.com/ubuntu/ precise main restricted 2 | deb http://mirrors.163.com/ubuntu/ precise-updates main restricted 3 | deb http://mirrors.163.com/ubuntu/ precise universe 4 | deb http://mirrors.163.com/ubuntu/ precise-updates universe 5 | deb http://mirrors.163.com/ubuntu/ precise multiverse 6 | deb http://mirrors.163.com/ubuntu/ precise-updates multiverse 7 | deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse 8 | deb http://mirrors.163.com/ubuntu/ precise-security main restricted 9 | deb http://mirrors.163.com/ubuntu/ precise-security universe 10 | deb http://mirrors.163.com/ubuntu/ precise-security multiverse 11 | -------------------------------------------------------------------------------- /.provision/roles/common/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: copy 163 source.list 3 | copy: src=sources.list dest=/etc/apt/ 4 | 5 | - name: apt-get update 6 | apt: update-cache=yes -------------------------------------------------------------------------------- /.provision/roles/env/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: mkdir dirs 3 | file: path={{ item }} state=directory owner={{ user }} group={{ group }} mode=0755 4 | with_items: 5 | - "{{ codepath }}" 6 | - "{{ codepath }}/config" 7 | - "{{ codepath }}/release" 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.provision/roles/soft/files/pip.conf: -------------------------------------------------------------------------------- 1 | [global] 2 | index-url = http://pypi.douban.com/simple/ -------------------------------------------------------------------------------- /.provision/roles/soft/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install soft 3 | apt: pkg={{ item }} state=present force=yes 4 | with_items: 5 | - nginx 6 | - mysql-client 7 | - mysql-server 8 | - python-virtualenv 9 | - git 10 | - supervisor 11 | - libmysqlclient-dev 12 | - python-dev 13 | 14 | - name: restart nginx 15 | service: name=nginx state=restarted 16 | 17 | - name: mkdir .pip 18 | file: path=/home/vagrant/.pip state=directory owner={{ user }} group={{ group }} mode=0755 19 | 20 | - name: cp pip.conf 21 | copy: src=pip.conf dest=/home/vagrant/.pip/ 22 | -------------------------------------------------------------------------------- /.provision/vars/common.yml: -------------------------------------------------------------------------------- 1 | --- 2 | codepath: /home/www 3 | user: vagrant 4 | group: www-data 5 | version: 20150501 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 智能家居 2 | ====================== 3 | * 控制家里所有的家电 4 | * 声控 5 | * 人脸识别 6 | 7 | 系统图 8 | ====================== 9 | * 人脸识别(借助讯飞语音和百度人脸识别平台) 10 | * 输入部分 (IOS & Android & 微信订阅号或者公众号) 11 | * 文字 12 | * 语音 (借助讯飞语音和百度语音开放平台) 13 | * 语意识别 (java apache Lucene) 14 | * [指令中心](docs/cmd.md) 15 | 16 | APP UI图 17 | ====================== 18 | * ![UI图1](docs/static/1.png) 19 | * ![UI图2](docs/static/2.png) 20 | 21 | 开发语言 22 | ====================== 23 | * python 24 | * java 25 | 26 | 27 | 代码结构 28 | ====================== 29 | * src 源码目录 30 | * docs 文档目录 31 | * .provision ansible自动化 ```ansible-playbook -i host playbook.yml 32 | 33 | 快速入门 34 | ===================== 35 | * 操作系统 Ubuntu 36 | * ansible自动化 37 | * [环境配置](docs/install.md) 38 | * [文本分类](http://textgrocery.readthedocs.org/zh/latest/index.html) 39 | * [PM2.5](http://www.pm25.in/api_doc) 40 | * [人脸识别](http://www.faceplusplus.com.cn/uc_home/) 41 | * [电视节目表](http://epg.tvsou.com/programys/TV_44/Channel_18/W1.htm) 42 | -------------------------------------------------------------------------------- /docs/cmd.md: -------------------------------------------------------------------------------- 1 | 指令集 2 | ========== 3 | * 电器 4 | * 电视机 5 | * 空调 6 | * 娱乐 7 | * 听歌曲 8 | * 看新闻 9 | * 开美图 10 | * 生活 11 | * 天气预报 12 | * 编程 -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | python 依赖包 2 | ============== 3 | * jieba 4 | * tgrocery(based on jieba) 5 | * BeautifulSoup(HTML/XML的解析器) -------------------------------------------------------------------------------- /docs/reg.md: -------------------------------------------------------------------------------- 1 | 语义识别 2 | =========== 3 | * 文本分类 4 | * [TextGrocery](https://github.com/apanly/TextGrocery) -------------------------------------------------------------------------------- /docs/static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apanly/autohome/0e7cf2179a21fca4191995109639df1fbba168d2/docs/static/1.png -------------------------------------------------------------------------------- /docs/static/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apanly/autohome/0e7cf2179a21fca4191995109639df1fbba168d2/docs/static/2.png -------------------------------------------------------------------------------- /src/cmd/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- -------------------------------------------------------------------------------- /src/cmd/readme.md: -------------------------------------------------------------------------------- 1 | [指令集](../../docs/cmd.md) 2 | ========== 3 | -------------------------------------------------------------------------------- /src/cmd/weather.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import requests, hashlib, urllib, json 3 | 4 | # from cmd.weather import Weather 5 | # target = Weather('上海') 6 | # target.get() 7 | 8 | class Weather: 9 | def __init__(self,city): 10 | self.ak = "721lCBGTp217nYZ5DLAuzCob" 11 | self.sk = "rHtM1RS581VBYNOiC3j8GpEVb3qtihkL" 12 | self.domain = "http://api.map.baidu.com" 13 | self.city = city 14 | self.url = "/telematics/v3/weather" 15 | 16 | def get(self): 17 | sn = self.caculateAKSN() 18 | weather_url = '%s%s?location=%s&output=json&ak=%s&sn=%s'%(self.domain,self.url,self.city,self.ak,sn) 19 | r = requests.get(weather_url) 20 | data = json.loads(r.content) 21 | if data['error'] == 0: 22 | pm25 = data['results'][0]['pm25'] 23 | weather = data['results'][0]['weather_data'] 24 | print 'PM2.5:%s'%pm25 25 | for item in weather: 26 | print '----------------' 27 | print '日期:%s'%item['date'] 28 | print '温度:%s'%item['temperature'] 29 | print '风速:%s'%item['wind'] 30 | print '天气:%s'%item['weather'] 31 | 32 | def caculateAKSN(self): 33 | querystring = "location=%s&output=json&ak=%s"%(urllib.quote_plus(self.city), self.ak) 34 | sn = '%s?%s%s'%(self.url,querystring,self.sk) 35 | sn = urllib.quote_plus(sn) 36 | return hashlib.md5(sn.encode('utf-8')).hexdigest() 37 | -------------------------------------------------------------------------------- /src/config.ini: -------------------------------------------------------------------------------- 1 | [global] #全局配置参数 2 | PID = '/tmp/autohome.pid' 3 | 4 | [language] 5 | STOP = '收到终止命令,退出程序' -------------------------------------------------------------------------------- /src/core/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- -------------------------------------------------------------------------------- /src/core/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import ConfigParser 3 | 4 | class Config: 5 | config = None 6 | 7 | @staticmethod 8 | def init(config_path): 9 | fp = open(config_path) 10 | config = ConfigParser.ConfigParser() 11 | config.readfp(fp) 12 | Config.config = config 13 | 14 | @staticmethod 15 | def get(scope, name): 16 | config = Config.config 17 | return config.get(scope, name) 18 | 19 | @staticmethod 20 | def set(scope, name, value=None): 21 | Config.config.set(scope, name, value) -------------------------------------------------------------------------------- /src/core/functions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os, signal, logging 3 | 4 | def Usage(): 5 | logging.info('Usage: python main.py start/stop/restart') 6 | exit() 7 | 8 | 9 | #为了防止并发加入PID文件 10 | def writePID(pid_path): 11 | fd=os.open(pid_path,os.O_CREAT|os.O_EXCL|os.O_RDWR) 12 | os.write(fd,"%s" % str(os.getpid())) 13 | os.close(fd) 14 | 15 | #删除本应用程序的PID 16 | def deletePID(pid_path): 17 | try: 18 | os.remove(pid_path) 19 | except: 20 | pass 21 | 22 | def stop(pid_path): 23 | if os.path.exists(pid_path): 24 | fd=open(pid_path) 25 | pid=int(fd.readline()) 26 | fd.close() 27 | try: 28 | deletePID() 29 | os.kill(pid,signal.SIGTERM) 30 | except: 31 | raise SystemExit('1:收到终止命令,退出程序') 32 | raise SystemExit('2:收到终止命令,退出程序') 33 | 34 | def init_log(): 35 | #日志级别大小关系为:CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET 36 | logging.basicConfig( 37 | level=logging.DEBUG, 38 | format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', 39 | datefmt='%a, %d %b %Y %H:%M:%S', 40 | filename='myapp.log', 41 | filemode='a') 42 | console = logging.StreamHandler() 43 | console.setLevel(logging.DEBUG) 44 | formatter = logging.Formatter('%(name)-6s: %(levelname)-8s %(message)s') 45 | console.setFormatter(formatter) 46 | logging.getLogger('').addHandler(console) -------------------------------------------------------------------------------- /src/input/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- -------------------------------------------------------------------------------- /src/input/readme.md: -------------------------------------------------------------------------------- 1 | 输入部分 2 | ========== 3 | * 输入类型 4 | * 文本 5 | * 音频 6 | 7 | * 输入媒介 8 | * 微信订阅号 9 | * APP(IOS & Andriod) 10 | 11 | * 特殊处理 12 | * 音频转化为文本(stt) -------------------------------------------------------------------------------- /src/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sys, os 3 | reload(sys) 4 | sys.setdefaultencoding('utf-8') 5 | sys.path.append(".")#加入默认的扫描路径 6 | 7 | import atexit 8 | import logging 9 | from core.functions import writePID, deletePID, Usage, stop, init_log 10 | from core.config import Config 11 | 12 | def init(): 13 | path=os.path.split(os.path.realpath(__file__))[0] 14 | config_path = '%s/config.ini'%path 15 | Config.init(config_path) 16 | CACHEFOLDER = os.getenv('HOME') + '/.cache/autohome/' 17 | if not os.path.exists(CACHEFOLDER): 18 | os.makedirs(CACHEFOLDER) 19 | PIDLOG="%sautohome.pid"%CACHEFOLDER 20 | Config.set("global",'PID',PIDLOG) 21 | init_log() 22 | 23 | def main(): 24 | writePID(PIDLOG) 25 | from cmd.weather import Weather 26 | target = Weather('上海') 27 | target.get() 28 | 29 | if __name__ == "__main__": 30 | init() 31 | PIDLOG = Config.get('global','PID') 32 | atexit.register(lambda:deletePID(PIDLOG)) 33 | params=sys.argv 34 | if len(params)<2: 35 | Usage() 36 | else: 37 | if params[1]=="start": 38 | if os.path.exists(PIDLOG): 39 | logging.info("Program is running") 40 | Usage() 41 | else: 42 | main() 43 | elif params[1]=="stop": 44 | stop(PIDLOG) 45 | elif params[1]=="restart": 46 | pass 47 | -------------------------------------------------------------------------------- /src/recognize/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- -------------------------------------------------------------------------------- /src/recognize/cat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from tgrocery import Grocery 3 | 4 | class Cat: 5 | def __init__(self): 6 | self.grocery = Grocery('autohome') 7 | 8 | def test(self): 9 | print self.grocery.get_load_status() -------------------------------------------------------------------------------- /src/recognize/readme.md: -------------------------------------------------------------------------------- 1 | 语义分析 2 | ======= 3 | * 找出分类(每个指定对应一个分类) 4 | * 分析语义(剔除无意义的词) 5 | * 结巴分词 6 | * 分词后搜索 --------------------------------------------------------------------------------