add import from url

This commit is contained in:
Valentin CZERYBA 2023-04-10 00:00:01 +02:00
parent cd50e45493
commit e74dfc2b73
2 changed files with 27 additions and 2 deletions

View File

@ -14,6 +14,18 @@ class WPimport:
# Public method # Public method
def fromUrl(self, webpage):
for page in webpage:
r = requests.get(page)
if r.status_code == 200:
soup = BeautifulSoup(r.content, self._parser)
articlebody = soup.find_all("div", class_="articlebody")
if len(articlebody) > 0:
self._addOrUpdatePost(soup)
else:
self._addOrUpdateFeaturedMedia(soup)
def fromDirectory(self, directory): def fromDirectory(self, directory):
directory = "{0}/archives".format(directory) directory = "{0}/archives".format(directory)
directories = self._getDirectories([], "{0}".format(directory)) directories = self._getDirectories([], "{0}".format(directory))

View File

@ -37,7 +37,7 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
logger = logging.getLogger('insert wordpress') logger = logging.getLogger('import export canalblog')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
if args.quiet is False: if args.quiet is False:
@ -75,6 +75,19 @@ if __name__ == '__main__':
if len(args.directory) > 0: if len(args.directory) > 0:
importWp.fromDirectory(args.directory) importWp.fromDirectory(args.directory)
exit(0) exit(0)
if len(args.canalblog) > 0:
try:
o = urlparse(args.canalblog)
o = o._replace(scheme="https")
url = o.geturl().replace(":///", "://")
except Exception as err:
logger.error("parsing error : {0}".format(err))
exit(1)
exportWp = WPExport.WPExport(url, logger, args.parser, args.directory)
webpage = exportWp.getUrlPage()
importWp.fromUrl(webpage)
if args.command == "export": if args.command == "export":
try: try:
o = urlparse(args.url) o = urlparse(args.url)