Implementation of automatic timing comment function on Python CSDN platform

Let's learn programming together 2021-10-29 05:54:21
implementation automatic timing comment function

Csdn Automatic evaluation function

Preface

A while ago , See some bloggers automatically comment under the article , Of course, I welcome you to comment on my article . I also thought about it , If I'm here for development automation evaluation , How do I do it .

First , What we need to think about , Let's list them one by one .

1、 Access to the article , And get the article id

2、 Get the interface of evaluation .

3、 How to deal with repeated evaluation .

4、 How system interrupts are handled .

Text

One 、 Analyze and get articles id

Get into csdn, Find the list of articles , Press F12, Analyze the article data return interface and return data . We extract the main data .

Then get the interface we need , The detailed steps are not explained here .

In the same way , Send a message under your article , You can get the interface for sending comments .

next , Let's think about our process .

Two 、 Process design

We can do it in two ways :

1、 Get the list of articles , Then get the article id, Then query whether to comment , Skip comments , Comment without comment .

advantage : There is no need to store any data , Reduce operation .

shortcoming : Article repeated query , Repeat query whether to comment , The efficiency is not high .

2、 We first save all the obtained article lists to the database , Then by getting the unreviewed articles in the database id, Evaluate , After the evaluation , Mark as evaluated , There is no need to query whether it has been evaluated .

advantage : Efficiency is relative 1 Improve , Will not repeatedly query whether to comment .

shortcoming : Database server required , Need to master database related operations .

Here we use the second way , But our previous articles may have what we have commented on , therefore , We still need to judge whether there have been comments , So our process changed .

3、 ... and 、 Database design

We have designed the process , Then design the database fields .

We need articles id, article url, author , Comment field , Like or not , Of course, you can add other fields .

Let's start creating tables :( Prevent nicknames from having emoticons , Coding does not use utf8, use utf8mb4 )

CREATE TABLE `article` (
`articleId` bigint NOT NULL COMMENT 'id',
`articleDetailUrl` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'url',
`articleTitle` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT ' title ',
`nickName` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT ' nickname ',
`hotRankScore` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT ' degree of heat ',
`comment` int NOT NULL DEFAULT '0' COMMENT ' Whether to comment on (0, no ,1 yes )',
`like` int NOT NULL DEFAULT '0' COMMENT ' Do you like it (0, no ,1 yes )',
`insert_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`articleId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

such , We have created our data table .

Four 、 Operating the database

We've built the database , Let's think now , What operations do we need . Thinking direction , Always think about adding, deleting, modifying and checking , So you'll know better .

1、 increase : Insert article list data

2、 Delete : We don't use it here

3、 modify : No comments updated to comments

4、 Inquire about : Query non commented articles id, Query whether the article list has been inserted into the database

So we write methods :


POOL = PooledDB(
creator=pymysql, maxconnections=20, mincached=6, maxcached=None, maxshared=5,
blocking=True, maxusage=None, setsession=[], ping=0, host='127.0.0.1',port=3306,user='root',password='root',database='csdn_article',charset='utf8')
def insert_article(articleId, articleDetailUrl,articleTitle, nickName, hotRankScore):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("INSERT INTO `article`(`articleId`, `articleDetailUrl`,`articleTitle`, `nickName`, `hotRankScore`) VALUES (%s, '%s','%s', '%s', '%s');"%(articleId, articleDetailUrl,pymysql.escape_string(articleTitle), pymysql.escape_string(nickName), hotRankScore))# Use execute Method execution SQL sentence
data=db.commit()# Use fetchone() Method to get a piece of data
db.close()
return data
def select_is_insert(articleId):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("SELECT COUNT(*) FROM `article` WHERE `articleId` = %s;"%articleId)# Use execute Method execution SQL sentence
data = conn.fetchall()# Use fetchone() Method to get a piece of data
db.close()
return data[0][0]
def select_is_comment():# Query data without comments
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("SELECT `articleId`,`articleDetailUrl` FROM `article` WHERE `comment` = '0' LIMIT 0, 2;")# Use execute Method execution SQL sentence
data = conn.fetchall()# Use fetchone() Method to get a piece of data
db.close()
return data
def update_article(articleId,comment=1):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("UPDATE `article` SET `comment` =%s WHERE `articleId` = %s;"%(comment,articleId))# Use execute Method execution SQL sentence
data=db.commit()# Use fetchone() Method to get a piece of data
db.close()
return data

5、 ... and 、 obtain csdn The article data

We continue to acquire csdn The article lists ( Get... From the leaderboard ):


def qzzhrb():
""" Comprehensive hot list of the whole station """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
for y in range(0,4):
time.sleep(5)
response=requests.get("https://blog.csdn.net/phoenix/web/blog/hotRank?page="+str(y)+"&pageSize=25",headers=headers1)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
#1 To 2 Once a day
def lynrb():
""" Domain content list """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
list=["python","java","javascript"," Artificial intelligence ","php","c%2Fc%2B%2B"," big data "," Mobile development "," Data structure and algorithm "," game "," The Internet "," Operation and maintenance "," test "]
for y in range(0,2):
for i in list:
response=requests.get("https://blog.csdn.net/phoenix/web/blog/hotRank?page="+str(y)+"&pageSize=25&child_channel="+i,headers=headers1)
time.sleep(5)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
# lynrb()
# Every day 8 Click once
def xjzzb():
""" List of new authors """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
for y in range(0,5):
time.sleep(5)
response=requests.get("https://blog.csdn.net/phoenix/web/blog/newUserRank?page="+str(y)+"&pageSize=20",headers=headers1)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
# xjzzb()
def recommend():
""" Recommendation column """
header={
"path": "/api/articles?type=more&category=home&shown_offset=0",
"accept-language": "zh-CN,zh;q=0.9",
"referer": "https://blog.csdn.net/",
"accept": "application/json, text/javascript, */*; q=0.01",
"X - Tingyun - Id": "im - pGljNfnc;r = 332305116",
"Sec - Fetch - Site": "same - origin",
"Sec - Fetch - Mode": "cors",
"Sec - Fetch - Dest": "empty",
"Accept - Encoding": "gzip, deflate, br",
"Accept - Language": "zh - CN, zh;q = 0.9",
"Host": "blog.csdn.net",
"Connection": "keep - alive",
"sec - ch - ua": '" Not A;Brand";v = "99", "Chromium";v = "90", "Google Chrome";v = "90"',
"Accept": "application / json, text / javascript, * / *; q = 0.01",
"X - Requested - With": "XMLHttpRequest",
"sec - ch - ua - mobile": "?0",
"Cookie": "uuid_tt_dd=10_30743904980-1618379395370-717724; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%7D; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_30743904980-1618379395370-717724; __gads=ID=e49a2afa774ef751-22e5578266c70052:T=1618379398:RT=1618379398:S=ALNI_MbGqjNddCmz_vAd5NE9aUuroCHdwA; ssxmod_itna=YqGxcCD=0QK7qYKGHEoQ40OxUxmufqLLdr80i44GNYWDZDiqAPGhDCbbtxw0mBmDI=fijYav4j4biaPIoKQmOXxbDCPGnDB9+fpDem=D5xGoDPxDeDADYo6DAqiOD7T=DEDm48DaxDoDehI7DY5DhxDC0GPDwx0CAg04eG9s7=7Cd/94VxxeAxG1=40HKYSm5t8EeGv3+x0kU40OuP58U6YDU7b4fQioWhhedndeklTYlelK/SD46nuKiD+xoehrTnq9DDpXbm6DD===; ssxmod_itna2=YqGxcCD=0QK7qYKGHEoQ40OxUxmufqLLdr80DA=nxAeD/FCbDFx48kIZp7KAphO1Cx25eGozrjvh8kC2L5tYKCxjy+INZxC0+h/0tZMc8qC2CO=5aZgAKKHnShO94Y8V=uoW+9KyHY/zkQG8xX4HqLlUDNjK0QxOW0x9EYc0wYQixG2Y0PDFqD2YiD==; dc_session_id=10_1620356271093.957181; TY_SESSION_ID=0fae6181-358c-443f-9ab9-19d622159650; dc_sid=dcd3c87e76fb26c5661211133000d30c; c_first_ref=default; c_first_page=https%3A//blog.csdn.net/; c_segment=12; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1618379397,1619322330,1620356273; c_ref=https%3A//blog.csdn.net/; firstDie=1; log_Id_view=51; c_pref=https%3A//blog.csdn.net/; c_page_id=default; dc_tos=qspx78; log_Id_pv=10; c-login-auto=9; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1620359253; announcement-new=%7B%22isLogin%22%3Afalse%2C%22announcementUrl%22%3A%22https%3A%2F%2Fblog.csdn.net%2Fblogdevteam%2Farticle%2Fdetails%2F112280974%3Futm_source%3Dgonggao_0107%22%2C%22announcementCount%22%3A0%7D",
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36"
}
list=["python","home","career","java","web","arch","blockchain","db","5g","game","mobile","ops","sec","engineering"]
for i in list:
response=requests.get("https://blog.csdn.net/api/articles?type=more&category=%s&shown_offset=0"%i,headers=header)
if response.json()["status"]=="true":
for i in response.json()["articles"]:
if select_is_insert(i["product_id"]) != 1:
insert_article(i["product_id"],i["url"],i["title"],i["nickname"],i["views"])

such , We get the data , And insert the data into the database .

6、 ... and 、 Query whether comments have been

We've got the data from the data , Need to query the data if we have commented on it before , So we need to make a judgment , Need to be in header Add your own cookie.


def comment_page(id,page=1,size=18):
""" Query whether comments have been """
header={
'Host': 'blog.csdn.net',
'Connection': 'keep-alive',
'Content-Length': '0',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'Accept': '*/*',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
'X-Tingyun-Id': 'im-pGljNfnc;r=301378265',
'Origin': 'https://blog.csdn.net',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
data="page=%s&size=%s&commentId="%(page,size)
response=requests.post("https://blog.csdn.net/phoenix/web/v1/comment/list/%s?page=%s&size=%s&commentId="%(id,page,size),headers=header,data=data)
if response.json()["code"]==200:
list=response.json()["data"]["list"]
if response.json()["data"]["count"]<< span="">=size:
for i in list:
if i["info"]["userName"]=="qq_39046854":# user id For my id, Need to change to your own
update_article(id)
return True
if response.json()["data"]["count"]>size:
for i in list:
if i["info"]["userName"] == "qq_39046854":
update_article(id)
return True
comment_page(id, 1, response.json()["data"]["count"])
return False

The whole logic :

Query comment list data , If the number of pieces is less than or equal to size, If the comment data , There is no one's own id, Then return to false, If you have your own id Then update the database , return true.

If the number of pieces is greater than size, If the comment data , There is no one's own id, Then recursion , If still not , return false, If you have your own id Then update the database , return true.

7、 ... and 、 Comment on

OK, I've finished the equipment , Then let's comment . Get the interface for comments .


def comment(articleId):
""" Comment on """
time.sleep(5)
user_headers = {
'Host': 'blog.csdn.net',
'Connection': 'keep-alive',
'Content-Length': '75',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
'X-Tingyun-Id': 'im-pGljNfnc;r=290154423',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://blog.csdn.net',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
content=["666"]
data="commentId=&content=%s&articleId=%s"%(random.choice(content),articleId)
response=requests.post("https://blog.csdn.net/phoenix/web/v1/comment/submit",
data=data.encode('utf-8'),
headers=user_headers)
print(response.json())
if response.json()["message"]=="success":
update_article(articleId)
if response.json()["code"]==400:
update_article(articleId)

You need to add your own cookie. Logic : Call the comment interface , If the return is successful , The database status is updated , If you return 400, If the article cannot be found, update and skip .

8、 ... and 、 Group comments

We've taken care of individual comments , Then we combine the functions , Query the database , Then comment .


def is_comment():
not_comment=select_is_comment()
if not_comment!=():
for i in not_comment:
if str(i[1][22:33]) in "qq_39046854":# Users who need to filter and don't comment write here
update_article(i[0])
else:
y=comment_page(i[0])
if y==False:
comment(i[0])

Logic : The query database did not comment on the data , If data is returned , Then enter the cycle , If it is a blacklist user article , Do not comment , Direct updating , If not, query whether to comment , If there is no comment, comment .

Nine 、 Set timing task

Various functions have been produced , But only once , Or write a loop , Why don't you write a scheduled task . Then let's combine timed tasks . Need to use schedule modular .


@repeat(every(10).minutes,func=recommend)# Query the recommended column
@repeat(every(3).minutes,func=is_comment)# Enter comments
@repeat(every().day.at("10:00"),func=qzzhrb)# Query hot list
@repeat(every().day.at("09:00"),func=lynrb)# Query hot list
@repeat(every().day.at("07:00"),func=xjzzb)# Query hot list
def run_threaded(func):
job_thread = threading.Thread(target=func)
job_thread.start()
def main():
while True:
try:
run_pending()#run_pending: Run all scheduled tasks that can be run
except:
pass
time.sleep(1)

Ten 、 Complete code

import random,time,os,threading
import requests
import pymysql
from dbutils.pooled_db import PooledDB
from schedule import every, repeat, run_pending
import json
POOL = PooledDB(
creator=pymysql, # Use the linked database module
maxconnections=20, # The maximum number of connections allowed by the connection pool ,0 and None Indicates that there is no limit to the number of connections
mincached=6, # On initialization , At least free links created in the link pool ,0 Means not to create
maxcached=None, # The most idle links in the link pool ,0 and None Don't limit
maxshared=5,
blocking=True, # If there is no connection available in the connection pool , Whether to block waiting .True, wait for ;False, Don't wait and report an error
maxusage=None,# The maximum number of times a link is reused ,None Means unlimited
setsession=[], # List of commands to execute before starting a session . Such as :["set datestyle to ...", "set time zone ..."]
ping=0, # ping MySQL Server side , Check if the service is available .
host='127.0.0.1',port=3306,user='root',password='root123456*',database='csdn_article',charset='utf8')
def insert_article(articleId, articleDetailUrl,articleTitle, nickName, hotRankScore):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("INSERT INTO `article`(`articleId`, `articleDetailUrl`,`articleTitle`, `nickName`, `hotRankScore`) VALUES (%s, '%s','%s', '%s', '%s');"%(articleId, articleDetailUrl,pymysql.escape_string(articleTitle), pymysql.escape_string(nickName), hotRankScore))# Use execute Method execution SQL sentence
data=db.commit()# Use fetchone() Method to get a piece of data
db.close()
return data
def select_is_insert(articleId):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("SELECT COUNT(*) FROM `article` WHERE `articleId` = %s;"%articleId)# Use execute Method execution SQL sentence
data = conn.fetchall()# Use fetchone() Method to get a piece of data
db.close()
return data[0][0]
def select_is_comment():# Query data without comments
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("SELECT `articleId`,`articleDetailUrl` FROM `article` WHERE `comment` = '0' LIMIT 0, 2;")# Use execute Method execution SQL sentence
data = conn.fetchall()# Use fetchone() Method to get a piece of data
db.close()
return data
def update_article(articleId,comment=1):
db = POOL.connection()
conn = db.cursor()# Use cursor() Method get operation cursor
conn.execute("UPDATE `article` SET `comment` =%s WHERE `articleId` = %s;"%(comment,articleId))# Use execute Method execution SQL sentence
data=db.commit()# Use fetchone() Method to get a piece of data
db.close()
return data
def comment(articleId):
""" Comment on """
time.sleep(5)
user_headers = {
'Host': 'blog.csdn.net',
'Connection': 'keep-alive',
'Content-Length': '75',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
'X-Tingyun-Id': 'im-pGljNfnc;r=290154423',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://blog.csdn.net',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
content=["666"]
data="commentId=&content=%s&articleId=%s"%(random.choice(content),articleId)
response=requests.post("https://blog.csdn.net/phoenix/web/v1/comment/submit",
data=data.encode('utf-8'),
headers=user_headers)
print(response.json())
if response.json()["message"]=="success":
update_article(articleId)
if response.json()["code"]==400:
update_article(articleId)
def qzzhrb():
""" Comprehensive hot list of the whole station """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
for y in range(0,4):
time.sleep(5)
response=requests.get("https://blog.csdn.net/phoenix/web/blog/hotRank?page="+str(y)+"&pageSize=25",headers=headers1)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
def lynrb():
""" Domain content list """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
list=["python","java","javascript"," Artificial intelligence ","php","c%2Fc%2B%2B"," big data "," Mobile development "," Data structure and algorithm "," game "," The Internet "," Operation and maintenance "," test "]
for y in range(0,2):
for i in list:
response=requests.get("https://blog.csdn.net/phoenix/web/blog/hotRank?page="+str(y)+"&pageSize=25&child_channel="+i,headers=headers1)
time.sleep(5)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
def xjzzb():
""" List of new authors """
headers1={
'Host': 'blog.csdn.net',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
}
for y in range(0,5):
time.sleep(5)
response=requests.get("https://blog.csdn.net/phoenix/web/blog/newUserRank?page="+str(y)+"&pageSize=20",headers=headers1)
if response.json()["message"]=="success":
for i in response.json()["data"]:
for j in range(1,len(i["articleDetailUrl"])):
if i["articleDetailUrl"][-j]=="/":
articleId=i["articleDetailUrl"][-j+1:]
if select_is_insert(articleId)!=1:
insert_article( articleId,i["articleDetailUrl"],i["articleTitle"],i["nickName"],i["hotRankScore"])
break
break
def recommend():
""" Recommendation column """
header={
"path": "/api/articles?type=more&category=home&shown_offset=0",
"accept-language": "zh-CN,zh;q=0.9",
"referer": "https://blog.csdn.net/",
"accept": "application/json, text/javascript, */*; q=0.01",
"X - Tingyun - Id": "im - pGljNfnc;r = 332305116",
"Sec - Fetch - Site": "same - origin",
"Sec - Fetch - Mode": "cors",
"Sec - Fetch - Dest": "empty",
"Accept - Encoding": "gzip, deflate, br",
"Accept - Language": "zh - CN, zh;q = 0.9",
"Host": "blog.csdn.net",
"Connection": "keep - alive",
"sec - ch - ua": '" Not A;Brand";v = "99", "Chromium";v = "90", "Google Chrome";v = "90"',
"Accept": "application / json, text / javascript, * / *; q = 0.01",
"X - Requested - With": "XMLHttpRequest",
"sec - ch - ua - mobile": "?0",
"Cookie": "uuid_tt_dd=10_30743904980-1618379395370-717724; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%7D; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_30743904980-1618379395370-717724; __gads=ID=e49a2afa774ef751-22e5578266c70052:T=1618379398:RT=1618379398:S=ALNI_MbGqjNddCmz_vAd5NE9aUuroCHdwA; ssxmod_itna=YqGxcCD=0QK7qYKGHEoQ40OxUxmufqLLdr80i44GNYWDZDiqAPGhDCbbtxw0mBmDI=fijYav4j4biaPIoKQmOXxbDCPGnDB9+fpDem=D5xGoDPxDeDADYo6DAqiOD7T=DEDm48DaxDoDehI7DY5DhxDC0GPDwx0CAg04eG9s7=7Cd/94VxxeAxG1=40HKYSm5t8EeGv3+x0kU40OuP58U6YDU7b4fQioWhhedndeklTYlelK/SD46nuKiD+xoehrTnq9DDpXbm6DD===; ssxmod_itna2=YqGxcCD=0QK7qYKGHEoQ40OxUxmufqLLdr80DA=nxAeD/FCbDFx48kIZp7KAphO1Cx25eGozrjvh8kC2L5tYKCxjy+INZxC0+h/0tZMc8qC2CO=5aZgAKKHnShO94Y8V=uoW+9KyHY/zkQG8xX4HqLlUDNjK0QxOW0x9EYc0wYQixG2Y0PDFqD2YiD==; dc_session_id=10_1620356271093.957181; TY_SESSION_ID=0fae6181-358c-443f-9ab9-19d622159650; dc_sid=dcd3c87e76fb26c5661211133000d30c; c_first_ref=default; c_first_page=https%3A//blog.csdn.net/; c_segment=12; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1618379397,1619322330,1620356273; c_ref=https%3A//blog.csdn.net/; firstDie=1; log_Id_view=51; c_pref=https%3A//blog.csdn.net/; c_page_id=default; dc_tos=qspx78; log_Id_pv=10; c-login-auto=9; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1620359253; announcement-new=%7B%22isLogin%22%3Afalse%2C%22announcementUrl%22%3A%22https%3A%2F%2Fblog.csdn.net%2Fblogdevteam%2Farticle%2Fdetails%2F112280974%3Futm_source%3Dgonggao_0107%22%2C%22announcementCount%22%3A0%7D",
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36"
}
list=["python","home","career","java","web","arch","blockchain","db","5g","game","mobile","ops","sec","engineering"]
for i in list:
response=requests.get("https://blog.csdn.net/api/articles?type=more&category=%s&shown_offset=0"%i,headers=header)
if response.json()["status"]=="true":
for i in response.json()["articles"]:
if select_is_insert(i["product_id"]) != 1:
insert_article(i["product_id"],i["url"],i["title"],i["nickname"],i["views"])
def comment_page(id,page=1,size=18):
""" Query whether comments have been """
header={
'Host': 'blog.csdn.net',
'Connection': 'keep-alive',
'Content-Length': '0',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'Accept': '*/*',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
'X-Tingyun-Id': 'im-pGljNfnc;r=301378265',
'Origin': 'https://blog.csdn.net',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': 'uuid_tt_dd=10_30743904990-1609307614140-892319; UN=qq_39046854; p_uid=U010000; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_30743904990-1609307614140-892319!5744*1*qq_39046854; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1614845242; __gads=ID=e3eda8954669b04c-22bf2c9088c700af:T=1619152098:RT=1619152098:S=ALNI_Mabu5XI7BhNuTCo5hOhZVC6RKaXJw; ssxmod_itna=Qqmx0Qi=D=0=nDeq0LP=4jo4RE7n7oiT+TrDlPpQxA5D8D6DQeGTT0dDB7Q1im7YHwTD578uhWx=m4ou=79C+oXPTDCPGnDBFh3TDee=D5xGoDPxDeDADYE6DAqiOD7qDdEsNv/8DbxYpnDA3Di4D+bkQDmqG0DDtHR4G2D7Un07Dqbu0jWWtohkDqwY+nD0t3xBLebaT5apaq0uiroPK48DDHtYyYQ0GCuxwCYBXTKqGyiKGuATUl9bRCOTXS/LvPthDLBhGCI7D6wAxqY7wC9gM5FYeqWhvQnGWnqReME0DDG8h=S2exD=; ssxmod_itna2=Qqmx0Qi=D=0=nDeq0LP=4jo4RE7n7oiT+D6aKp0DGqDsrdeeDLD=vR9bk=yn8Qk0IkUDnbmYyQjB9+FP6hOP2vebQd20Wa5U70=s5vbAxcwHwWzkr6nbVC3b0N2CdOIvRgQVByY2qdw874XwYWLDV+GM0AfmKDAyG+EPYQjxIRhk8jAx3kDV4MGkidjRfL0mD8Pvt8KGGYXOCPNGA=+sIP6K6P0CdRytv=4yl2FcBaH/bRc=4CFyBmK8=+OKppF4/=EvEcBhvu9iVcXmdRRsd/HW=sCLvk8yjfeDKdwiC3+Y=YhS4hrlZ+M0NVpGM7PDjKDeuD4D; UserName=qq_39046854; UserInfo=354c160126b1426e8ee609598d4e473f; UserToken=354c160126b1426e8ee609598d4e473f; UserNick=%E5%A4%A7%E5%AE%B6%E4%B8%80%E8%B5%B7%E5%AD%A6%E7%BC%96%E7%A8%8B%EF%BC%88python%EF%BC%89; AU=1D9; BT=1619320665305; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22qq_39046854%22%2C%22scope%22%3A1%7D%7D; c_first_ref=www.baidu.com; c_segment=15; dc_sid=3287252e7d613c9ce0fc0f7bff30cc8d; firstDie=1; c_first_page=https%3A//download.csdn.net/download/binzainet/11432043; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1620921821,1620924825,1621223521,1621223546; aliyun_webUmidToken=T2gA_B9FwF6d3YpegJJLr7sTunCxnLaUsnXsbtNlO-dk6-hgLZhENFiE0dyY2OFIiK8=; dc_session_id=10_1621301343026.272834; TY_SESSION_ID=5adae148-659f-4a3c-8354-3c27eafb9e82; announcement-new=%7B%22isLogin%22%3Atrue%2C%22announcementUrl%22%3A%22https%3A%2F%2Fblog.csdn.net%2Fblogdevteam%2Farticle%2Fdetails%2F112280974%3Futm_source%3Dgonggao_0107%22%2C%22announcementCount%22%3A0%2C%22announcementExpire%22%3A3600000%7D; log_Id_click=1149; c_ref=https%3A//blog.csdn.net/; log_Id_view=3430; c_pref=https%3A//blog.csdn.net/; c_utm_medium=distribute.pc_feed.none-task-blog-yuanlijihua_tag_v1-2.nonecase; c_page_id=default; dc_tos=qta45d; log_Id_pv=2040; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1621301378',
}
data="page=%s&size=%s&commentId="%(page,size)
response=requests.post("https://blog.csdn.net/phoenix/web/v1/comment/list/%s?page=%s&size=%s&commentId="%(id,page,size),headers=header,data=data)
if response.json()["code"]==200:
list=response.json()["data"]["list"]
if response.json()["data"]["count"]<size:
for i in list:
if i["info"]["userName"]=="qq_39046854":
update_article(id)
return True
if response.json()["data"]["count"]==size:
for i in list:
if i["info"]["userName"] == "qq_39046854":
update_article(id)
return True
if response.json()["data"]["count"]>size:
for i in list:
if i["info"]["userName"] == "qq_39046854":
update_article(id)
return True
comment_page(id, 1, response.json()["data"]["count"])
return False
# Every four minutes
def is_comment():
not_comment=select_is_comment()
if not_comment!=():
for i in not_comment:
if str(i[1][22:33]) in "qq_39046854weixin_43673589":
update_article(i[0])
else:
y=comment_page(i[0])
if y==False:
comment(i[0])
@repeat(every(10).minutes,func=recommend)
@repeat(every(3).minutes,func=is_comment)
@repeat(every().day.at("10:00"),func=qzzhrb)
@repeat(every().day.at("09:00"),func=lynrb)
@repeat(every().day.at("07:00"),func=xjzzb)
def run_threaded(func):
job_thread = threading.Thread(target=func)
job_thread.start()
def main():
while True:
try:
run_pending()#run_pending: Run all the tasks that can be run
except:
pass
time.sleep(1)
if __name__ == '__main__':
main()

This article is from WeChat official account. - Let's learn programming together (z2y1314-bc) , author : My code writes my heart

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the [email protected] Delete .

Original publication time : 2021-10-11

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Let's learn programming together]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/10/20211013175209930z.html

  1. L'application de Seed en python
  2. Python functional programming series 008: Testability
  3. [must see for getting started with Python] the difference and connection between cookie and session in Python!
  4. Python Xiaobai from scratch pyqt5 project actual combat (4) basic controls
  5. Python Xiaobai starts the pyqt5 project from scratch (3) connection between signal and slot
  6. Echarts ne peut pas afficher le HTML en PDF en utilisant le pdfkit de Python
  7. 一只Python 小white 的日常提问(づ ●─● )づ
  8. 2021 tutoriel complet d'automatisation des tests d'interface python [matériel d'apprentissage joint]
  9. Décrivez ce que les connaissances pertinentes jouent dans votre travail en utilisant arduino ou Python, y compris les bibliothèques pertinentes, en conjonction avec votre travail quotidien.
  10. Une question quotidienne d'un petit morceau de Python (づ● - ●)
  11. Python中字典问题请求解惑
  12. 一只Python 小white 的日常提問(づ ●─● )づ
  13. 在python中的问题,请问如何解决
  14. Only 10 questions are needed to easily master Matplotlib graphics processing | Python skill tree
  15. 在python中的問題,請問如何解决
  16. Comment résoudre le problème en python
  17. Demande de résolution de problèmes de dictionnaire en python
  18. 使用python,在一个命名为.txt文本文档写入n m乘法表。
  19. En utilisant Python, écrivez une table de multiplication n m dans un document texte nommé.txt.
  20. 使用python,在一個命名為.txt文本文檔寫入n m乘法錶。
  21. Python,前缀后缀相同时合并
  22. 关于#python#的问题:python
  23. 關於#python#的問題:python
  24. Python,前綴後綴相同時合並
  25. Questions sur # # Python #: Python
  26. Python, préfixe et suffixe combinés en même temps
  27. python manage.py shell无法运行,
  28. python manage.py shell無法運行,
  29. Le shell Python manage.py ne fonctionne pas,
  30. python中使用vscode Import 'matplotlib.pyplot' could not be resolved from source 问题
  31. [Chapter 11 of the full version] Python advanced crawler practice - system master Po anti climbing skills challenge high salary
  32. L'utilisation de vscode Import 'matplotlib.pyplot' en python ne peut pas être résolue à partir du problème source
  33. Python fusionne les deux listes et supprime les éléments dupliqués lors de la fusion
  34. [JS Reverse AES Reverse Encryption] python crawler combat, les jours sont de plus en plus décisifs
  35. 30 jeux Python. Je peux jouer à la pêche au travail pendant une journée.
  36. J'a i collecté un nouveau hit de liste en python, donc c'est un secret que quelqu'un d'autre peut devenir un magnat des médias!
  37. J'a i utilisé Python pour ramper à travers 5000 belles photos de papier peint, un jour oublié Premier amour!
  38. [Python planting system] the best green plant for your girlfriend. Girls love it when they see it! Attachment: should be able to feed - right??!
  39. [Python love guide] two small programs for sweetness burst table are released! Afraid you can't find someone?
  40. J'ai utilisé Python pour ramper 1000 lettres d'amour pour aider mon colocataire à exprimer les fleurs de classe, mais les inverser et les inverser... C'est le secret ultime des fleurs de classe!
  41. J'ai utilisé Python pour me connecter à la plus grande plate - forme de jeu au monde, et à quel point le cryptage steam est intelligent [code source inclus]
  42. python中列表转为矩阵后无法进行矩阵的乘法运算
  43. Python crawler Development and Learning full tutoriel 2nd Edition, banggan 100000 words [recommended Collection]
  44. Python crawler haut de gamme: microstore confus anti - décryptage
  45. La multiplication de la matrice ne peut pas être effectuée lorsque la liste est convertie en matrice en python
  46. Introduction to operators in python (Part 1)
  47. Are the dictionaries in Python ordered
  48. Introduction to dictionaries in Python
  49. List introduction in Python
  50. pandas比较两个dataframe特定数据列的数值是否相同并给出差值:使用np.where函数
  51. Python使用matplotlib绘制透明背景的可视化图像并保存透明背景的可视化结果(transparent background)
  52. Python self study notes -- basic grammar
  53. Python utilise matplotlib pour dessiner une image visuelle de l'arrière - plan transparent et enregistrer les résultats visuels de l'arrière - plan transparent
  54. Pandas compare les valeurs de deux colonnes de données spécifiques à dataframe et donne des valeurs de voyage: en utilisant la fonction np.where
  55. Comment configurer une application ASGI Django avec Postgres, nginx et uvicorn sur Ubuntu 20.04
  56. What are the advantages of Python and how to get started quickly
  57. Python self study notes -- basic data types
  58. Python code reading (Chapter 14): List Union
  59. Analyse statistique de la fonction de données des essais aléatoires Python
  60. Alien invasion project in Python application -- Aliens (Part 2)