Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def extract_info_from_html(html_content):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Example: Extract order number and buyer name
|
| 9 |
-
order_number = soup.find('input', {'name': 'ordr_idxx'})['value'] if soup.find('input', {'name': 'ordr_idxx'}) else 'Not found'
|
| 10 |
-
buyer_name = soup.find('input', {'name': 'buyr_name'})['value'] if soup.find('input', {'name': 'buyr_name'}) else 'Not found'
|
| 11 |
|
| 12 |
return {
|
| 13 |
-
"order_number":
|
| 14 |
-
"buyer_name":
|
| 15 |
# Add more extracted fields as needed
|
| 16 |
}
|
| 17 |
|
|
@@ -36,8 +45,8 @@ def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, u
|
|
| 36 |
}
|
| 37 |
|
| 38 |
headers = {
|
| 39 |
-
'Accept': 'application/json',
|
| 40 |
-
'Content-Type': 'application/x-www-form-urlencoded',
|
| 41 |
}
|
| 42 |
|
| 43 |
try:
|
|
@@ -62,7 +71,50 @@ def request_batch_key(onfftid, pay_type, method, cert_type, order_no, user_nm, u
|
|
| 62 |
"raw_response": getattr(e.response, 'text', None)
|
| 63 |
}
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
gr.Markdown("# API ์ฐ๋ ํ
์คํธ")
|
|
@@ -93,6 +145,28 @@ with gr.Blocks() as demo:
|
|
| 93 |
outputs=batch_key_output
|
| 94 |
)
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
demo.launch()
|
|
|
|
| 1 |
+
from bs4 import BeautifulSoup
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
+
from html.parser import HTMLParser
|
| 5 |
+
|
| 6 |
+
class MyHTMLParser(HTMLParser):
|
| 7 |
+
def __init__(self):
|
| 8 |
+
super().__init__()
|
| 9 |
+
self.data = {}
|
| 10 |
+
|
| 11 |
+
def handle_starttag(self, tag, attrs):
|
| 12 |
+
if tag == 'input':
|
| 13 |
+
d = dict(attrs)
|
| 14 |
+
if 'name' in d and 'value' in d:
|
| 15 |
+
self.data[d['name']] = d['value']
|
| 16 |
|
| 17 |
def extract_info_from_html(html_content):
|
| 18 |
+
parser = MyHTMLParser()
|
| 19 |
+
parser.feed(html_content)
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
return {
|
| 22 |
+
"order_number": parser.data.get('ordr_idxx', 'Not found'),
|
| 23 |
+
"buyer_name": parser.data.get('buyr_name', 'Not found'),
|
| 24 |
# Add more extracted fields as needed
|
| 25 |
}
|
| 26 |
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
headers = {
|
| 48 |
+
'Accept': 'application/json',
|
| 49 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
| 50 |
}
|
| 51 |
|
| 52 |
try:
|
|
|
|
| 71 |
"raw_response": getattr(e.response, 'text', None)
|
| 72 |
}
|
| 73 |
|
| 74 |
+
def request_payment(onfftid, fix_key, tot_amt, card_user_type, auth_value, install_period, user_nm,
|
| 75 |
+
user_phone2, product_nm, pay_type, method, order_no):
|
| 76 |
+
url = "https://store.onoffkorea.co.kr/fix/index.php"
|
| 77 |
+
payload = {
|
| 78 |
+
"onfftid": onfftid,
|
| 79 |
+
"fix_key": fix_key,
|
| 80 |
+
"tot_amt": tot_amt,
|
| 81 |
+
"card_user_type": card_user_type,
|
| 82 |
+
"auth_value": auth_value,
|
| 83 |
+
"install_period": install_period,
|
| 84 |
+
"user_nm": user_nm,
|
| 85 |
+
"user_phone2": user_phone2,
|
| 86 |
+
"product_nm": product_nm,
|
| 87 |
+
"pay_type": pay_type,
|
| 88 |
+
"method": method,
|
| 89 |
+
"order_no": order_no
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
headers = {
|
| 93 |
+
'Accept': 'application/json',
|
| 94 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
response = requests.post(url, data=payload, headers=headers)
|
| 99 |
+
response.raise_for_status()
|
| 100 |
+
|
| 101 |
+
# Check if the response is JSON
|
| 102 |
+
try:
|
| 103 |
+
return response.json()
|
| 104 |
+
except requests.exceptions.JSONDecodeError:
|
| 105 |
+
# If not JSON, assume it's HTML and extract information
|
| 106 |
+
extracted_info = extract_info_from_html(response.text)
|
| 107 |
+
return {
|
| 108 |
+
"status": "HTML response received",
|
| 109 |
+
"extracted_info": extracted_info,
|
| 110 |
+
"raw_html": response.text[:1000] # First 1000 characters of HTML for reference
|
| 111 |
+
}
|
| 112 |
+
except requests.exceptions.RequestException as e:
|
| 113 |
+
return {
|
| 114 |
+
"error": str(e),
|
| 115 |
+
"status_code": getattr(e.response, 'status_code', None),
|
| 116 |
+
"raw_response": getattr(e.response, 'text', None)
|
| 117 |
+
}
|
| 118 |
|
| 119 |
with gr.Blocks() as demo:
|
| 120 |
gr.Markdown("# API ์ฐ๋ ํ
์คํธ")
|
|
|
|
| 145 |
outputs=batch_key_output
|
| 146 |
)
|
| 147 |
|
| 148 |
+
with gr.Tab("์นด๋ ๋ฐฐ์นํค ๊ฒฐ์ ์น์ธ ์์ฒญ"):
|
| 149 |
+
onfftid_pay = gr.Textbox(label="์จ์คํ์ฝ๋ฆฌ์ TID")
|
| 150 |
+
fix_key = gr.Textbox(label="์นด๋ ๋ฐฐ์น ํค")
|
| 151 |
+
tot_amt_pay = gr.Number(label="๊ฒฐ์ ๊ธ์ก")
|
| 152 |
+
card_user_type_pay = gr.Radio(["0", "1"], label="์นด๋ ํ์
", value="0")
|
| 153 |
+
auth_value_pay = gr.Textbox(label="์ฃผ๋ฏผ(์ฌ์
์)๋ฑ๋ก๋ฒํธ")
|
| 154 |
+
install_period = gr.Dropdown(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"], label="ํ ๋ถ๊ธฐ๊ฐ")
|
| 155 |
+
user_nm_pay = gr.Textbox(label="๊ณ ๊ฐ๋ช
")
|
| 156 |
+
user_phone2_pay = gr.Textbox(label="๊ณ ๊ฐ์ฐ๋ฝ์ฒ")
|
| 157 |
+
product_nm_pay = gr.Textbox(label="์ํ๋ช
")
|
| 158 |
+
pay_type_pay = gr.Textbox(label="๊ฒฐ์ ํ์
", value="fixKey")
|
| 159 |
+
method_pay = gr.Textbox(label="๋ฉ์๋", value="authTran")
|
| 160 |
+
order_no_pay = gr.Textbox(label="์ฃผ๋ฌธ๋ฒํธ")
|
| 161 |
+
|
| 162 |
+
payment_button = gr.Button("๊ฒฐ์ ์น์ธ ์์ฒญ")
|
| 163 |
+
payment_output = gr.JSON(label="์๋ต ๊ฒฐ๊ณผ")
|
| 164 |
+
|
| 165 |
+
payment_button.click(
|
| 166 |
+
request_payment,
|
| 167 |
+
inputs=[onfftid_pay, fix_key, tot_amt_pay, card_user_type_pay, auth_value_pay, install_period,
|
| 168 |
+
user_nm_pay, user_phone2_pay, product_nm_pay, pay_type_pay, method_pay, order_no_pay],
|
| 169 |
+
outputs=payment_output
|
| 170 |
+
)
|
| 171 |
|
| 172 |
demo.launch()
|