Use sub parsers
This commit is contained in:
parent
cb91739d86
commit
e097803b94
|
@ -13,7 +13,7 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import configparser
|
||||
import os
|
||||
from datetime import date
|
||||
|
@ -33,7 +33,7 @@ from twomartens.allrisscraper import meeting
|
|||
from twomartens.allrisscraper.definitions import ALLRIS_LOGIN
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(args: argparse.Namespace) -> None:
|
||||
config_file = f"{os.getcwd()}/tm-allris-scraper-config.ini"
|
||||
if not config_module.initialize_config(config_file):
|
||||
return
|
||||
|
|
|
@ -6,10 +6,16 @@ from twomartens.allrisscraper import public
|
|||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Scrape the ALLRis website")
|
||||
parser.add_argument("mode", choices=["oparl", "internal"], help="which mode should be used")
|
||||
args = parser.parse_args()
|
||||
subparsers = parser.add_subparsers(help="sub-command help", required=True)
|
||||
oparl_parser = subparsers.add_parser("oparl", help="scrapes the public website")
|
||||
oparl_parser.add_argument("--include-organizations", action="store_true", dest="include_organizations")
|
||||
oparl_parser.set_defaults(function=public.main)
|
||||
internal_parser = subparsers.add_parser("internal", help="scrapes the internal website")
|
||||
internal_parser.set_defaults(function=internal.main)
|
||||
|
||||
if args.mode == "oparl":
|
||||
public.main()
|
||||
else:
|
||||
internal.main()
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue