2018年1月27日 星期六

python use request and re to get and parse web page

import requests
#from multiprocessing import Pool
from requests.exceptions import RequestException
import re
import json

def get_one_page(url):
    try:
        response = requests.get(url)
        if response.status_code ==200:
            return response.text
        return None
    except RequestException:
        return None

def parse_one_page(html):
    pattern = re.compile('<dd>.*?board-index.*?>(\d+)</i>.*?data-src="(.*?)".*?name"><a'+
                        '.*?>(.*?)</a>.*?star">(.*?)</p>.*?releasetime">(.*?)</p>'+
                        '.*?integer">(.*?)</i>.*?fraction">(.*?)</i>.*?</dd>',re.S)
    items = re.findall(pattern,html)
    for item in items:
        yield {
            'index': item[0],
            'image': item[1],
            'title': item[2],
            'actor': item[3].strip()[3:],
            'time' : item[4].strip()[5:],
            'score' : item[5] +  item[6]                   
        }
def write_to_file(content):
    with open('c://test/result.txt','a',encoding='utf-8') as f:
        f.write(json.dumps(content,ensure_ascii=False) + '\n')
        f.close()
   
def main(offset):
    url = 'https://maoyan.com/board/4?offset=' + str(offset)
    html = get_one_page(url)
    #print(html)
    for item in parse_one_page(html):
          print(item)
          write_to_file(item) 
if __name__ ==    '__main__':
    for i  in range(10):
      main(i*10)
    #pool = Pool()
    #pool.map(main, [i*10 for i in range(10)] )

2017年12月4日 星期一

rpi cam web interface

https://elinux.org/RPi-Cam-Web-Interface


先要安裝  apachpe2 和php

可以參考這一篇

https://www.stewright.me/2016/03/turn-raspberry-pi-3-php-7-powered-web-server/



sudo apt-get update
sudo apt-get dist-upgrade
 sudo apt-get install git


git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
./install.sh



2017年10月2日 星期一

口譯機器人

https://chtseng.wordpress.com/2016/06/22/%E5%8D%B3%E6%99%82%E5%8F%A3%E8%AD%AF%E6%A9%9F%E5%99%A8%E4%BA%BAdiy%EF%BC%88%E4%B8%80%EF%BC%89/




1.   sudo apt-get install flac


2,  sudo pip install PocketSphinx  -> error

 3.  sudo apt-get install swig

4, sudo apt-get install libpulse-dev

5.   sudo pip install PocketSphinx



切割成20秒的長度...太常會有問題

https://github.com/Uberi/speech_recognition/issues/132



youtube 上面有人分享用python 來產生srt file

https://www.youtube.com/watch?v=hK6dpTLYlY4



use tensorflow to speech to srt

https://www.youtube.com/watch?v=u9FPqkuoEJ8