add password parameter and fix post to delete 75%

This commit is contained in:
Valentin CZERYBA 2023-05-04 00:47:06 +02:00
parent 4789fe80aa
commit 21d2f35e6e
2 changed files with 26 additions and 18 deletions

View File

@ -96,6 +96,7 @@ if __name__ == '__main__':
import_parser = subparsers.add_parser("import")
import_parser.add_argument("--user", help="wordpress user", required=True)
import_parser.add_argument("--password", help="password wordpress's user", default="")
import_parser.add_argument("--file", help="HTML file", default="")
import_parser.add_argument("--directory", help="HTML directory", default="")
import_parser.add_argument("--canalblog", help="URL Canalblog", default="")
@ -103,6 +104,7 @@ if __name__ == '__main__':
import_parser.add_argument("--serial", help="Serial execution", action="store_true")
export_parser = subparsers.add_parser("export")
export_parser.add_argument("--url", help="canblog URL to be scraping", required=True)
@ -143,6 +145,8 @@ if __name__ == '__main__':
logger.addHandler(fileHandler)
if args.command == "import":
password = args.password
if len(args.password) == 0:
password = getpass()
if len(password) == 0:
logger.error("No password error !!! ")

View File

@ -228,6 +228,8 @@ class WPimport:
data = page.content
img_type = "image/{0}".format(img_type_file)
if img_type_file == "jpg":
img_type = "image/jpeg"
headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)}
try:
r = self._request.post("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, headers=headers, data=data)
@ -509,6 +511,8 @@ class WPimport:
result = page.json()
if len(result) > 0:
for i in result:
self._logger.debug("{0} : Data for post to delete : {1}".format(self._name, i))
if i["title"]["rendered"] == title:
self._logger.info("{0} : Page {1} already exist and going to delete".format(self._name, title))
post_id = i["id"]
try: