今さらPython

NHKニュースでも読んでみますか。

#!/usr/bin/env python3

import feedparser as fp
import datetime
import os
import subprocess
from playsound import playsound

class Jtalk():
   def talk(self,str):
       # 出力先を設定
       self.wavfile = "/var/tmp/newsone.wav"
       # 既にファイルがあったら消しておく。
       if(os.path.exists(self.wavfile) == True):
           os.remove(self.wavfile)
       os.environ["WAVFILE"] = self.wavfile
       os.environ["TALK"] = str
       os.environ["Voice"] = "/home/"+os.environ["USER"]+"/Downloads/MMDAgent/MMDAgent_Example-1.8/Voice/mei/mei_normal.htsvoice"
       print(os.environ["TALK"])
       subprocess.run("echo $TALK | /usr/bin/open_jtalk -x /var/lib/mecab/dic/open-jtalk/naist-jdic/ -m $Voice -r 1.0 -ow $WAVFILE",shell=True)
       playsound(self.wavfile)

class News():
   def __init__(self,d,title,summary):
       self.date = d
       self.title = title
       self.summary= summary

def filewrite(self,title,d,summary,filename):
   with open(filename,"w") as f:
       f.write(d,"\t",title,"\t",summary,"\n")
 
################

d = fp.parse("https://www.nhk.or.jp/rss/news/cat0.xml")
jj = Jtalk()
s = []
 
for entry in d.entries:
   year = entry.published_parsed.tm_year
   month = entry.published_parsed.tm_mon
   day = entry.published_parsed.tm_mday
   hour = entry.published_parsed.tm_hour
   minute = entry.published_parsed.tm_min
   #d = datetime.datetime(year,month,day,hour,minute,0).strftime("%Y/%m/%d %H:%M:%S")
   d = datetime.datetime(year,month,day,hour,minute,0).strftime("%Y年%m月%d日 %H時%M分")
   dd = News(d,entry.title,entry.summary)
   s.append(dd)

ans = "ニュースは全部で" + str(len(s)) + "件あります。"
jj.talk(ans)

k=1
for t in s:
   jj.talk(str(k)+"件めです。")
   jj.talk(t.date)
   jj.talk(t.title)
   jj.talk(t.summary)
   k=k+1

jj.talk("以上です。")

うん。


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS