2021-07-22 20:00:00 -04:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
# NOTE: Many options listed here are not implemented yet.
|
|
|
|
|
|
|
|
license = """
|
|
|
|
rsstube - get RSS feeds from supported sites
|
|
|
|
Copyright (C) 2021
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
2021-12-28 19:00:00 -05:00
|
|
|
# get installation path
|
|
|
|
import os.path
|
|
|
|
path = os.path.realpath(os.path.abspath(__file__))
|
|
|
|
path = path[0:path.rfind("/")]
|
|
|
|
path = path[0:path.rfind("/")]
|
|
|
|
|
|
|
|
def update():
|
|
|
|
if os.path.isdir(path + "/.git"):
|
|
|
|
print("rsstube appears to have been downloaded with git.")
|
|
|
|
try:
|
|
|
|
import git
|
|
|
|
print("Attempting to update rsstube...")
|
|
|
|
g = git.cmd.Git(path)
|
|
|
|
output = g.pull()
|
|
|
|
print(output)
|
|
|
|
except ImportError:
|
|
|
|
print("python3-GitPython must be installed to update rsstube this way.")
|
|
|
|
print("If you don't want to install python3-GitPython, you can run `git pull` in the directory where rsstube was installed.")
|
|
|
|
else:
|
|
|
|
print("rsstube appears to have been manually downloaded or installed with a package manager. Use that same method to update.")
|
|
|
|
|
2021-07-22 20:00:00 -04:00
|
|
|
def options(params):
|
|
|
|
import sys,getopt,glob
|
|
|
|
from utils import debug,notify,warn,error
|
|
|
|
|
|
|
|
# general settings
|
|
|
|
network = True
|
|
|
|
|
|
|
|
## verbosity: in addition to the feed, print...
|
|
|
|
## 0: no messages (suppress errors)
|
|
|
|
## 1: only error messages
|
|
|
|
## 2: error messages and warnings
|
|
|
|
## 3: [default] errors, warnings, and info
|
|
|
|
## 4: all messages, including debugging info
|
|
|
|
verbosity = None
|
|
|
|
|
|
|
|
# pycurl args
|
|
|
|
d = dict()
|
|
|
|
header = []
|
|
|
|
|
|
|
|
# count number of arguments
|
|
|
|
arg_count = 0
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(params,"A:c:H:hnp:qtUVv", [
|
|
|
|
"user-agent=",
|
|
|
|
"ciphers=",
|
|
|
|
"compressed",
|
|
|
|
"header=",
|
|
|
|
"help",
|
|
|
|
"license",
|
|
|
|
"non-network",
|
|
|
|
"proxy",
|
|
|
|
"quiet",
|
|
|
|
"sites",
|
|
|
|
"suppress-errors",
|
|
|
|
"tls-max=",
|
|
|
|
"tls13-ciphers=",
|
|
|
|
"verbose",
|
|
|
|
"verbosity=",
|
|
|
|
"version"
|
|
|
|
])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
error ("Invalid options. See the README or manual for legal rsstube flags.")
|
|
|
|
sys.exit(2)
|
|
|
|
for opt, arg in opts:
|
|
|
|
if arg == "":
|
|
|
|
arg_count += 1
|
|
|
|
else:
|
|
|
|
arg_count += 2
|
|
|
|
|
|
|
|
if opt in ("-A", "--user-agent"):
|
|
|
|
d["user_agent"] = arg
|
|
|
|
elif opt == "--ciphers":
|
|
|
|
d["ciphers"] = arg
|
|
|
|
elif opt == "--compressed":
|
|
|
|
d["compressed"] = True
|
|
|
|
elif opt in ("-h", "--help"):
|
|
|
|
print ("Usage: rsstube [OPTIONS] URL")
|
|
|
|
# not available yet
|
|
|
|
# print ("Use `man rsstube` to see the manual for rsstube.")
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("-H", "--header"):
|
|
|
|
header.append(arg)
|
|
|
|
elif opt in ("--license"):
|
|
|
|
print(license)
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("-n", "--non-network"):
|
|
|
|
network = False
|
|
|
|
elif opt in ("-p", "--proxy"):
|
|
|
|
d["proxy"] = arg
|
|
|
|
elif opt in ("-q", "--quiet"):
|
|
|
|
verbosity = 1
|
|
|
|
elif opt in ("--sites"):
|
|
|
|
print ("Site-specific support:")
|
|
|
|
for test in sorted(glob.glob(path + "/tests/*.txt")):
|
|
|
|
site = test[test.rfind("/")+1:(-4)]
|
|
|
|
print ("- " + site)
|
|
|
|
|
|
|
|
print ("\nGeneric support:")
|
|
|
|
for test in sorted(glob.glob(path + "/tests/generic/*.txt")):
|
|
|
|
site = test[test.rfind("/")+1:(-4)]
|
|
|
|
print ("- " + site)
|
|
|
|
sys.exit()
|
|
|
|
elif opt in ("--suppress-errors"):
|
|
|
|
verbosity = 0
|
|
|
|
elif opt == "--tls-max":
|
|
|
|
d["tls_max"] = arg
|
|
|
|
elif opt == "--tls13-ciphers":
|
|
|
|
d["tls13_ciphers"] = arg
|
2021-12-28 19:00:00 -05:00
|
|
|
elif opt in ("-U", "--update"):
|
|
|
|
update()
|
|
|
|
sys.exit()
|
2021-07-22 20:00:00 -04:00
|
|
|
elif opt in ("-v", "--verbose"):
|
|
|
|
verbosity = 4
|
|
|
|
elif opt == "--verbosity":
|
|
|
|
v = int(arg)
|
|
|
|
if v >= 0 and v <= 4:
|
|
|
|
verbosity = v
|
|
|
|
else:
|
|
|
|
print ("Invalid verbosity: " + arg)
|
|
|
|
elif opt in ("-V", "--version"):
|
|
|
|
version = open(path + "/docs/version","r")
|
|
|
|
|
|
|
|
# only go to -1 to cut EOL character
|
|
|
|
print (version.readline()[:-1])
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
d["header"] = header
|
|
|
|
return network,verbosity,d,arg_count
|