-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.py
66 lines (49 loc) · 1.91 KB
/
Post.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
import random
from datetime import datetime, timedelta, date
from bs4 import BeautifulSoup
from Comment import Comment
import requests
import re
class PostComments(Comment):
def __init__(self, context, rate, post_id, name, token):
super().__init__(context, rate)
self.post_id = post_id
self.name = name
self.token = token.tokenkey
def send_comment(self,):
post_url = "http://localhost/wp-comments-post.php"
myobj = {'rating': self.rate,
'comment': self.context,
'author': self.name,
'submit': 'Submit',
'comment_post_ID': self.post_id,
'comment_parent': '0'}
post_request = requests.post(post_url, data=myobj)
regex_comment_id = re.findall('<div id="comment-(.*?)" class="comment_container"><img alt',
str(post_request.content))
print(regex_comment_id)
if regex_comment_id != [] or int(regex_comment_id[-1]) >= 0:
self.edit_comment(regex_comment_id[-1])
#17609
#1005002505477256
def edit_comment(self, comment_id):
post_url = "http://localhost/wp-json/wp/v2/comments/" + str(comment_id)
print(post_url)
curlHeaders = {
"Authorization": self.token,
"Content-Type": "application/json",
"Accept": "application/json",
}
postDict = {
"date_gmt": self.gen_datetime(),
"status": "approved"
}
x = requests.post(post_url, json=postDict, headers=curlHeaders)
@staticmethod
def gen_datetime():
start_date = date.today().replace(day=1, month=1).toordinal()
end_date = date.today().toordinal()
random_day = date.fromordinal(random.randint(start_date, end_date))
json_datetime = str(random_day) + "T10:16:34"
return json_datetime