upload
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""鼠标停在已打开的谷歌浏览器上时才向下滚,移开就停。Ctrl+C 停止。
|
||||
|
||||
用法:
|
||||
python chrome_自动下滑.py
|
||||
不移动鼠标,不抢焦点。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import subprocess
|
||||
import time
|
||||
from ctypes import wintypes
|
||||
|
||||
# ==================== 运行参数(改这里) ====================
|
||||
SCROLL_INTERVAL = 0.08 # 每轮间隔,秒
|
||||
WHEEL_NOTCHES = 4 # 每轮滚几格,正数向下
|
||||
# 只滚标题包含这段文字的窗口;留空 = 全部 Chrome
|
||||
TITLE_KEYWORD = ''
|
||||
# ============================================================
|
||||
|
||||
subprocess.run('chcp 65001', shell=True, capture_output=True)
|
||||
|
||||
user32 = ctypes.windll.user32
|
||||
kernel32 = ctypes.windll.kernel32
|
||||
|
||||
WHEEL_DELTA = 120
|
||||
MOUSEEVENTF_WHEEL = 0x0800
|
||||
GA_ROOT = 2
|
||||
|
||||
class MOUSEINPUT(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('dx', wintypes.LONG),
|
||||
('dy', wintypes.LONG),
|
||||
('mouseData', wintypes.DWORD),
|
||||
('dwFlags', wintypes.DWORD),
|
||||
('time', wintypes.DWORD),
|
||||
('dwExtraInfo', ctypes.POINTER(ctypes.c_ulong)),
|
||||
]
|
||||
|
||||
|
||||
class INPUT(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('type', wintypes.DWORD),
|
||||
('mi', MOUSEINPUT),
|
||||
]
|
||||
|
||||
|
||||
def _window_text(hwnd):
|
||||
length = user32.GetWindowTextLengthW(hwnd)
|
||||
buf = ctypes.create_unicode_buffer(length + 1)
|
||||
user32.GetWindowTextW(hwnd, buf, length + 1)
|
||||
return buf.value
|
||||
|
||||
|
||||
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
||||
|
||||
|
||||
def _exe_path(hwnd):
|
||||
pid = wintypes.DWORD()
|
||||
user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
|
||||
handle = kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, pid.value)
|
||||
if not handle:
|
||||
return ''
|
||||
try:
|
||||
size = wintypes.DWORD(32768)
|
||||
buf = ctypes.create_unicode_buffer(size.value)
|
||||
if not kernel32.QueryFullProcessImageNameW(handle, 0, buf, ctypes.byref(size)):
|
||||
return ''
|
||||
return buf.value
|
||||
finally:
|
||||
kernel32.CloseHandle(handle)
|
||||
|
||||
|
||||
def chrome_under_cursor():
|
||||
"""鼠标当前所在的窗口是 chrome.exe 时返回根窗口,否则 None。"""
|
||||
pt = wintypes.POINT()
|
||||
if not user32.GetCursorPos(ctypes.byref(pt)):
|
||||
return None
|
||||
hwnd = user32.WindowFromPoint(pt)
|
||||
if not hwnd:
|
||||
return None
|
||||
root = user32.GetAncestor(hwnd, GA_ROOT)
|
||||
exe = _exe_path(root).lower()
|
||||
if not exe.endswith('\\chrome.exe'):
|
||||
return None
|
||||
if TITLE_KEYWORD and TITLE_KEYWORD not in _window_text(root):
|
||||
return None
|
||||
return root
|
||||
|
||||
|
||||
def _send_wheel(notches):
|
||||
# 只发滚轮,不移动光标
|
||||
delta = (-WHEEL_DELTA * notches) & 0xFFFFFFFF
|
||||
wheel = INPUT()
|
||||
wheel.type = 0
|
||||
wheel.mi.mouseData = delta
|
||||
wheel.mi.dwFlags = MOUSEEVENTF_WHEEL
|
||||
user32.SendInput(1, ctypes.byref(wheel), ctypes.sizeof(INPUT))
|
||||
|
||||
|
||||
def main():
|
||||
print('鼠标放在谷歌浏览器上才下滑,移开即停。Ctrl+C 结束。', flush=True)
|
||||
scrolling = False
|
||||
try:
|
||||
while True:
|
||||
hwnd = chrome_under_cursor()
|
||||
if hwnd:
|
||||
if not scrolling:
|
||||
print(f'开始下滑: {_window_text(hwnd)}', flush=True)
|
||||
scrolling = True
|
||||
_send_wheel(WHEEL_NOTCHES)
|
||||
elif scrolling:
|
||||
print('鼠标已离开浏览器,暂停', flush=True)
|
||||
scrolling = False
|
||||
time.sleep(SCROLL_INTERVAL)
|
||||
except KeyboardInterrupt:
|
||||
print('已停止', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
import re
|
||||
import pymysql
|
||||
|
||||
class All_Setting():
|
||||
def __init__(self,host,port,db):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
|
||||
def remove_symbols(self,text):
|
||||
pattern = re.compile(r'[^\w\s]')
|
||||
return pattern.sub('', text)
|
||||
|
||||
def get_chinese(self,text,printTxt=False):
|
||||
# text = "海王星辰(广州智慧城店)"
|
||||
pattern = r'[^\w\s]'
|
||||
result = re.sub(pattern, '', text)
|
||||
if printTxt:
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def get_shoppingmalls(self,sql):
|
||||
res_list = []
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
if conn:
|
||||
print('ok')
|
||||
cursor = conn.cursor()
|
||||
res = cursor.execute(sql)
|
||||
c2 = cursor.fetchall()
|
||||
return c2
|
||||
|
||||
def write_data(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.executemany(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def update_data(self,sql):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def write_data_one(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
import json
|
||||
import time,requests
|
||||
|
||||
|
||||
def get_sign_meituan(url, dfpid, data):
|
||||
url_mtg = "http://118.89.119.254:18003/mt_jym_1_2"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
"ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response1 = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
print(response1.text)
|
||||
mtgsig1 = response1.json()
|
||||
return str(mtgsig1)
|
||||
|
||||
def get_sign_waimai(url, dfpid, data):
|
||||
print('我是外卖mtg')
|
||||
|
||||
url_mtg = "http://118.89.119.254:18003/get_mt_tg_0507_jym"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
# "ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
mtgsig = response.json()
|
||||
print(mtgsig)
|
||||
return str(mtgsig)
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
|
||||
# 名称医乐邦
|
||||
# 请输入坐标34.268453,117.165798
|
||||
Reference in New Issue
Block a user