#!/usr/bin/python3 # NOTE: Many options listed here are not implemented yet. license = """ rsstube - tool for finding RSS/Atom feeds for pages 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 2 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 . """ # 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("GitPython must be installed to update rsstube this way.") print("If you don't want to install 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.") def options(params): import sys,getopt,glob from utils import debug,notify,warn,error # general settings network = True output_format = "" output_filename = None ## 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:hno:p:qtUVv", [ "user-agent=", "ciphers=", "header=", "help", "license", "non-network", "output=", "output-format=", "proxy", "quiet", "sites", "suppress-errors", "tls-max=", "tls13-ciphers=", "unbreak", "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 opt in ("-A", "--user-agent"): d["user_agent"] = arg arg_count += 2 elif opt == "--ciphers": d["ciphers"] = arg arg_count += 2 elif opt in ("-h", "--help"): print ("Usage: rsstube [OPTIONS] URL") # not available yet # print ("Use `man rsstube` to see the manual for rsstube.") arg_count += 1 sys.exit() elif opt in ("-H", "--header"): header.append(arg) arg_count += 2 elif opt in ("--license"): print(license) arg_count += 1 sys.exit() elif opt in ("-n", "--non-network"): network = False arg_count += 1 elif opt in ("-o", "--output"): output_filename = arg arg_count += 2 elif opt == "--output-format": if str.lower(arg) in ("opml", "url"): output_format = str.lower(arg) arg_count += 2 elif opt in ("-p", "--proxy"): d["proxy"] = arg arg_count += 2 elif opt in ("-q", "--quiet"): verbosity = 1 arg_count += 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) arg_count += 1 sys.exit() elif opt in ("--suppress-errors"): verbosity = 0 arg_count += 1 elif opt == "--tls-max": d["tls_max"] = arg arg_count += 2 elif opt == "--tls13-ciphers": d["tls13_ciphers"] = arg arg_count += 2 elif opt == "--unbreak": # attempt to unbreak hostile websites (e.g., Cloudflare) # based on Tor Browser cURL request d["user_agent"] = 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' header = [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language: en-US,en;q=0.5', 'Connection: keep-alive', 'Upgrade-Insecure-Requests: 1', 'Sec-Fetch-Dest: document', 'Sec-Fetch-Mode: navigate', 'Sec-Fetch-Site: none', 'Sec-Fetch-User: ?1', 'Cache-Control: max-age=0' ] arg_count += 1 elif opt in ("-U", "--update"): update() arg_count += 1 sys.exit() elif opt in ("-v", "--verbose"): verbosity = 4 arg_count += 1 elif opt == "--verbosity": v = int(arg) if v >= 0 and v <= 4: verbosity = v else: print ("Invalid verbosity: " + arg) arg_count += 2 elif opt in ("-V", "--version"): version = open(path + "/docs/version","r") # only go to -1 to cut EOL character print (version.readline()[:-1]) arg_count += 1 sys.exit() d["header"] = header return network,verbosity,d,arg_count,output_format,output_filename