こんなの。
#!/usr/bin/env python
# pipで入れたモジュールが動くかテスト。
# (あと、ネット環境が動くかもテスト)
import datetime
import feedparser
#import jaconv
import os
import re
import subprocess
import sys
import time
myself = sys.argv[0]
# 主要(0)
#key=0
# 社会(1)
key=1
# 国際(6)
p = re.compile(r'\-max=([0-9]+)$',flags=re.IGNORECASE)
p2 = re.compile(r'\-key=([0-9]+)$',flags=re.IGNORECASE)
p3 = re.compile(r'\-get=([0-9]+)$',flags=re.IGNORECASE)
p5 = re.compile(r'\-view=([0-9]+)$',flags=re.IGNORECASE)
p4 = re.compile(r'\-help$',flags=re.IGNORECASE)
# 記事の最大数
o=18
g=-1
g2=-1
for x in sys.argv:
if(p.search(x) != None):
o=int(re.sub(p,'\\1',x))
if(o < 0):
o = o * -1
elif(p2.search(x) != None):
key=int(re.sub(p2,'\\1',x))
elif(p4.search(x) != None):
print("1. news title: "+myself)
print("2. news key: "+myself+" --key=(news key)")
print("3. news summary: "+myself+" --get=(news key)")
print("4. call www: "+myself+" -view=(news key)")
print("5. This message: "+myself+" --help")
quit()
elif(p3.search(x) != None):
g=int(re.sub(p3,'\\1',x))
if(g < 0):
g = g * -1
#print("get: "+str(g))
elif(p5.search(x) != None):
g2=int(re.sub(p5,'\\1',x))
if(g2 < 0):
g2 = g2 * -1
print("get: "+str(g2))
url = "https://www.nhk.or.jp/rss/news/cat"+str(key)+".xml"
d = feedparser.parse(url)
gg = 0
for entry in d.entries:
if(g >= 0 or g2 >= 0):
if(gg == g):
print(entry.title)
print(entry.link)
print(entry.summary)
elif(gg == g2):
subprocess.run(["start",entry.link],shell=True)
else:
print(str(gg)+"\t"+entry.title+"\n\t"+entry.link)
gg = gg + 1
o = o - 1
if(o < 1):
break