File size: 1,644 Bytes
01b7d84
 
3f1df0d
26fd880
b166bee
01b7d84
 
f7cf6e6
 
 
2ee2a2c
f7cf6e6
3cf842d
 
 
 
f7cf6e6
9e02324
 
 
dc1f1cd
9e02324
d33ca30
9e02324
5853efe
 
 
d1bf724
dc1f1cd
 
 
5853efe
 
9e02324
dc1f1cd
a6e671f
01b7d84
79272ae
 
 
 
 
6cfa95b
5ebc5a8
 
01b7d84
617c1aa
01b7d84
 
9e02324
 
 
 
 
f7cf6e6
9bb3b94
3cf842d
 
9bb3b94
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import requests
import xmltodict
import bs4
import lxml
import json



def read_rss():
    f = open('feeds_sorted.json')
    data = json.load(f)
    #with open('tmp.json','w') as f:
    out = json.dumps(data, indent=4)
    #f.close()
    return data, out

def find_rss(rss_url):
    json_box=[]
    json_dict={}
    json_dict_other={}
    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']
            else:
                json_dict_other[str(p.text)]=p['href']
                
        except Exception:
            pass
    json_box.append(json_dict)
    json_box.append(json_dict_other)
    yield 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")
    r_btn=gr.Button("read")
    with gr.Row():
        out_json = gr.JSON()
        fil = gr.Textbox()
    r_btn.click(read_rss,None,[out_json,fil])
    search_btn.click(find_rss,rss_search,out_json)
    btn.click(get_rss,rss,out_json)
app.launch()