空闲时间写的软件,目前正在开发中,算是写到一半了吧。发出来大家一起研究研究。
主要用途:小红书小号日常更新。
功能:自动生成图片、免接口通义生成笔记、小红书多账号管理、定时发布、审核后发布、按关键词搜索笔记后自动评论点赞收藏,自动同步小豆芽账号[可用于接任务]。
图片生成方式:自定义背景图或生成的信笺图片+自定义随机字体+随机排列=笔记图片
测试软件运行环境:win10 .net 4.7以上 Node.js 其它系统自行测试。
软件:小红书群控系统测试版 以下是展示图片:
图片生成器与小红书发送接口代码如下:
from flask import Flask, request, jsonify
import jieba
import json
import os
import execjs
import requests
import random
import time
from PIL import Image, ImageDraw, ImageFont, ImageStat
from datetime import datetime
import math
import string
import random
import base64
app = Flask(__name__)
headers = {
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"content-type": "application/json;charset=UTF-8",
"origin": "https://www.xiaohongshu.com",
"pragma": "no-cache",
"referer": "https://www.xiaohongshu.com/",
"sec-ch-ua": "\"Chromium\";v=\"112\", \"Google Chrome\";v=\"112\", \"Not:A-Brand\";v=\"99\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
}
PUNCTUATION = ",。!?:;、()“”‘’【】[]《》〈〉…—~·!@#$%^&*()_+-=<>?/\\\"'`"
# 常见符号列表用于信笺四角装饰
DECORATIVE_SYMBOLS = ["circle", "star", "heart", "zigzag", "zigzags","sun", "moon", "wave", "dashed", "lightning"]
def get_random_font(font_directory='ttf'):
"""
随机从指定目录中选择一个字体文件
"""
# 获取 ttf 目录下的所有文件
font_files = [f for f in os.listdir(font_directory) if f.endswith('.ttf')]
# 如果目录中没有字体文件,抛出错误
if not font_files:
raise FileNotFoundError("在指定的字体目录中没有找到任何字体文件")
# 随机选择一个字体文件
random_font = random.choice(font_files)
return os.path.join(font_directory, random_font)
def segment_text(text):
words = jieba.lcut(text)
lines = []
current_line = ""
# 定义随机让词语独占一行的概率
single_word_prob = 0.05
two_words_prob = 0.1
three_words_prob = 0.15
four_words_prob = 0.2
for word in words:
word_length = len(word)
if word_length == 1 and random.random() < single_word_prob:
if current_line:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
current_line = ""
lines.append(word)
elif word_length == 2 and random.random() < two_words_prob:
if current_line:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
current_line = ""
lines.append(word)
elif word_length == 3 and random.random() < three_words_prob:
if current_line:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
current_line = ""
lines.append(word)
elif word_length == 4 and random.random() < four_words_prob:
if current_line:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
current_line = ""
lines.append(word)
else:
if len(current_line) + word_length > 8:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
current_line = word
else:
current_line += word
if current_line:
cleaned_line = clean_punctuation(current_line)
if cleaned_line:
lines.append(cleaned_line)
return lines
def clean_punctuation(text):
while text and text[0] in PUNCTUATION:
text = text[1:]
while text and text[-1] in PUNCTUATION:
text = text[:-1]
if not text or all(char in PUNCTUATION for char in text):
return ""
return text
def calculate_text_size(draw, text, font):
bbox = draw.textbbox((0, 0), text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
return text_width, text_height
def calculate_average_color(image):
stat = ImageStat.Stat(image)
avg_color = stat.mean[:3]
return avg_color
def choose_text_color(background_color):
brightness = (background_color[0] * 299 + background_color[1] * 587 + background_color[2] * 114) / 1000
if brightness > 180:
return (0, 0, 0) # 黑色
else:
return (255, 255, 255) # 白色
def add_shadow(draw, position, text, font, text_color, shadow_color):
x, y = position
draw.text((x + 2, y + 2), text, font=font, fill=shadow_color)
def generate_random_background(image_width, image_height):
"""
随机生成信笺风格的背景
"""
# 增加更多随机浅色系背景颜色
background_colors = [
(255, 250, 240), (248, 244, 232), (240, 230, 210), (255, 245, 238), (250, 240, 230),
(255, 248, 220), (253, 245, 230), (245, 245, 220), (230, 230, 250),
# 额外的淡色背景颜色
(255, 255, 240), (250, 250, 210), (255, 239, 219), (255, 240, 245), (255, 240, 255),
(250, 240, 255), (245, 255, 250), (240, 255, 255), (240, 255, 240), (255, 255, 224),
(253, 245, 230), (245, 255, 250), (250, 250, 250), (255, 250, 250), (255, 255, 255),
(250, 240, 255),