Omnibus's picture
Update app.py
43173f5 verified
raw
history blame
952 Bytes
import gradio as gr
import requests
import xmltodict
import bs4
import lxml
import json
def find_rss(rss_url):
json_box=[]
json_dict={}
r = requests.get(f'{rss_url}')
soup = bs4.BeautifulSoup(source.content,'lxml')
for i,p in enumerate(soup.find_all("a")):
json_dict[i]=p
json_box.append(json_dict)
return json_box
def get_rss(rss_url):
r = requests.get(f'{rss_url}')
if ".json" in rss_url:
lod = json.loads(r.text)
if ".xml" in rss_url:
#with open() as xml_file:
lod = xmltodict.parse(r.text)
return lod
with gr.Blocks() as app:
with gr.Row():
rss_search = gr.Textbox(label="search rss (xml,json)")
search_btn=gr.Button("find rss")
with gr.Row():
rss = gr.Textbox(label="rss")
btn = gr.Button("load rss")
out_json = gr.JSON()
search_btn.click(find_rss,rss_search,out_json)
btn.click(get_rss,rss,out_json)
app.launch()