#!/usr/bin/python3 from bs4 import BeautifulSoup from urllib.parse import urlparse from requests.auth import HTTPBasicAuth from getpass import getpass import requests, os, argparse, logging, re if __name__ == '__main__': tags = [] month = {"janvier":"01", "février": "02", "mars": "03", "avril":"04", "mai": "05", "juin": "06", "juillet": "07", "août": "08", "septembre": "09", "octobre": "10", "novembre": "11", "décembre": "12"} parser = argparse.ArgumentParser() parser.add_argument("--user", help="wordpress user", required=True) parser.add_argument("--file", help="HTML file", required=True) args = parser.parse_args() password = getpass() if len(password) == 0: print("No password error !!! ") exit(1) basic = HTTPBasicAuth(args.user, password) liste = ["categories", "tags"] elements = {} element = {} listelement = {} for i in liste: page = requests.get("http://localhost:8080/wp-json/wp/v2/{0}".format(i)) if page.status_code == 200: elements[i] = page.json() element[i] = [] listelement[i] = [] with open(args.file, 'r') as f: contents = f.read() soup = BeautifulSoup(contents, 'html.parser') articletitle = soup.find_all("h2", class_="articletitle") articlebody = soup.find_all("div", class_="articlebody") articledate = soup.find_all("span", class_="articledate") articleacreator = soup.find_all("span", class_="articlecreator") dateheader = soup.find_all("div", class_="dateheader") itemfooter = soup.find_all("div", class_="itemfooter") comment = soup.find_all("div", class_="comment_item") comment_post = [] for i in comment: comment_item = i.text.split("\n") footer = i.find_all("div", class_="itemfooter") comment_author = footer[0].text.split(",")[0].replace("Posté par ", "") comment_date = footer[0].find_all("abbr")[0].get("title") comment_content = "
"
for j in range(0, len(comment_item)-2):
if len(comment_item[j]) > 0:
comment_content = comment_content + comment_item[j] + "
"
comment_content = comment_content + "
"
for i in body:
if len(i.text) == 1:
bodyhtml = bodyhtml + "
"
else:
bodyhtml = bodyhtml + str(i).replace("
", "").replace("
", "").replace("