Spaces:
Sleeping
Sleeping
Penut Chen
commited on
Commit
•
5bd4136
1
Parent(s):
8c89f83
Add Bookmarks
Browse files
Intro.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Yuyu-Tei Price Crawler
|
2 |
+
|
3 |
+
[Yuyu-Tei Website](https://yuyu-tei.jp/game_ws/sell/sell_price.php)
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import datetime
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
@@ -9,23 +10,60 @@ from bs4.element import Tag
|
|
9 |
|
10 |
class App:
|
11 |
def __init__(self) -> None:
|
12 |
-
with
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
with gr.Row():
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
def Download(self, url):
|
30 |
try:
|
31 |
ts = datetime.datetime.utcnow() + datetime.timedelta(hours=8)
|
@@ -36,7 +74,7 @@ class App:
|
|
36 |
return None, f"Error: {e}"
|
37 |
|
38 |
def Launch(self):
|
39 |
-
self.demo.launch()
|
40 |
|
41 |
|
42 |
def CrawlPage(url, output_path):
|
@@ -95,5 +133,9 @@ def GetCardNameFromPage(url):
|
|
95 |
return card_name.text.strip()
|
96 |
|
97 |
|
|
|
|
|
|
|
|
|
98 |
if __name__ == "__main__":
|
99 |
App().Launch()
|
|
|
1 |
import datetime
|
2 |
+
import json
|
3 |
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
|
|
10 |
|
11 |
class App:
|
12 |
def __init__(self) -> None:
|
13 |
+
with open("bookmarks.json", "rt", encoding="UTF-8") as fp:
|
14 |
+
self.bookmark_info = json.load(fp)
|
15 |
+
|
16 |
+
with open("Intro.md", "rt", encoding="UTF-8") as fp:
|
17 |
+
intro = fp.read()
|
18 |
+
|
19 |
+
theme = gr.themes.Soft()
|
20 |
+
with gr.Blocks(title="Yuyu Tei Crawler", theme=theme) as self.demo:
|
21 |
+
gr.Markdown(intro)
|
22 |
+
with gr.Row(equal_height=False):
|
23 |
+
self.__CreateColumns__()
|
24 |
+
self.__RegisterEvents__()
|
25 |
+
|
26 |
+
def __CreateColumns__(self):
|
27 |
+
with gr.Column():
|
28 |
+
ph = "e.g. https://yuyu-tei.jp/game_ws/sell/sell_price.php?ver=uma&menu=newest"
|
29 |
+
self.input_url = gr.Textbox(label="URL", placeholder=ph)
|
30 |
+
self.submit_btn = gr.Button("Submit")
|
31 |
+
self.__CreateBookmarks__()
|
32 |
+
|
33 |
+
with gr.Column():
|
34 |
+
self.output_file = gr.File(label="Result", file_count="single")
|
35 |
+
self.status = gr.Textbox("Ready", label="Status", interactive=False)
|
36 |
+
|
37 |
+
def __CreateBookmarks__(self):
|
38 |
+
with gr.Tab("Bookmarks"):
|
39 |
with gr.Row():
|
40 |
+
self.bookmarks = {name: gr.Button(value=name) for name in self.bookmark_info}
|
41 |
+
|
42 |
+
def __RegisterEvents__(self):
|
43 |
+
args_submit = KwargsToDict(
|
44 |
+
fn=self.Download,
|
45 |
+
inputs=self.input_url,
|
46 |
+
outputs=[self.output_file, self.status],
|
47 |
+
)
|
48 |
+
|
49 |
+
self.submit_btn.click(**args_submit)
|
50 |
+
self.input_url.submit(**args_submit)
|
51 |
+
|
52 |
+
def GetArgsBookmark(name):
|
53 |
+
return KwargsToDict(
|
54 |
+
fn=self.ClickBookmark,
|
55 |
+
inputs=self.bookmarks[name],
|
56 |
+
outputs=self.input_url,
|
57 |
+
show_progress=False,
|
58 |
)
|
59 |
|
60 |
+
for name in self.bookmarks:
|
61 |
+
args_bookmark = GetArgsBookmark(name)
|
62 |
+
self.bookmarks[name].click(**args_bookmark)
|
63 |
+
|
64 |
+
def ClickBookmark(self, name):
|
65 |
+
return self.bookmark_info[name]
|
66 |
+
|
67 |
def Download(self, url):
|
68 |
try:
|
69 |
ts = datetime.datetime.utcnow() + datetime.timedelta(hours=8)
|
|
|
74 |
return None, f"Error: {e}"
|
75 |
|
76 |
def Launch(self):
|
77 |
+
self.demo.launch(favicon_path="icon.png")
|
78 |
|
79 |
|
80 |
def CrawlPage(url, output_path):
|
|
|
133 |
return card_name.text.strip()
|
134 |
|
135 |
|
136 |
+
def KwargsToDict(**kwargs):
|
137 |
+
return kwargs
|
138 |
+
|
139 |
+
|
140 |
if __name__ == "__main__":
|
141 |
App().Launch()
|
bookmarks.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"UMA": "https://yuyu-tei.jp/game_ws/sell/sell_price.php?ver=uma&menu=newest",
|
3 |
+
"LRC": "https://yuyu-tei.jp/game_ws/sell/sell_price.php?ver=lrc&menu=newest"
|
4 |
+
}
|
icon.png
ADDED