2023-03-23 23:28:57 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
from getpass import getpass
|
2023-04-08 12:27:30 +02:00
|
|
|
import argparse, logging
|
|
|
|
import WPImport
|
2023-03-28 22:29:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--user", help="wordpress user", required=True)
|
2023-04-06 21:53:56 +02:00
|
|
|
parser.add_argument("--file", help="HTML file", default="")
|
|
|
|
parser.add_argument("--directory", help="HTML directory", default="")
|
2023-03-29 22:31:35 +02:00
|
|
|
parser.add_argument("--wordpress", help="URL Wordpress", required=True)
|
2023-04-08 12:17:43 +02:00
|
|
|
parser.add_argument("--debug", help="Verbosity", action="store_true")
|
|
|
|
parser.add_argument("--logfile", help="Log file", default="")
|
|
|
|
parser.add_argument("--quiet", help="No console output", action="store_true")
|
|
|
|
|
2023-03-28 22:29:55 +02:00
|
|
|
args = parser.parse_args()
|
2023-04-08 12:17:43 +02:00
|
|
|
logger = logging.getLogger('insert wordpress')
|
|
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
|
|
|
|
if args.quiet is False:
|
|
|
|
ch = logging.StreamHandler()
|
|
|
|
if args.debug is True:
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
ch.setLevel(logging.DEBUG)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
ch.setLevel(logging.INFO)
|
|
|
|
ch.setFormatter(formatter)
|
|
|
|
logger.addHandler(ch)
|
|
|
|
|
|
|
|
|
|
|
|
if len(args.logfile) > 0:
|
|
|
|
fileHandler = logging.FileHandler(args.logfile)
|
|
|
|
if args.debug is True:
|
|
|
|
fileHandler.setLevel(logging.DEBUG)
|
|
|
|
else:
|
|
|
|
fileHandler.setLevel(logging.INFO)
|
|
|
|
fileHandler.setFormatter(formatter)
|
|
|
|
logger.addHandler(fileHandler)
|
|
|
|
|
2023-03-28 22:29:55 +02:00
|
|
|
password = getpass()
|
|
|
|
if len(password) == 0:
|
2023-04-08 12:17:43 +02:00
|
|
|
logger.error("No password error !!! ")
|
2023-03-28 22:29:55 +02:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
basic = HTTPBasicAuth(args.user, password)
|
2023-04-08 12:17:43 +02:00
|
|
|
importWp = WPimport(basic, args.wordpress, logger)
|
2023-04-06 21:53:56 +02:00
|
|
|
if len(args.file) > 0:
|
2023-04-07 22:55:27 +02:00
|
|
|
importWp.fromFile(args.file.split(","))
|
2023-04-06 21:53:56 +02:00
|
|
|
exit(0)
|
|
|
|
if len(args.directory) > 0:
|
|
|
|
importWp.fromDirectory(args.directory)
|