add .gitgnore + add function

This commit is contained in:
Valentin CZERYBA 2023-03-28 22:29:55 +02:00
parent d96d38e508
commit 19229bc65b
2 changed files with 22 additions and 13 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
backup/
web_scrap.log

View File

@ -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"]))
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)