File size: 1,184 Bytes
01b7d84
 
3f1df0d
26fd880
b166bee
01b7d84
 
9e02324
 
 
 
d33ca30
9e02324
5853efe
 
 
d1bf724
5853efe
 
9e02324
 
01b7d84
79272ae
 
 
 
 
6cfa95b
5ebc5a8
 
01b7d84
617c1aa
01b7d84
 
9e02324
 
 
 
 
01b7d84
43173f5
 
01b7d84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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(r.content,'lxml')
    for i,p in enumerate(soup.find_all("a")):
        try:
            if ".xml" in p['href'] or ".json" in p['href'] or ".rss" in p['href']:
                print (p['href'])
                json_dict[str(p.text)]=p['href']
        except Exception:
            pass
    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:
        lod = xmltodict.parse(r.text)
    if ".rss" in rss_url:
        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()