File size: 4,121 Bytes
aa64e27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97c8695
aa64e27
97c8695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa64e27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97c8695
aa64e27
eaf1505
 
 
aa64e27
 
97c8695
aa64e27
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import gradio as gr
import requests
from bs4 import BeautifulSoup
import re

def search_fn(query,count):
    if count>99:
        count = 99
    page = requests.get(f"https://www.google.com/search?q={query}&num={count}")
    soup = BeautifulSoup(page.content)
    #links = soup.findAll("a")
    
    links = soup.findAll("a")
    file = open("myfile.txt", "w")

    for link in soup.find_all("a",href=re.compile("(?<=/url\?q=)(htt.*://.*)")):
        out = (re.split(":(?=http)",link["href"].replace("/url?q=","").split("&sa",1)[0]))
        out = out[0]
        rr=requests.get(f"{out}")
        x_opt = (dict(rr.headers).get("x-frame-options"))
        if x_opt == None:
            frame_l=f'<div class="container-mee"><div class="put-on-top"><a target="_blank" href="{out}">{out}</a></div><iframe class="responsive-iframe-mee" src="{out}" frameborder="3"></iframe></div>'
            file.writelines(frame_l)
        else:
            pass
      
        #print(file1.read())
        print (out)
        print(dict(rr.headers).get("x-frame-options"))

    file.close()
        
    with open("myfile.txt", "r") as file1:
        html_out = file1.read()
    out = format_t(html_out)  
    return out
def details_fn(query):

    page = requests.get(f"{query}")
    soup = BeautifulSoup(page.content)
    #links = soup.findAll("a")
    
    links = soup.findAll(".//title")
    file = open("myfile.txt", "w")
    
    #for link in soup.find_all(".//title"):
        #out = (re.split(":(?=http)",link["href"].replace("/url?q=","").split("&sa",1)[0]))
        #out = out[0]
        #rr=requests.get(f"{out}")
        #x_opt = (dict(rr.headers).get("x-frame-options"))
    #    if x_opt == None:
    #        frame_l=f'<div class="container-mee"><div class="put-on-top"><a target="_blank" href="{out}">{out}</a></div><iframe class="responsive-iframe-mee" src="{out}" frameborder="3"></iframe></div>'
    #        file.writelines(frame_l)
    #    else:
    #        pass
      
        #print(file1.read())
    print (links.text)
        #print(dict(rr.headers).get("x-frame-options"))

    file.close()
        
    #with open("myfile.txt", "r") as file1:
    #    html_out = file1.read()
    #out = format_t(html_out)  
    return links.text

def first():
    out = '''<h1>Loading'''
    return out

def test(out):
    return format_t(f'<div class="container-mee"><div class="put-on-top"><a target="_blank" href="{out}">{out}</a></div><iframe class="responsive-iframe-mee" src="{out}" frameborder="3"></iframe></div>')

def format_t(inp):

    style = '''
    .put-on-top{
    align-contents:center;
    border-style: solid;
    border-width: 3px;
    border-radius: 5px;
    background: none;
    padding: 0.5em;
    margin-top:1em;
    margin-bottom:0.3em;
    }
    .grid-mee {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: space-evenly;
	align-items: stretch;
	align-content: space-evenly;
}
    
    .container-mee {
  
  position: relative;
  overflow: hidden;
  width: 48%;
  height: 60em;
  margin-top:1em;
}
/* Then style the iframe to fit in the container div with full height and width */
.responsive-iframe-mee {
  position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
    
}
  '''
    out = f'''<!DOCTYPE html>
<html lang="en">
  <head>
  </head>
  <style>
  {style}
  </style>
  <body>
  <div class=grid-mee>
    {inp}
  </div>
  </body>
</html>'''
    return out
with gr.Blocks() as app:
    gr.HTML("""<h1>Interactive Social Media Card Maker</h1>""")
    gr.HTML("""<h3><b>Step 1:</b> Enter a URL with Iframe capability</h3>""")
    with gr.Row():
        search_box=gr.Textbox(label = "Enter a search topic here to find URL's",scale=2)
        num_return=gr.Number(label= "Number of URL's to return", value=20, scale=1)
        search_btn=gr.Button(value= "Search", scale=1)
    with gr.Row():
        input = gr.Textbox(label = "URL")
        btn = gr.Button("Preview")
    output = gr.HTML("""""")

    search_btn.click(search_fn,[search_box,num_return],output)
    btn.click(first,None,output).then(test,input,output)
app.launch()