功能:微博自动评论超话多线程加代理ip。评论后可导出评论链接
ps:此软件仅赚了500
不多说上代码
import tkinter as tk
from tkinter import filedialog
from tkinter import scrolledtext
import tkinter.messagebox as messagebox
import requests
import random
import threading
import re
running = False
# 导入CK功能
def import_ck():
filepath = filedialog.askopenfilename()
if not filepath:
return
with open(filepath, "r", encoding="utf-8") as file:
ck_list = file.readlines()
ck_listbox.delete(0, tk.END) # 先清空现有列表
for ck in ck_list:
ck_listbox.insert(tk.END, ck.strip())
update_total_label() # 更新总数标签
# 重置已完成标签为0
completed_label.config(text="已完成: 0")
# 导入超话功能
def import_super_topic():
filepath = filedialog.askopenfilename()
if not filepath:
return
with open(filepath, "r", encoding="utf-8") as file:
topics = file.readlines()
super_topic_listbox.delete(0, tk.END)
for topic in topics:
super_topic_listbox.insert(tk.END, topic.strip())
# 导入话术功能
def import_script():
filepath = filedialog.askopenfilename()
if not filepath:
return
with open(filepath, "r", encoding="utf-8") as file:
script = file.read()
script_text.delete("1.0", tk.END)
script_text.insert(tk.END, script)
def extract_super_topic_id(super_topic_url):
# 使用正则表达式从超话链接中提取ID,匹配数字和字母的组合
match = re.search(r'https://weibo\.com/p/([0-9a-zA-Z]+)', super_topic_url.strip())
if match:
return match.group(1) # 返回匹配的超话ID
else:
return None
# 获取代理的函数
# def get_proxy():
# 从文本框获取代理API URL
# proxy_api_url = api_entry.get()
# if not proxy_api_url:
# messagebox.showerror("错误", "代理API URL为空")
# return None
# try:
# # 尝试从您的代理API获取代理
# response = requests.get(proxy_api_url, timeout=10)
# if response.status_code == 200:
# proxy_ip_port = response.text.strip()
# print(f"成功获取代理IP地址:{proxy_ip_port}")
# # 验证代理的有效性
# if test_proxy(proxy_ip_port):
# return proxy_ip_port
# else:
# messagebox.showerror("错误", "获取的代理无法使用")
# return None
# else:
# print("无法从代理API获取代理IP地址")
# messagebox.showerror("错误", "无法从代理API获取代理IP地址")
# except Exception as e:
# print(f"获取代理IP地址时发生异常:{e}")
# messagebox.showerror("错误", f"请求代理API时出错:{e}")
# return None
# 验证代理是否有效的函数
# def test_proxy(proxy_ip_port):
# if not proxy_ip_port:
# print("无效的代理IP地址")
# return False
# try:
# proxies = {
# "http": f"http://{proxy_ip_port}",
# "https": f"http://{proxy_ip_port}",
# }
# # 尝试连接到微博来测试代理
# response = requests.get("https://www.weibo.com", proxies=proxies, timeout=10)
# if response.status_code == 200:
# print(f"代理 {proxy_ip_port} 可以正常连接到https://www.weibo.com")
# return True
# else:
# print(f"代理 {proxy_ip_port} 无法连接到https://www.weibo.com,状态码:{response.status_code}")
# return False
# except Exception as e:
# print(f"代理 {proxy_ip_port} 连接时发生异常:{e}")
# return False
def run_script():
global running
# proxy_api_url = api_entry.get() # 代理API的URL
# if not proxy_api_url:
# messagebox.showerror("错误", "代理API URL为空")
# return None
if not running:
running = True
run_btn.config(text="停止")
# 在新线程中执行耗时操作
threading.Thread(target=execute_script, daemon=True).start()
else:
running = False
run_btn.config(text="运行")
def execute_script():
global running
ck_data = ck_listbox.get(0, tk.END)
super_topic_data = super_topic_listbox.get(0, tk.END)
script_data = script_text.get("1.0", tk.END)
image_data = image_text.get("1.0", tk.END)
# 根据实际需要发送请求或执行其他操作
# 示例:发送请求到代理API
try:
completed_count = 0 # 计数已完成的任务数量
for ck in ck_data:
if not running: # 检查是否需要停止执行
break # 如果需要停止执行,则跳出循环
# 随机选择一个超话链接并提取ID
# 随机选择一个超话链接并提取ID
random_super_topic_url = random.choice(super_topic_data)
super_topic_id = extract_super_topic_id(random_super_topic_url)
if not super_topic_id:
print("无法提取超话ID")
continue
# proxy_ip_port = get_proxy() # 获取新的代理IP
# if not proxy_ip_port:
# running = False
# run_btn.config(text="运行")
# return
ck_parts = ck.split("----")
ck_cookie = f'SUB={ck_parts[1]}'
user_id = ck_parts[0]
headers = {
'authority': 'weibo.com',
'accept': 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cache-control': 'no-cache',
'client-version': 'v2.44.79',
'cookie': ck_cookie,
'pragma': 'no-cache',
'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'server-version': 'v2024.04.01.2',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
'x-requested-with': 'XMLHttpRequest',
}
# # 设置代理IP
# proxies = {
# "http": f"http://{proxy_ip_port}",
# "https": f"https://{proxy_ip_port}",
# }
# 发送第一个请求
# print(super_topic_id)
# print(ck_cookie)
response = requests.get(f'https://weibo.com/ajax/stopic/curl?oid=1022:{super_topic_id}&display_name=&is_obturate=0&is_live=0', headers=headers)
response_json = response.json()
if 'code' not in response_json or response_json.get('code') != 10000:
with open("失败.txt", "a", encoding="utf-8") as f:
f.write(ck + '\n')
continue
data = {
'id': super_topic_id,
'domain': super_topic_id[:6],
'module': 'share_topic',
'title': '%E5%8F%91%E5%B8%96',
'content': '',
'api_url': 'http://i.huati.weibo.com/pcpage/super/publisher',
'spr': '',
'extraurl': '',
'is_stock': '',
'check_url': f'http%3A%2F%2Fi.huati.weibo.com%2Fpcpage%2Foperation%2Fpublisher%2Fsuperauth%2Fpageid%3D{super_topic_id}%26uid%{user_id}',
'location': f'page_{super_topic_id[:6]}_super_index',
'text': random.choice(script_data.splitlines()),
'appkey': '',
'style_type': '1',
'pic_id': f'{random.choice(image_data.splitlines())}',
'tid': '',
'pdetail': super_topic_id,
'mid': '',
'isReEdit': 'false',
'gif_ids': '',
'sync_wb': '1',
'pub_source': 'page_2',
'api': f'http://i.huati.weibo.com/pcpage/operation/publisher/sendcontent?sign=super&page_id={super_topic_id}',
'longtext': '1',
'topic_id': f'1022%3A{super_topic_id}',
'updata_img_num': '1',
'pub_type': 'dialog',
'_t': '0'
}
headerss = {
'authority': 'weibo.com',
'accept': '*/*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cache-control': 'no-cache',
'content-type': 'application/x-www-form-urlencoded',
'cookie': ck_cookie,
'origin': 'https://weibo.com',
'pragma': 'no-cache',
'referer': f'https://weibo.com/p/{super_topic_id}/super_index',
'sec-ch-ua': '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0',
'x-requested-with': 'XMLHttpRequest',
}
# print(data)
# response = requests.post('https://weibo.com/p/aj/proxy?ajwvr=6&__rnd=', headers=headers, data=data, proxies=None)
post_response = requests.post('https://weibo.com/p/aj/proxy?ajwvr=6&__rnd=', headers=headerss, data=data)
post_result = post_response.json()
if post_result.get('code') == '100000':
post_id = post_result.get('data', {}).get('id')
weibo_link = f'https://weibo.com/{user_id}/{post_id}'
links_listbox.insert(tk.END, weibo_link) # 将链接添加到列表中
print(f"发帖成功,链接:{weibo_link}")
# 成功发帖后更新已完成标签
completed_count += 1
completed_label.config(text=f"已完成: {completed_count}/{len(ck_data)}")
else:
print("发帖失败:", post_response.text)
except Exception as e:
# 处理异常
print("Error:", e)
finally:
def update_ui():
global running
running = False
run_btn.config(text="运行")
# 在GUI主线程上安全地执行UI更新
app.after(0, update_ui)
# 导出链接功能
def export_links():
filepath = filedialog.asksaveasfilename(defaultextension=".txt")
if not filepath:
return
with open(filepath, "w", encoding="utf-8") as file:
for index in range(links_listbox.size()):
file.write(links_listbox.get(index) + "\n")
# 复制选定的文本
def copy_selected_text(listbox):
selected_item = listbox.get(tk.ACTIVE)
if selected_item:
listbox.clipboard_clear()
listbox.clipboard_append(selected_item)
# 清空列表
def clear_list(listbox, update_total=True):
listbox.delete(0, tk.END)
if update_total:
update_total_label()
# 更新总数标签
def update_total_label():
total_label.config(text=f"总数: {ck_listbox.size()}")
app = tk.Tk()
app.title('微博超话发送')
app.geometry('800x600')
top_frame = tk.Frame(app)
top_frame.pack(side=tk.TOP, fill=tk.X)
import_ck_btn = tk.Button(top_frame, text="导入CK", command=import_ck)
import_ck_btn.pack(side=tk.LEFT, padx=10, pady=10)
import_super_topic_btn = tk.Button(top_frame, text="导入超话", command=import_super_topic)
import_super_topic_btn.pack(side=tk.LEFT, padx=10, pady=10)
import_script_btn = tk.Button(top_frame, text="导入话术", command=import_script)
import_script_btn.pack(side=tk.LEFT, padx=10, pady=10)
run_btn = tk.Button(top_frame, text="运行", command=run_script)
run_btn.pack(side=tk.LEFT, padx=10, pady=10)
export_links_btn = tk.Button(top_frame, text="导出链接", command=export_links)
export_links_btn.pack(side=tk.LEFT, padx=10, pady=10)
total_label = tk.Label(top_frame, text="总数: 0")
total_label.pack(side=tk.LEFT, padx=10)
completed_label = tk.Label(top_frame, text="已完成: 0")
completed_label.pack(side=tk.LEFT, padx=10)
api_frame = tk.Frame(app)
api_frame.pack(side=tk.TOP, fill=tk.X, pady=10)
api_label = tk.Label(api_frame, text="代理API:")
api_label.pack(side=tk.LEFT, padx=5)
api_entry = tk.Entry(api_frame)
api_entry.pack(fill=tk.X, expand=True, side=tk.LEFT, padx=5)
content_frame = tk.Frame(app)
content_frame.pack(fill=tk.BOTH, expand=True)
labels = ["CK列表", "超话列表", "话术编辑", "图片编辑", "链接列表"]
widgets = []
for i, label_text in enumerate(labels):
label_frame = tk.Frame(content_frame)
label_frame.grid(row=0, column=i, sticky='ew', padx=5)
content_frame.grid_columnconfigure(i, weight=1)
label = tk.Label(label_frame, text=label_text)
label.pack()
frame = tk.Frame(content_frame)
frame.grid(row=1, column=i, sticky='nsew', padx=5, pady=5)
if i == 0 or i == 1 or i == 4: # Listboxes
widget = tk.Listbox(frame, height=10, width=50)
widget.bind("<Button-3>", lambda event, lb=widget: lb_menu_popup(event, lb)) # 绑定右键菜单
else: # ScrolledTexts
widget = scrolledtext.ScrolledText(frame, wrap=tk.WORD, height=10, width=50)
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL, command=widget.yview)
widget.config(yscrollcommand=scrollbar.set)
widget.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
widgets.append(widget)
ck_listbox, super_topic_listbox, script_text, image_text, links_listbox = widgets
content_frame.grid_rowconfigure(1, weight=1)
# 右键菜单弹出
def lb_menu_popup(event, listbox):
menu = tk.Menu(listbox, tearoff=0)
menu.add_command(label="复制", command=lambda: copy_selected_text(listbox))
menu.add_command(label="清空列表", command=lambda: clear_list(listbox))
menu.post(event.x_root, event.y_root)
app.mainloop()
本文来自投稿,不代表本站立场,如若转载,请注明出处:
3awtmn
还能用吗
@小七
才几天必须能