Skip to content

Commit

Permalink
feat: 自动驱动下载
Browse files Browse the repository at this point in the history
  • Loading branch information
mikumifa committed Jun 5, 2024
1 parent e934600 commit 799fd1c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 7 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from loguru import logger

import gradio as gr
from loguru import logger

from tab.go import go_tab
from tab.login import login_tab
from tab.settings import setting_tab
from tab.train import train_tab


header = """
# B 站会员购抢票🌈
️此项目仅用于个人参考学习,切勿进行盈利,所造成的后果与本人无关。
️此项目完全开源免费 ([项目地址](https://github.com/mikumifa/biliTickerBuy)),切勿进行盈利,所造成的后果与本人无关。
"""

short_js = """
Expand All @@ -28,7 +27,6 @@

if __name__ == "__main__":
logger.add("app.log")

with gr.Blocks(head=short_js, css=custom_css) as demo:
gr.Markdown(header)
with gr.Tab("配置"):
Expand All @@ -37,6 +35,8 @@
go_tab()
with gr.Tab("训练你的验证码速度"):
train_tab()
with gr.Tab("登录管理"):
login_tab()

# 运行应用
print("点击下面的网址运行程序 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓")
Expand Down
11 changes: 11 additions & 0 deletions tab/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ def start_go(tickets_info_str, time_start, interval, mode, total_attempts):


def go_tab():
gr.Markdown("""
> **分享一下经验**
> - 抢票前,不要去提前抢还没有发售的票,会被b站封掉一段时间导致错过抢票的
> - 热门票要提前练习过验证码
> - 如果要使用自动定时抢,电脑的时间和b站的时间要一致
> - 使用不同的多个账号抢票 (可以每一个exe文件都使用不同的账号, 或者在使用这个程序的时候,手机使用其他的账号去抢)
> - 程序能保证用最快的速度发送订单请求,但是不保证这一次订单请求能够成功。所以不要完全依靠程序
> - 现在各个平台抢票和秒杀机制都是进抽签池抽签,网速快发请求多快在拥挤的时候基本上没有效果
> 此时就要看你有没有足够的设备和账号来提高中签率
> - 欢迎前往[discussions](https://github.com/mikumifa/biliTickerBuy/discussions) 分享你的经验
""")
with gr.Column():
ticket_ui = gr.TextArea(
label="填入配置", info="再次填入配置信息", interactive=True
Expand Down
93 changes: 93 additions & 0 deletions tab/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json

import gradio as gr
from loguru import logger

from config import cookies_config_path
from util.bili_request import BiliRequest

names = []


@logger.catch
def login_tab():
gr.Markdown("""
> **补充**
>
> 在这里,你可以
> 1. 去更改账号,
> 2. 查看当前程序正在使用哪个账号
> 3. 使用配置文件切换到另一个账号
>
""")
main_request = BiliRequest(cookies_config_path=cookies_config_path)
username_ui = gr.Text(
main_request.get_request_name(),
label="账号名称",
interactive=False,
info="当前账号的名称",
)
gr.Markdown("""🏵️ 登录""")
info_ui = gr.TextArea(
info="此窗口为输出信息", label="输出信息", interactive=False
)
add_btn = gr.Button("重新登录")
with gr.Column() as out_col:
out_btn = gr.Button("导出")
login_config = gr.Text(
label="导出登录信息,复制后粘贴到其他地方即可",
visible=False,
interactive=False,
show_copy_button=True
)

def out():
return gr.update(value=json.dumps(main_request.cookieManager.config), visible=True)

out_btn.click(
fn=out,
inputs=None,
outputs=login_config
)
with gr.Column() as in_col:
in_btn = gr.Button("导入")
in_text_ui = gr.Text(
label="先将登录信息粘贴到此处,然后点击导入",
interactive=True,
)

def in_fn(text):
temp = main_request.cookieManager.config
try:
main_request.cookieManager.config = json.loads(text)
main_request.cookieManager.dump_config()
name = main_request.get_request_name()
return [f"退出重启一下来保证完全更改", gr.update(name)]
except Exception:
main_request.cookieManager.config = temp
main_request.cookieManager.dump_config()
return ["配置文件错误,未修改", gr.update()]

in_btn.click(
fn=in_fn,
inputs=in_text_ui,
outputs=[info_ui, username_ui]
)

def add():
temp = main_request.cookieManager.config
yield ["将打开浏览器,请在浏览器里面重新登录", gr.update()]
try:
main_request.cookieManager.get_cookies_str_force()
name = main_request.get_request_name()
yield [f"退出重启一下来保证完全更改", gr.update(name)]
except Exception:
main_request.cookieManager.config = temp
main_request.cookieManager.dump_config()
yield ["配置文件错误,未修改", gr.update()]

add_btn.click(
fn=add,
inputs=None,
outputs=[info_ui, username_ui]
)
4 changes: 2 additions & 2 deletions tab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def on_submit_all(ticket_id, ticket_info, people_indices, people_buyer_index, ad

def setting_tab():
gr.Markdown("""
> **补充**
> **必看**
>
> 保证自己在抢票前,已经配置了地址和购买人信息(就算不需要也要提前填写)
> 保证自己在抢票前,已经配置了地址和购买人信息(就算不需要也要提前填写) 如果没填,生成表单时候不会出现任何选项
>
> - 地址 : 会员购中心->地址管理
> - 购买人信息:会员购中心->购买人信息
Expand Down
8 changes: 8 additions & 0 deletions tab/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@


def train_tab():
gr.Markdown("""
> **补充**
>
> 在这里,你可以
> 1. 提前知道抢票时候验证码的过程
> 2. 训练验证码,提高验证码速度
>
""")
_request = BiliRequest(cookies_config_path=cookies_config_path)

gr.Markdown("💪 在这里训练一下手过验证码的速度,提前演练一下")
Expand Down
9 changes: 9 additions & 0 deletions util/bili_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, headers=None, cookies=None, cookies_config_path=""):
}

def get(self, url, data=None):
self.headers["cookies"] = self.cookieManager.get_cookies_str()
response = self.session.get(url, data=data, headers=self.headers)
response.raise_for_status()
if response.json().get("msg", "") == "请先登录":
Expand All @@ -33,13 +34,21 @@ def get(self, url, data=None):
return response

def post(self, url, data=None):
self.headers["cookies"] = self.cookieManager.get_cookies_str()
response = self.session.post(url, data=data, headers=self.headers)
response.raise_for_status()
if response.json().get("msg", "") == "请先登录":
self.headers["cookies"] = self.cookieManager.get_cookies_str_force()
self.post(url, data)
return response

def get_request_name(self):
try:
result = self.get("https://api.bilibili.com/x/web-interface/nav").json()
return result["data"]["uname"]
except Exception:
return "未登录"


if __name__ == "__main__":
payload = {}
Expand Down
5 changes: 5 additions & 0 deletions util/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def dump_config(self):
with open(self.config_file_path, "w") as f:
json.dump(self.config, f, indent=4)

def clear_config(self):
self.config = {}
with open(self.config_file_path, "w") as f:
json.dump(self.config, f, indent=4)

def get_cookies(self):
try:
with open(self.config_file_path, "r") as f:
Expand Down

0 comments on commit 799fd1c

Please sign in to comment.