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.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
@ -33,7 +33,7 @@ from twomartens.allrisscraper import meeting
|
||||||
from twomartens.allrisscraper.definitions import ALLRIS_LOGIN
|
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"
|
config_file = f"{os.getcwd()}/tm-allris-scraper-config.ini"
|
||||||
if not config_module.initialize_config(config_file):
|
if not config_module.initialize_config(config_file):
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,10 +6,16 @@ from twomartens.allrisscraper import public
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Scrape the ALLRis website")
|
parser = argparse.ArgumentParser(description="Scrape the ALLRis website")
|
||||||
parser.add_argument("mode", choices=["oparl", "internal"], help="which mode should be used")
|
subparsers = parser.add_subparsers(help="sub-command help", required=True)
|
||||||
args = parser.parse_args()
|
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":
|
args = parser.parse_args()
|
||||||
public.main()
|
args.func(args)
|
||||||
else:
|
|
||||||
internal.main()
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue