From 19229bc65bd0d332ce447a623c5d35ceb040f7ae Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 28 Mar 2023 22:29:55 +0200 Subject: [PATCH] add .gitgnore + add function --- .gitignore | 2 ++ insert_wordpress.py | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9171fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +backup/ +web_scrap.log diff --git a/insert_wordpress.py b/insert_wordpress.py index be12c65..babec3a 100644 --- a/insert_wordpress.py +++ b/insert_wordpress.py @@ -5,19 +5,9 @@ from requests.auth import HTTPBasicAuth from getpass import getpass import requests, os, argparse, logging, re - -if __name__ == '__main__': +def insertWordpress(file, basic): 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 = {} @@ -32,7 +22,7 @@ if __name__ == '__main__': listelement[i] = [] - with open(args.file, 'r') as f: + with open(file, 'r') as f: contents = f.read() soup = BeautifulSoup(contents, 'html.parser') @@ -109,6 +99,8 @@ if __name__ == '__main__': result = page.json() if len(result) == 0: page_exist = False + else: + print("La page {0} existe deja".format(title)) if page_exist == False: page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data) @@ -121,4 +113,19 @@ if __name__ == '__main__': page = requests.post("http://localhost:8080/wp-json/wp/v2/comments", auth=basic, data=data) print(page.status_code) if page.status_code == 201: - print("Commentaire ajoute pour {0}".format(result["title"]["raw"])) \ No newline at end of file + print("Commentaire ajoute pour {0}".format(result["title"]["raw"])) + + + +if __name__ == '__main__': + 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) + insertWordpress(args.file, basic) \ No newline at end of file