add password parameter and fix post to delete 75%
This commit is contained in:
parent
4789fe80aa
commit
21d2f35e6e
@ -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,10 +145,12 @@ if __name__ == '__main__':
|
||||
logger.addHandler(fileHandler)
|
||||
|
||||
if args.command == "import":
|
||||
password = getpass()
|
||||
if len(password) == 0:
|
||||
logger.error("No password error !!! ")
|
||||
exit(1)
|
||||
password = args.password
|
||||
if len(args.password) == 0:
|
||||
password = getpass()
|
||||
if len(password) == 0:
|
||||
logger.error("No password error !!! ")
|
||||
exit(1)
|
||||
|
||||
basic = HTTPBasicAuth(args.user, password)
|
||||
wordpress = args.wordpress.split(",")
|
||||
|
@ -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,21 +511,23 @@ class WPimport:
|
||||
result = page.json()
|
||||
if len(result) > 0:
|
||||
for i in result:
|
||||
self._logger.info("{0} : Page {1} already exist and going to delete".format(self._name, title))
|
||||
post_id = i["id"]
|
||||
try:
|
||||
params = {"force":1}
|
||||
page = self._request.delete("http://{0}/wp-json/wp/v2/posts/{1}".format(self._wordpress, post_id), auth=self._basic, headers=headers, params=params)
|
||||
except Exception as err:
|
||||
self._logger.error("{0} : Connection error for delete post : {1}".format(self._name, err))
|
||||
exit(1)
|
||||
if page.status_code == 200:
|
||||
result = page.json()
|
||||
self._logger.info("{0} : Post deleted : {1}".format(self._name, title))
|
||||
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:
|
||||
params = {"force":1}
|
||||
page = self._request.delete("http://{0}/wp-json/wp/v2/posts/{1}".format(self._wordpress, post_id), auth=self._basic, headers=headers, params=params)
|
||||
except Exception as err:
|
||||
self._logger.error("{0} : Connection error for delete post : {1}".format(self._name, err))
|
||||
exit(1)
|
||||
if page.status_code == 200:
|
||||
result = page.json()
|
||||
self._logger.info("{0} : Post deleted : {1}".format(self._name, title))
|
||||
|
||||
else:
|
||||
self._logger.error("{0} : Post not deleted due status code : {1}".format(self._name, page.status_code))
|
||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||
else:
|
||||
self._logger.error("{0} : Post not deleted due status code : {1}".format(self._name, page.status_code))
|
||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||
else:
|
||||
self._logger.error("{0} : Connection for delete post error with status code : {1}".format(self._name, page.status_code))
|
||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||
|
Loading…
x
Reference in New Issue
Block a user