add tags
This commit is contained in:
parent
eae95d5671
commit
3622e37942
@ -7,9 +7,8 @@ import requests, os, argparse, logging
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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"}
|
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 = argparse.ArgumentParser()
|
||||||
parser.add_argument("--user", help="wordpress user", required=True)
|
parser.add_argument("--user", help="wordpress user", required=True)
|
||||||
parser.add_argument("--file", help="HTML file", required=True)
|
parser.add_argument("--file", help="HTML file", required=True)
|
||||||
@ -20,6 +19,13 @@ if __name__ == '__main__':
|
|||||||
exit(1)
|
exit(1)
|
||||||
basic = HTTPBasicAuth(args.user, password)
|
basic = HTTPBasicAuth(args.user, password)
|
||||||
|
|
||||||
|
page = requests.get("http://localhost:8080/wp-json/wp/v2/tags")
|
||||||
|
|
||||||
|
if page.status_code == 200:
|
||||||
|
tags = page.json()
|
||||||
|
print(tags)
|
||||||
|
|
||||||
|
|
||||||
with open(args.file, 'r') as f:
|
with open(args.file, 'r') as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
|
|
||||||
@ -35,13 +41,28 @@ if __name__ == '__main__':
|
|||||||
rel = i.get("rel")
|
rel = i.get("rel")
|
||||||
if rel[0] == 'tag':
|
if rel[0] == 'tag':
|
||||||
tag.append(i.text)
|
tag.append(i.text)
|
||||||
print(tag)
|
listtag = []
|
||||||
|
for i in tag:
|
||||||
|
tag_exist = False
|
||||||
|
for j in tags:
|
||||||
|
if j["name"] == i:
|
||||||
|
tag_exist = True
|
||||||
|
listtag.append(j["id"])
|
||||||
|
if tag_exist is False:
|
||||||
|
data = {"name": i}
|
||||||
|
page = requests.post("http://localhost:8080/wp-json/wp/v2/tags", auth=basic, data=data)
|
||||||
|
if page.status_code == 201:
|
||||||
|
result = page.json()
|
||||||
|
listtag.append(result["id"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
title = articletitle[0].text
|
title = articletitle[0].text
|
||||||
body = articlebody[0]
|
body = articlebody[0]
|
||||||
hour = articledate[0].text
|
hour = articledate[0].text
|
||||||
time = dateheader[0].text.split(" ")
|
time = dateheader[0].text.split(" ")
|
||||||
data = {"title":title, "content":body, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": [5]}
|
data = {"title":title, "content":body, "status":"publish", "date": "{0}-{1}-{2}T{3}:00".format(time[2],month[time[1]],time[0], hour), "tags": listtag}
|
||||||
#print(data)
|
print(data)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
|
page = requests.post("http://localhost:8080/wp-json/wp/v2/posts", auth=basic, data=data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user