add url and file
This commit is contained in:
parent
47f504beb5
commit
f0b4ba5e27
@ -10,6 +10,7 @@ from lib.WPImport import WPimport
|
|||||||
from lib.WPExport import WPExport
|
from lib.WPExport import WPExport
|
||||||
from lib.WPRemove import WPRemove
|
from lib.WPRemove import WPRemove
|
||||||
from lib.WPChange import WPChange
|
from lib.WPChange import WPChange
|
||||||
|
from lib.WPMenu import WPMenu
|
||||||
|
|
||||||
def errorRevert(logger, revert, tmp):
|
def errorRevert(logger, revert, tmp):
|
||||||
if revert is True:
|
if revert is True:
|
||||||
@ -202,8 +203,14 @@ if __name__ == '__main__':
|
|||||||
change_parser.add_argument("--file",
|
change_parser.add_argument("--file",
|
||||||
default="",
|
default="",
|
||||||
help="File")
|
help="File")
|
||||||
|
|
||||||
|
|
||||||
|
menu_parser = subparsers.add_parser("menu")
|
||||||
|
menu_parser.add_argument("--user", help="wordpress user", required=True)
|
||||||
|
menu_parser.add_argument("--password", help="password wordpress's user", default="")
|
||||||
|
menu_parser.add_argument("--file", help="HTML file", default="")
|
||||||
|
menu_parser.add_argument("--canalblog", help="URL Canalblog", default="")
|
||||||
|
menu_parser.add_argument("--wordpress", help="URL Wordpress", required=True)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logger = logging.getLogger('import export canalblog')
|
logger = logging.getLogger('import export canalblog')
|
||||||
@ -240,7 +247,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
os.makedirs(args.tmp, exist_ok=True)
|
os.makedirs(args.tmp, exist_ok=True)
|
||||||
|
|
||||||
if args.command == "import" or args.command == "remove":
|
if args.command == "import" or args.command == "remove" or args.command = "menu":
|
||||||
password = args.password
|
password = args.password
|
||||||
if len(args.password) == 0:
|
if len(args.password) == 0:
|
||||||
password = getpass()
|
password = getpass()
|
||||||
@ -341,4 +348,12 @@ if __name__ == '__main__':
|
|||||||
changeWp = WPChange(logger=logger)
|
changeWp = WPChange(logger=logger)
|
||||||
for filei in args.file.split(","):
|
for filei in args.file.split(","):
|
||||||
changeWp.fromFile(filei)
|
changeWp.fromFile(filei)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
if args.command == "menu":
|
||||||
|
menuWp = WPMenu(name="Thread-1", basic=basic, wordpress=args.wordpress, logger=logger, parser=args.parser, ssl_canalblog=ssl_canalblog, ssl_wordpress=ssl_wordpress)
|
||||||
|
if len(args.file) > 0:
|
||||||
|
menuWp.fromFile(args.file)
|
||||||
|
if len(args.canalblog) > 0:
|
||||||
|
menuWp.fromUrl(args.canalblog)
|
||||||
exit(0)
|
exit(0)
|
@ -34,23 +34,32 @@ class WPMenu:
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
print("{0} : Import finished for {1}".format(self._name, self._wordpress))
|
print("{0} : Import finished for {1}".format(self._name, self._wordpress))
|
||||||
|
|
||||||
# Public method
|
# Public method
|
||||||
|
|
||||||
|
## From file
|
||||||
|
|
||||||
|
def fromFile(self, files):
|
||||||
|
if os.path.exists(files):
|
||||||
|
with open(files, 'r') as f:
|
||||||
|
self._logger.info("{0} : File is being processed : {1}".format(self._name, files))
|
||||||
|
content = f.read()
|
||||||
|
self._menu(content)
|
||||||
|
else:
|
||||||
|
self._logger.error("{0} : File isn't exist : {1}".format(self._name, files))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Get from URL
|
## Get from URL
|
||||||
|
|
||||||
def fromUrl(self):
|
def fromUrl(self, canalblog):
|
||||||
try:
|
try:
|
||||||
o = urlparse(self._canalblog)
|
o = urlparse(canalblog)
|
||||||
o = o._replace(scheme=self._protocol_canalblog)
|
o = o._replace(scheme=self._protocol_canalblog)
|
||||||
i = o.geturl().replace(":///", "://")
|
i = o.geturl().replace(":///", "://")
|
||||||
page = self._request.get(i)
|
page = self._request.get(i)
|
||||||
if page.status_code == 200:
|
if page.status_code == 200:
|
||||||
soup = BeautifulSoup(page.text, self._parser)
|
self._logger.info("{0} : Page web is being processed : {1}".format(self._name, i))
|
||||||
ul = soup.find_all("ul", id="listsmooth")
|
self._menu(page.content)
|
||||||
for anchor in ul[0].find_all("li"):
|
|
||||||
li = anchor.find_all("li")
|
|
||||||
for content in li:
|
|
||||||
a = content.find("a")
|
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} : index didn't get due status code : {1}".format(self._name, page.status_code))
|
self._logger.error("{0} : index didn't get due status code : {1}".format(self._name, page.status_code))
|
||||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
@ -58,4 +67,14 @@ class WPMenu:
|
|||||||
self._logger.error("{0} : Connection error for get url {1} : {2}".format(self._name, webpage[i], err))
|
self._logger.error("{0} : Connection error for get url {1} : {2}".format(self._name, webpage[i], err))
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, webpage[i], err))
|
self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, webpage[i], err))
|
||||||
|
|
||||||
|
|
||||||
|
def _menu(self, content):
|
||||||
|
|
||||||
|
soup = BeautifulSoup(page.text, self._parser)
|
||||||
|
ul = soup.find_all("ul", id="listsmooth")
|
||||||
|
for anchor in ul[0].find_all("li"):
|
||||||
|
li = anchor.find_all("li")
|
||||||
|
for content in li:
|
||||||
|
a = content.find("a")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user