支持截图,文件存储改用minio
This commit is contained in:
@@ -10,10 +10,11 @@ import threading
|
||||
import sys
|
||||
import os
|
||||
from const import MIMETYPE, BUCKET, PIC_TYPE, BASE_PATH
|
||||
from uclouds3 import client
|
||||
from miniofile import client, put_object
|
||||
from urllib.parse import quote
|
||||
from exceptions import AuthException, OperationFailed
|
||||
from playwright.sync_api import sync_playwright
|
||||
from PIL import ImageGrab
|
||||
|
||||
|
||||
def get_dtsg_token(cookies):
|
||||
@@ -707,6 +708,14 @@ def sleep(a, b):
|
||||
return time.sleep(round(random.uniform(a, b), 1))
|
||||
|
||||
|
||||
def _full_screenshot():
|
||||
im = ImageGrab.grab()
|
||||
mem_file = io.BytesIO()
|
||||
# 保存到内存中
|
||||
im.save(mem_file, "png")
|
||||
return mem_file
|
||||
|
||||
|
||||
def update_windows_distinguish(x=1920, y=1080):
|
||||
"""更改windows分辨率"""
|
||||
if sys.platform == "win32":
|
||||
@@ -791,8 +800,12 @@ def playwright_like(cookies, post_id):
|
||||
page.click(button_xpath)
|
||||
time.sleep(10)
|
||||
|
||||
content = _full_screenshot()
|
||||
context.close()
|
||||
browser.close()
|
||||
key = f'{uuid.uuid4()}.png'
|
||||
put_object(key, content)
|
||||
return {'image_key': key}
|
||||
|
||||
|
||||
def playwright_post(cookies, message, image_key=None):
|
||||
@@ -818,7 +831,7 @@ def playwright_post(cookies, message, image_key=None):
|
||||
if image_key:
|
||||
filename = image_key.split('/')[-1]
|
||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||
client.download_file(BUCKET, image_key, file_path)
|
||||
client.fget_object(BUCKET, image_key, file_path)
|
||||
page.click('//span[text()="Photo/video"]')
|
||||
sleep(1, 2)
|
||||
with page.expect_file_chooser() as fc_info:
|
||||
@@ -838,9 +851,17 @@ def playwright_post(cookies, message, image_key=None):
|
||||
post_url = page.locator('//div[@data-pagelet="FeedUnit_0"]//a[@role="link"]').nth(2).get_attribute('href')
|
||||
if '&__cft__' in post_url:
|
||||
post_url = post_url.split('&__cft__')[0]
|
||||
page.goto(post_url)
|
||||
time.sleep(5)
|
||||
content = _full_screenshot()
|
||||
if image_key:
|
||||
os.remove(file_path)
|
||||
context.close()
|
||||
browser.close()
|
||||
return {'resp_id': post_url}
|
||||
|
||||
key = f'{uuid.uuid4()}.png'
|
||||
put_object(key, content)
|
||||
return {'resp_id': post_url, 'image_key': key}
|
||||
|
||||
|
||||
def playwright_comment(cookies, post_id, message, image_key=None):
|
||||
@@ -891,7 +912,7 @@ def playwright_comment(cookies, post_id, message, image_key=None):
|
||||
if image_key:
|
||||
filename = image_key.split('/')[-1]
|
||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||
client.download_file(BUCKET, image_key, file_path)
|
||||
client.fget_object(BUCKET, image_key, file_path)
|
||||
sleep(1, 2)
|
||||
with page.expect_file_chooser() as fc_info:
|
||||
page.click(attach_xpath)
|
||||
@@ -901,10 +922,17 @@ def playwright_comment(cookies, post_id, message, image_key=None):
|
||||
|
||||
page.type(input_xpath, message)
|
||||
page.click(comment_xpath)
|
||||
|
||||
time.sleep(5)
|
||||
content = _full_screenshot()
|
||||
if image_key:
|
||||
os.remove(file_path)
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
key = f'{uuid.uuid4()}.png'
|
||||
put_object(key, content)
|
||||
return {'image_key': key}
|
||||
|
||||
|
||||
def playwright_get_user_profile(cookies):
|
||||
path = os.path.join(BASE_PATH, 'chrome', '130-0008', 'chrome.exe')
|
||||
@@ -933,10 +961,14 @@ def playwright_get_user_profile(cookies):
|
||||
response = requests.get(
|
||||
url=profile_pic_url,
|
||||
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'},
|
||||
# proxies={
|
||||
# 'http': 'http://127.0.0.1:10889',
|
||||
# 'https': 'http://127.0.0.1:10889',
|
||||
# }
|
||||
)
|
||||
bio = io.BytesIO(response.content)
|
||||
key = f"facebook/{nickname.replace(' ', '_')}.png"
|
||||
client.putstream(BUCKET, key, bio)
|
||||
key = f"{nickname.replace(' ', '_')}.png"
|
||||
put_object(key, bio)
|
||||
return {'profile_pic': key, 'nickname': nickname}
|
||||
|
||||
|
||||
@@ -982,7 +1014,7 @@ def playwright_set_user_profile(cookies, firstname=None, lastname=None, image_ke
|
||||
page.click('//a[@aria-label="Profile picture"]')
|
||||
filename = image_key.split('/')[-1]
|
||||
file_path = os.path.join(BASE_PATH, 'files', filename)
|
||||
client.download_file(BUCKET, image_key, file_path)
|
||||
client.fget_object(BUCKET, image_key, file_path)
|
||||
sleep(1, 2)
|
||||
with page.expect_file_chooser() as fc_info:
|
||||
page.click('//div[text()="Upload new photo"]')
|
||||
@@ -990,6 +1022,7 @@ def playwright_set_user_profile(cookies, firstname=None, lastname=None, image_ke
|
||||
file_chooser.set_files(file_path)
|
||||
page.locator('//span[text()="Save"]').last.click()
|
||||
time.sleep(5)
|
||||
os.remove(file_path)
|
||||
|
||||
context.close()
|
||||
browser.close()
|
||||
@@ -1042,23 +1075,24 @@ if __name__ == '__main__':
|
||||
# playwright_test(cookies)
|
||||
# post(cookies, 'cs2025')
|
||||
# like(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5')
|
||||
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'facebook/xzpq.mp4')
|
||||
# comment(cookies, 'ZmVlZGJhY2s6MTIyMTA5NjE0NjU0NzkzNzc5', 'game la', 'xzpq.mp4')
|
||||
# playwright_like(cookies, 'https://www.facebook.com/watch/?v=1007800324567828')
|
||||
# print(playwright_post(cookies, '2025-3-230~like'))
|
||||
# playwright_post(cookies, '2025-3-26~like', 'face/rg.jpg')
|
||||
# playwright_post(cookies, '2025-3-26~like', 'rg.jpg')
|
||||
# playwright_comment(
|
||||
# cookies,
|
||||
# 'https://www.facebook.com/permalink.php?story_fbid=122096663738814448&id=61574433449058',
|
||||
# # 'https://www.facebook.com/watch/?v=1603348023628396',
|
||||
# # 'https://www.facebook.com/permalink.php?story_fbid=635052906055594&id=100086526695858',
|
||||
# 'https://www.facebook.com/reel/3578555425778137',
|
||||
# # 'https://www.facebook.com/reel/3578555425778137',
|
||||
# '2025-3-26~like',
|
||||
# # 'face/rg.jpg'
|
||||
# # 'rg.jpg'
|
||||
# )
|
||||
# print(playwright_get_user_profile(cookies))
|
||||
# playwright_set_user_profile(
|
||||
# cookies,
|
||||
# firstname='Lisa',
|
||||
# lastname='Keals',
|
||||
# image_key='facebook/rg.jpg'
|
||||
# image_key='rg.jpg'
|
||||
# )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user