スキップしてメイン コンテンツに移動

RSSからYoutube/Podcast配信

情報収集自動化

RSSを使って情報収集自動化

情報のソースとなるRSSフィードを選び出します。
各自いつも見ているNewsサイトなどのRSSフィードを取得してください。
今回はGoogleNewsです。



Pythonライブラリの追加

以下のライブラリをインストールしてください。
※pipが無ければapt-getしてください。
$ pip install feedparser
$ pip install extractcontent3
$ pip install google-api-python-client
$ pip install google-auth-httplib2
$ pip install google-auth-oauthlib 
$ pip install google-cloud-translate 

Pythonプログラム

test.pyを作成して以下のコードを記述します。
ここではGoogleNewsのRSSフィードからタイトルとソース記事を引っ張ってきます。
test.py
# coding: utf-8
import feedparser

def getRss():
    rssUrl = 'https://news.google.com/news/rss/headlines/section/topic/TECHNOLOGY'
    rssLang = '?hl=en-US&gl=US&ceid=US:en'
    feed = feedparser.parse(rssUrl + rssLang)
    for entry in feed.entries:
            title = entry.get('title')
            print('title:' + title)
            link = entry.get('link')
            print('link:' + link)

if __name__ == '__main__':
    getRss() 
結果はこちら
$ python3 test.py
title:PS5 And Xbox Shortages To Continue Into 2022
link:https://news.google.com/__i/rss/rd/articles/CBMiVWh0dHBzOi8va290YWt1LmNvbS94Ym94LWhlYWQtZXhwbGFpbnMtY29uc29sZS1zaG9ydGFnZXMtd2lsbC1jb250aW51ZS1pbnRvLTE4NDc3ODc0NzjSAVlodHRwczovL2tvdGFrdS5jb20veGJveC1oZWFkLWV4cGxhaW5zLWNvbnNvbGUtc2hvcnRhZ2VzLXdpbGwtY29udGludWUtaW50by0xODQ3Nzg3NDc4L2FtcA?oc=5
         :
        以下略
         :

URLから本文を取得

RSSフィードから取得したURLから記事本文を読み込みます。

Pythonライブラリの追加

$ pip install extractcontent3

Pythonプログラム

URLからextractcontent3を使用して記事本文を抜き出します。
test.py
# coding: utf-8
import feedparser
import requests
from extractcontent3 import ExtractContent

extractor = ExtractContent()
# オプション値を指定する
opt = {"threshold":50}
extractor.set_option(opt)

def getBody(link):
    try :
        res = requests.get(link)
        extractor.analyse(res.text)
        text, title = extractor.as_text()
        print('===================================================')
        print('title:' + title)
        print('===================================================')
        print('body :' + text.replace('. ', '.\n'))
        print('===================================================')
    except Exception as e :
        print(e)

def getRss():
    rssUrl = 'https://news.google.com/news/rss/headlines/section/topic/TECHNOLOGY'
    rssLang = '?hl=en-US&gl=US&ceid=US:en'
    feed = feedparser.parse(rssUrl + rssLang)
    for entry in feed.entries:
            link = entry.get('link')
            getBody(link)

if __name__ == '__main__':
    getRss()

結果はこちら
$ python3 test.py
===================================================
title:PS5 And Xbox Shortages To Continue Into 2022
===================================================
body :Its likely that if you are reading these words on this website, you already know how hard it can be to get your hands on the new consoles.
Well, Ive got some bad news straight from Xbox VP of gaming Phil Spencer: Finding a console aint getting easier anytime soon.

As spotted and transcribed by VGC, Phil Spencer spoke to The Wrap recently and explained that while chip shortages were partly to blame for the ongoing console shortages, there was more going on with the situation.
I think its probably too isolated to talk about it as just a chip problem, Spencer said.
When I think about, what does it mean to get the parts necessary to build a console today, and then get it to the markets where the demand is, there are multiple kind of pinch points in that process.
And I think regretfully its going to be with us for months and months, definitely through the end of this calendar year and into the next calendar year.
Spencer claims he and everyone at Mircosoft is working hard to get consoles out the door and into peoples homes, but he expects it will continue to be a challenge for quite a while.
The thing thats most disappointing is just the fan disappointment, Spencer admitted.
People really want this new generation of consoles—theyre good consoles, both from us and the other platform holders—and they want the new functionality.

===================================================

次はひとまず要約や翻訳は置いておいてBlogger自動投稿を行います。
 

このブログの人気の投稿

RSSからYoutube/Podcast配信

皆さん、情報収集はどの様にされていますでしょうか? 私は最先端に情報に触れる為、海外ニュースをRSSで購読しているのですが、私の英語力/語彙力では時間が掛かかってしょうがない。 また、できれば目で読むのではなく、音声で聞き流しながら通勤や他の作業中に行いたい。 という事で自動でニュースを収集・要約・翻訳し、それをブログ・ポッドキャスト・Youtubeに自動投稿するPythonプログラムを作成して時短化しました。 その手法を公開してますので参考にしてください。 Bloggerの立ち上げ方 GCPとBloggerの連携 情報収集自動化 Blogger自動投稿 本文要約 翻訳 音声作成 動画作成 Youtubeにアップロード Youtubeの投稿制限の回避方法 Podcast配信 翻訳・要約の改善(GPT-3) 以下のURLで上記から作成したブログやYoutubeを公開しています。参考までに見てください。 ブログ:海外ニュースを仕入れてお届け YouTube:海外Newsを仕入れてお届け Amazon Music:海外ニュースを仕入れてお届け。 Google Podcasts:海外ニュースを仕入れてお届け。 Apple Podcasts:海外ニュースを仕入れてお届け。

本文要約

要約 今回は現在使用している方法とは異なり、実装が簡単な要約方法になります。 参考元にはニューラルネットワーク(accel-brain-base)を使用した例などもありますので、そちらを参考にしてください。 Pythonライブラリの追加 以下のライブラリをインストールしてください。 $ pip install pysummarization Pythonプログラム test.pyに以下のコードを記述します。 ここでソース記事の各行を重みづけしてから、重要度の高い5つの行だけを選択します。 test.py from pysummarization.nlpbase.auto_abstractor import AutoAbstractor from pysummarization.tokenizabledoc.simple_tokenizer import SimpleTokenizer from pysummarization.abstractabledoc.top_n_rank_abstractor import TopNRankAbstractor def getSummary ( text ): # Object of automatic summarization. auto_abstractor = AutoAbstractor () # Set tokenizer. auto_abstractor . tokenizable_doc = SimpleTokenizer () # Set delimiter for making a list of sentence. auto_abstractor . delimiter_list = [ ". " , ". \n " , " \n " ] # Object of abstracting and filtering document. abstractable_doc = TopNRankAbstractor () # Summarize document. result_dict = auto_abstrac

Bloggerの立ち上げ

Bloggerとは BloggerはGoogleのサービスの一つで、無料でブログを始めることができます。 Googleアカウントが必要となりますので、ない方はアカウントの作成をお願いします。 Bloggerサイトへのログイン https://www.blogger.com/から「ブログの作成」を選択してください。 Googleアカウントを聞かれるので、Googleアカウントとパスワードを入力してください。 ブログの名前を入力 作成するブログの名前を決めます。これは後から変えられるのでとりあえずは書こうとしてる内容に沿ったものを記入してください。 ブログのURL(インターネット上の所在地)を作成します。 こちらも変更できる(※)のですがので、頻繁に変更すると読者や検索などから外されてしますので、個人名や法人名など変更しないことを前提に名付けた方が良いと思います。 (※「.blogspot.com」以外のカスタムドメインを自分でとって、それを設定することもできます) プロファイルの作成 ブログが作成されるとプロファイルの作成画面が出てきます。ブログ読者に見られることを意識して、ユーザー名やわかりやすい説明を記入しましょう。 以上でブログが作成できました。作成したURLをブラウザに打ち込んでみましょう! 貴方だけのブログサイトが立ち上がりました。 次は GCP(Google Cloud Platform)とBloggerを連携 させてみましょう。 参考: Blogger Help