first commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import psycopg2
|
||||
|
||||
# 数据库连接参数
|
||||
db_params = {
|
||||
'dbname': 'freshrss',
|
||||
'user': 'freshrss',
|
||||
'password': 'freshrss',
|
||||
'host': 'erhe.top',
|
||||
'port': '20788'
|
||||
}
|
||||
|
||||
# SQL 查询语句
|
||||
query = 'SELECT id, url FROM freshrss_toor_feed;'
|
||||
|
||||
try:
|
||||
# 建立数据库连接
|
||||
conn = psycopg2.connect(**db_params)
|
||||
|
||||
# 创建 cursor 对象
|
||||
cur = conn.cursor()
|
||||
|
||||
# 执行 SQL 查询
|
||||
cur.execute(query)
|
||||
|
||||
# 获取查询结果
|
||||
records = cur.fetchall()
|
||||
|
||||
# 遍历查询结果
|
||||
for record in records:
|
||||
id, url = record
|
||||
|
||||
# 替换 rsshub.app 为 rsshub.erhe.top
|
||||
if 'rsshub.app' in url:
|
||||
url = url.replace('rsshub.app', 'rsshub.erhe.top')
|
||||
|
||||
# 如果不包含 #force_feed,则在末尾加上
|
||||
if '#force_feed' not in url:
|
||||
url += '#force_feed'
|
||||
|
||||
# 更新 SQL 语句
|
||||
update_query = 'UPDATE freshrss_toor_feed SET url = %s WHERE id = %s;'
|
||||
|
||||
# 执行更新操作
|
||||
cur.execute(update_query, (url, id))
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
|
||||
print("Data updated successfully.")
|
||||
|
||||
except psycopg2.Error as e:
|
||||
print(f"Database error: {e}")
|
||||
conn.rollback()
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
# 关闭 cursor 和连接
|
||||
if 'cur' in locals():
|
||||
cur.close()
|
||||
if 'conn' in locals():
|
||||
conn.close()
|
||||
@@ -0,0 +1,70 @@
|
||||
'''
|
||||
获取 coin 现价, 并发邮件提醒
|
||||
(先做单个coin)
|
||||
'''
|
||||
import datetime
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
|
||||
|
||||
from base.base_load_config import load_config, get_base_path
|
||||
|
||||
config_json = load_config()
|
||||
base_project = get_base_path()
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
import time
|
||||
|
||||
|
||||
class CheckCoinCurrentPrice(object):
|
||||
def __init__(self):
|
||||
self.number_of_reminders = 5
|
||||
self.reminder_interval = 60 * 5
|
||||
self.target_price = 2.04
|
||||
|
||||
def main(self):
|
||||
coins_link = {
|
||||
'SUI': 'https://www.528btc.com/coin/33118.html'
|
||||
}
|
||||
url = coins_link['SUI']
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.webkit.launch(headless=False)
|
||||
context = browser.new_context(viewport={'width': 1920, 'height': 1080})
|
||||
page = context.new_page()
|
||||
|
||||
# 使用选择器获取元素的文本内容
|
||||
selector = '#detail_app_cid_5113 > div.money > div.sum > i > i.price_num.wordRise'
|
||||
|
||||
while True:
|
||||
try:
|
||||
page.goto(url)
|
||||
page.wait_for_load_state('load')
|
||||
time.sleep(3) # 确保页面完全加载
|
||||
|
||||
element = page.query_selector(selector)
|
||||
if element:
|
||||
price_text = element.inner_text()
|
||||
print(f'SUI price: {price_text}' + '\t' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
else:
|
||||
print("Element not found")
|
||||
context.close()
|
||||
browser.close()
|
||||
exit(0)
|
||||
|
||||
if float(price_text) > self.target_price:
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
exit(0)
|
||||
|
||||
# 关闭浏览器
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
C = CheckCoinCurrentPrice()
|
||||
C.main()
|
||||
@@ -0,0 +1,103 @@
|
||||
import asyncio
|
||||
from aioquic.asyncio import connect
|
||||
from aioquic.quic.configuration import QuicConfiguration
|
||||
from aioquic.quic.events import StreamDataReceived, ConnectionTerminated
|
||||
from aioquic.asyncio.protocol import QuicConnectionProtocol
|
||||
import ssl
|
||||
|
||||
# Trojan 配置
|
||||
config = {
|
||||
"server": "lbso.bnnodeservice.com", # 目标服务器地址
|
||||
"port": 443, # 目标服务器端口
|
||||
"sni": "cert.bitbyte.one", # SNI 伪装域名
|
||||
"password": "f2e8e50c-ffb8-48a1-a460-2e72dfaf7845", # 密码
|
||||
"local_address": "127.0.0.1", # 本地监听地址
|
||||
"local_port": 1080, # 本地监听端口
|
||||
}
|
||||
|
||||
# 创建 QUIC 配置
|
||||
quic_config = QuicConfiguration(is_client=True, alpn_protocols=["h3"], max_datagram_frame_size=65536)
|
||||
quic_config.verify_mode = ssl.CERT_NONE # 禁用证书验证
|
||||
quic_config.server_name = config["sni"] # 设置 SNI
|
||||
|
||||
|
||||
# 创建 QUIC 连接
|
||||
class TrojanClientProtocol(QuicConnectionProtocol):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.writer = None
|
||||
|
||||
def connection_established(self, quic):
|
||||
self.quic = quic
|
||||
|
||||
def quic_event_received(self, event):
|
||||
if isinstance(event, StreamDataReceived):
|
||||
if self.writer:
|
||||
self.writer.write(event.data)
|
||||
self.writer.drain()
|
||||
elif isinstance(event, ConnectionTerminated):
|
||||
if self.writer:
|
||||
self.writer.close()
|
||||
|
||||
|
||||
# 处理客户端请求
|
||||
async def handle_client(reader, writer):
|
||||
protocol = TrojanClientProtocol()
|
||||
protocol.writer = writer
|
||||
|
||||
# 创建到目标服务器的 QUIC 连接
|
||||
async with connect(
|
||||
config["server"],
|
||||
config["port"],
|
||||
configuration=quic_config,
|
||||
create_protocol=lambda: protocol,
|
||||
) as quic_connection:
|
||||
# 发送密码
|
||||
quic_connection.send_stream_data(0, config["password"].encode() + b"\r\n")
|
||||
|
||||
# 处理客户端请求
|
||||
async def client_to_server():
|
||||
try:
|
||||
while True:
|
||||
data = await reader.read(4096)
|
||||
if not data:
|
||||
break
|
||||
quic_connection.send_stream_data(0, data)
|
||||
except Exception as e:
|
||||
print(f"Client to server error: {e}")
|
||||
finally:
|
||||
quic_connection.close()
|
||||
|
||||
# 处理服务器响应
|
||||
async def server_to_client():
|
||||
try:
|
||||
while True:
|
||||
event = quic_connection.next_event()
|
||||
if isinstance(event, StreamDataReceived):
|
||||
writer.write(event.data)
|
||||
await writer.drain()
|
||||
elif isinstance(event, ConnectionTerminated):
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Server to client error: {e}")
|
||||
finally:
|
||||
writer.close()
|
||||
|
||||
# 启动两个任务
|
||||
await asyncio.gather(client_to_server(), server_to_client())
|
||||
|
||||
# 关闭连接
|
||||
writer.close()
|
||||
|
||||
|
||||
# 启动本地代理服务器
|
||||
async def start_proxy():
|
||||
server = await asyncio.start_server(handle_client, config["local_address"], config["local_port"])
|
||||
print(f"代理服务器已启动,监听地址:{config['local_address']}:{config['local_port']}")
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
|
||||
# 运行代理服务器
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(start_proxy())
|
||||
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
|
||||
my_dlt = [
|
||||
['01', '02', '03', '04', '05', '06', '07']
|
||||
]
|
||||
|
||||
|
||||
def generate_lotto():
|
||||
# 前区号码池
|
||||
front_area = list(range(1, 36))
|
||||
# 后区号码池
|
||||
back_area = list(range(1, 13))
|
||||
|
||||
# 随机选择前区5个号码
|
||||
selected_front = sorted(random.sample(front_area, 5))
|
||||
# 随机选择后区2个号码
|
||||
selected_back = sorted(random.sample(back_area, 2))
|
||||
|
||||
# 将选中的号码组合成一注
|
||||
lotto_ticket = [str(num).zfill(2) for num in selected_front + selected_back]
|
||||
|
||||
return lotto_ticket
|
||||
|
||||
|
||||
def check_match(ticket, my_dlt):
|
||||
for dlt in my_dlt:
|
||||
if ticket == dlt:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# 生成并检查匹配
|
||||
attempts = 0
|
||||
while True:
|
||||
attempts += 1
|
||||
generated_ticket = generate_lotto()
|
||||
if check_match(generated_ticket, my_dlt):
|
||||
print(f"在第 {attempts} 次尝试时,我们匹配了一注号码:{generated_ticket}")
|
||||
break
|
||||
if attempts % 100000 == 0:
|
||||
print(f"已经尝试了 {attempts} 次,还没有匹配。")
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import httpx
|
||||
|
||||
# 设置代理,包含协议部分
|
||||
proxies = {
|
||||
"http://": "http://127.0.0.1:7890",
|
||||
"https://": "http://127.0.0.1:7890",
|
||||
}
|
||||
|
||||
# 设置请求头
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107"
|
||||
}
|
||||
|
||||
# 创建 httpx 客户端,并设置代理和请求头
|
||||
client = httpx.Client(proxies=proxies, headers=headers)
|
||||
|
||||
# 目标 URL
|
||||
# url = "https://coinmarketcap.com/currencies/sui/" # sui
|
||||
url = "https://coinmarketcap.com/currencies/x/" # x
|
||||
|
||||
try:
|
||||
result = ''
|
||||
|
||||
resp = client.get(url)
|
||||
|
||||
page = resp.text
|
||||
|
||||
|
||||
|
||||
text = re.findall('<strong>(.*?)sc-65e7f566-0', page)[0] if re.findall(
|
||||
'<strong>(.*?)sc-65e7f566-0', page) else 'No Data'
|
||||
|
||||
text = re.sub(r'</strong>', '', text)
|
||||
text = re.sub(r'<!-- -->', '', text)
|
||||
text = re.sub(r'</p></div></div><div class="', '', text)
|
||||
|
||||
print(text.replace('我们会实时更新SUI兑换为CNY的价格。 ', ''))
|
||||
|
||||
prices = re.findall(r'\$(\d+\.\d+)', text)
|
||||
if prices:
|
||||
result += f'prices: ${prices[0]}\n'
|
||||
|
||||
volumes = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
||||
if volumes:
|
||||
result += f'24-hour trading volume: ${volumes[1]}\n'
|
||||
|
||||
change = re.findall(r'(up|down) (\d+\.\d+)%', text)
|
||||
if change:
|
||||
c = ' '.join(change[0])
|
||||
result += f'change: {c}%\n'
|
||||
|
||||
live_market_cap = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
||||
if live_market_cap:
|
||||
if len(live_market_cap) == 3:
|
||||
result += f'live market cap: ${live_market_cap[2]}\n'
|
||||
else:
|
||||
pass
|
||||
|
||||
max_circulating_supply = re.findall(r'(\d{1,3}(?:,\d{3})*)', text)
|
||||
if max_circulating_supply:
|
||||
result += f'max circulating supply: {max_circulating_supply[-1]}\n'
|
||||
|
||||
result += '\n'
|
||||
|
||||
print(result)
|
||||
except httpx.RequestError as e:
|
||||
# 打印错误信息
|
||||
print(f"请求错误: {e}")
|
||||
except Exception as e:
|
||||
# 打印其他错误信息
|
||||
print(f"发生错误: {e}")
|
||||
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
# 连接到MongoDB,这里假设MongoDB运行在默认端口上的本地机器
|
||||
client = MongoClient('mongodb://root:aaaAAA111!!!@erhe.top:38000/')
|
||||
|
||||
# 获取数据库列表
|
||||
db_list = client.list_database_names()
|
||||
|
||||
print("数据库列表:")
|
||||
for db_name in db_list:
|
||||
print(db_name)
|
||||
|
||||
# 获取指定数据库的集合列表
|
||||
# db = client[db_name]
|
||||
# collection_list = db.list_collection_names()
|
||||
#
|
||||
# print(f"\n数据库 '{db_name}' 的集合列表:")
|
||||
# for collection_name in collection_list:
|
||||
# print(collection_name)
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import psycopg2
|
||||
|
||||
# PostgreSQL数据库连接参数
|
||||
host = "192.168.100.122:20788"
|
||||
dbname = "postgres"
|
||||
user = "freshrss"
|
||||
password = "freshrss"
|
||||
|
||||
# 连接到PostgreSQL数据库
|
||||
conn = psycopg2.connect(host=host, dbname=dbname, user=user, password=password)
|
||||
conn.autocommit = True
|
||||
|
||||
# 创建一个cursor对象
|
||||
cur = conn.cursor()
|
||||
|
||||
# 获取所有数据库的名称
|
||||
cur.execute("SELECT datname FROM pg_database WHERE datistemplate = false;")
|
||||
databases = cur.fetchall()
|
||||
|
||||
print("数据库列表:")
|
||||
for db in databases:
|
||||
print(db[0])
|
||||
|
||||
# 连接到具体的数据库
|
||||
conn.close()
|
||||
conn = psycopg2.connect(dbname=db[0], user=user, password=password, host=host)
|
||||
cur = conn.cursor()
|
||||
|
||||
# 获取该数据库中的所有表
|
||||
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public';")
|
||||
tables = cur.fetchall()
|
||||
|
||||
print(f"\n数据库 '{db[0]}' 的表列表:")
|
||||
for table in tables:
|
||||
print(table[0])
|
||||
|
||||
# 关闭cursor和连接
|
||||
cur.close()
|
||||
conn.close()
|
||||
@@ -0,0 +1,34 @@
|
||||
from fastapi import FastAPI, HTTPException, Query
|
||||
import httpx
|
||||
import re
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"message": "FastAPI is running"}
|
||||
|
||||
|
||||
@app.get("/fetch-url/")
|
||||
async def fetch_url(url: str = Query(..., description="The URL to fetch")):
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
response = await client.get(url)
|
||||
response.raise_for_status() # Check if the request was successful
|
||||
content = response.text
|
||||
price = '$' + re.findall('mainPrice__tM6aY"><p title="\$(.*?)"', content)[0]
|
||||
percentage = re.findall('"name\\":\\"Percent Change 24H\\",\"value\\":(.*?)},', content)[0] + '%'
|
||||
res = f"{price} {percentage}"
|
||||
return res
|
||||
except httpx.RequestError as e:
|
||||
raise HTTPException(status_code=400, detail=f"An error occurred while requesting {url}: {str(e)}")
|
||||
except httpx.HTTPStatusError as e:
|
||||
raise HTTPException(status_code=e.response.status_code,
|
||||
detail=f"Error response {e.response.status_code} while requesting {url}: {str(e)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=34567)
|
||||
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import requests
|
||||
|
||||
orderId = "O24112815252166905421"
|
||||
pwd = "Z4cBtneT"
|
||||
host = "flow.hailiangip.com"
|
||||
port = "14223"
|
||||
user = orderId
|
||||
password = 'pwd=' + pwd + "&pid=-1" + "&cid=-1" + "&uid=" + "&sip=0" + "&nd=0"
|
||||
targetUrl = "http://api.hailiangip.com:8422/api/myIp"
|
||||
|
||||
|
||||
def httpProxyWithPassRequest(targetUrl):
|
||||
proxyUrl = "http://" + user + ":" + password + "@" + host + ":" + port
|
||||
print(proxyUrl)
|
||||
proxy = {"http": proxyUrl, "https": proxyUrl}
|
||||
r = requests.get(targetUrl, proxies=proxy)
|
||||
print("status Code : " + str(r.status_code))
|
||||
print("response : " + r.text)
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
httpProxyWithPassRequest(targetUrl)
|
||||
Reference in New Issue
Block a user