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 = subparsers.add_parser("import")
|
||||||
import_parser.add_argument("--user", help="wordpress user", required=True)
|
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("--file", help="HTML file", default="")
|
||||||
import_parser.add_argument("--directory", help="HTML directory", default="")
|
import_parser.add_argument("--directory", help="HTML directory", default="")
|
||||||
import_parser.add_argument("--canalblog", help="URL Canalblog", 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")
|
import_parser.add_argument("--serial", help="Serial execution", action="store_true")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export_parser = subparsers.add_parser("export")
|
export_parser = subparsers.add_parser("export")
|
||||||
|
|
||||||
export_parser.add_argument("--url", help="canblog URL to be scraping", required=True)
|
export_parser.add_argument("--url", help="canblog URL to be scraping", required=True)
|
||||||
@ -143,6 +145,8 @@ if __name__ == '__main__':
|
|||||||
logger.addHandler(fileHandler)
|
logger.addHandler(fileHandler)
|
||||||
|
|
||||||
if args.command == "import":
|
if args.command == "import":
|
||||||
|
password = args.password
|
||||||
|
if len(args.password) == 0:
|
||||||
password = getpass()
|
password = getpass()
|
||||||
if len(password) == 0:
|
if len(password) == 0:
|
||||||
logger.error("No password error !!! ")
|
logger.error("No password error !!! ")
|
||||||
|
@ -228,6 +228,8 @@ class WPimport:
|
|||||||
|
|
||||||
data = page.content
|
data = page.content
|
||||||
img_type = "image/{0}".format(img_type_file)
|
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)}
|
headers={ 'Content-Type': img_type,'Content-Disposition' : 'attachment; filename={0}'.format(img_name)}
|
||||||
try:
|
try:
|
||||||
r = self._request.post("http://{0}/wp-json/wp/v2/media".format(self._wordpress), auth=self._basic, headers=headers, data=data)
|
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()
|
result = page.json()
|
||||||
if len(result) > 0:
|
if len(result) > 0:
|
||||||
for i in result:
|
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))
|
self._logger.info("{0} : Page {1} already exist and going to delete".format(self._name, title))
|
||||||
post_id = i["id"]
|
post_id = i["id"]
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user