Selaa lähdekoodia

kw basic search

ming 3 vuotta sitten
vanhempi
commit
7e81d36d8b
4 muutettua tiedostoa jossa 513 lisäystä ja 43 poistoa
  1. 1 1
      similar_web/index.html
  2. 410 0
      similar_web/keyword.html
  3. 51 0
      similar_web/keywords.html
  4. 51 42
      similar_web/main.py

+ 1 - 1
similar_web/index.html

@@ -180,7 +180,7 @@
               <div class="col-sm-4">
                 <div class="card p-3">
                   <div class="card-body text-center">
-                    <h5 class="card-title card__rank__title mb-2">國際行</h5>
+                    <h5 class="card-title card__rank__title mb-2">國際行</h5>
                     <p class="card-text" >
                     </p>
                     <span href="#" class="rank__mark"># <strong id="globalrank" class="rank_num">1000</strong></span>

+ 410 - 0
similar_web/keyword.html

@@ -0,0 +1,410 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <meta http-equiv="X-UA-Compatible" content="ie=edge">
+  <title>Googo Website Traffic</title>
+  <!-- Font Awesome -->
+  <link
+    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
+    rel="stylesheet"
+  />
+  <!-- Google Fonts -->
+  <link
+    href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
+    rel="stylesheet"
+  />
+  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
+    integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
+  <!-- MDB -->
+  <link
+    href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/3.3.0/mdb.min.css"
+    rel="stylesheet"
+  />
+  <link rel="stylesheet" href="https://unpkg.com/js-datepicker/dist/datepicker.min.css">
+  <link rel="stylesheet" type="text/css" href="reset.css">
+  <link rel="stylesheet" type="text/css" href="main.css">
+  <!-- MDB -->
+  <script
+    type="text/javascript"
+    src="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/3.3.0/mdb.min.js"
+  ></script>    
+  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
+  <script src="echarts.min.js"></script>
+  <style>
+    body {
+      font-family: 'Lato', sans-serif;
+    }
+    
+    .overlay {
+      height: 100%;
+      width: 100%;
+      display: none;
+      position: fixed;
+      z-index: 1;
+      top: 0;
+      left: 0;
+      background-color: rgb(0,0,0);
+      background-color: rgba(0,0,0, 0.6);
+    }
+    
+    .overlay-content {
+      position: relative;
+      top: 25%;
+      width: 100%;
+      text-align: center;
+      margin-top: 30px;
+    }
+    
+    .overlay a {
+      padding: 8px;
+      text-decoration: none;
+      font-size: 36px;
+      color: #818181;
+      display: block;
+      transition: 0.3s;
+    }
+    
+    .overlay a:hover, .overlay a:focus {
+      color: #f1f1f1;
+    }
+    
+    .overlay .closebtn {
+      position: absolute;
+      top: 20px;
+      right: 45px;
+      font-size: 60px;
+    }
+    
+    @media screen and (max-height: 450px) {
+      .overlay a {font-size: 20px}
+      .overlay .closebtn {
+      font-size: 40px;
+      top: 15px;
+      right: 35px;
+      }
+    }
+    </style>
+</head>
+<body class="color__grey">
+  <div id="myNav" class="overlay">
+    <div class="overlay-content">
+      <a href="#">載入資料中,請稍候</a>
+    </div>
+  </div>
+<!-- Navbar -->
+  <nav class="navbar navbar-expand-lg navbar-light bg-white">
+    <!-- Container wrapper -->
+    <div class="container-fluid">
+      <!-- Navbar brand -->
+      <a class="navbar-brand" href="#">Googo Website Traffic</a>
+  
+      <!-- Toggle button -->
+      <button class="navbar-toggler" type="button" data-mdb-toggle="collapse"
+        data-mdb-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
+        aria-label="Toggle navigation">
+        <i class="fas fa-bars text-light"></i>
+      </button>
+  
+      <!-- Collapsible wrapper -->
+      <div class="collapse navbar-collapse" id="navbarSupportedContent">
+        <!-- Left links -->
+        <ul class="navbar-nav me-auto d-flex flex-row mt-3 mt-lg-0">
+          <li class="nav-item text-center mx-2 mx-lg-1">
+            <a class="nav-link active" aria-current="page" href="index.html">
+              <div>
+                <i class="fas fa-home fa-lg mb-1"></i>
+              </div>
+              首頁
+            </a>
+          </li>
+          <li class="nav-item text-center mx-2 mx-lg-1">
+            <a class="nav-link" href="http://news.google.com">
+              <div>
+                <i class="fas fa-globe-americas fa-lg mb-1"></i>
+                <!-- <span class="badge rounded-pill badge-notification bg-success">11</span> -->
+              </div>
+              新聞
+            </a>
+          </li>
+          <li class="nav-item text-center mx-2 mx-lg-1">
+            <a class="nav-link" href="keywords.html">
+              <div>
+                <i class="fab fa-korvue fa-lg mb-1"></i>
+                <!-- <span class="badge rounded-pill badge-notification bg-success">11</span> -->
+              </div>
+              關鍵字
+            </a>
+          </li>
+        </ul>
+        <!-- Right links -->
+      </div>
+      <!-- Collapsible wrapper -->
+    </div>
+    <!-- Container wrapper -->
+  </nav>
+  <!-- Navbar -->
+
+  <div class="container">
+    <div class="row">
+      <!-- <div class="col-1 col-lg-1"></div> -->
+      <div class="col-12 col-12">
+          <!-- Search form  -->
+        <form id="searchform" class="d-flex input-group search__form">
+          <input type="search" class="form-control search__bar" placeholder="在此輸入網址" aria-label="Domain Name" id="search_query"  />
+          <button class="btn btn-primary search__btn" type="button" data-mdb-ripple-color="dark" id="search__btn" >
+              查詢
+          </button>
+        </form>
+          <h3 class="h3 text-center" id="sitename">Website Traffic</h3>
+            <div class="card card__grback mb-4">
+              <div class="card-body card__left">
+              <!-- 根據搜尋內容顯示網站標題及網站內容簡介 -->
+                <h5 class="card-title card__url" id="sitetitle"><i class="fas fa-chart-bar card__url__icon"></i>Example.com</h5>
+                <p class="card-text card__intro" id="descriptions">
+                  Lorem ipsum dolor sit amet consectetur adipisicing elit. Ut ipsa totam maxime pariatur iure 
+                  suscipit nihil possimus deserunt esse blanditiis. Quidem aliquid, voluptas quae tenetur quaerat 
+                  iure explicabo repellat ad.
+                </p>
+  <!--            <a href="#" class="btn btn-primary" id="globalrank2"></a> -->
+              </div>
+            </div>
+            <div class="date__input mb-3">
+              <label for="daterng">開始日期:</label><input type="text" name="daterng" id="daterng1">
+              <label for="daterng">結束日期:</label><input type="text" name="daterng" id="daterng2">
+              <button class='sub__date btn'>套用</button>
+            </div>
+            <div class="text-muted mb-2 border-bottom">排行</div>
+            <div class="row g-5 mb-3">
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2">國際牌行</h5>
+                    <p class="card-text" >
+                    </p>
+                    <span href="#" class="rank__mark"># <strong id="globalrank" class="rank_num">1000</strong></span>
+                  </div>
+                </div>
+              </div>
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2">國內排行</h5>
+                    <p class="card-text">
+                    </p>
+                    <span href="#" class="rank__mark"># <strong id="countryrank" class="rank_num">100</strong></span>
+                  </div>
+                </div>
+              </div>
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2"><i class="fas fa-tags"></i>網站類別</h5>
+                    <p class="card-text card__rank__cat" id="category">
+                      Lorem
+                    </p>
+                  </div>
+                </div>
+              </div>
+            </div>
+            <div class="text-muted mt-5 mb-2">Global Website Traffic Rankings</div>
+            <div class="row mb-4">
+              <div class="col-12 col-12">
+                  <!--
+                  <button type="button" class="btn btn-primary btn-block mb-4 ripple-surface">Place order</button>
+                  -->
+                <div class="card card__notHover">
+                  <div id="main" class="chart"></div>
+                </div>
+              </div>
+            </div>
+            <div class="text-muted mb-2 border-bottom">BENEFIT</div>
+            <div class="btn-group group__btn" role="group" aria-label="date-buttons">
+              <button class="btn__benefit active">搜尋流量</button>
+              <button class="btn__benefit">有搜尋流量的網頁數</button>
+            </div>
+            <div class="row g-5 mb-3">
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2">搜尋流量</h5>
+                    <p class="card-text" >
+                    </p>
+                    <span href="#" class="rank__mark"><strong id="maxflow" class="rank_num">1000</strong></span>
+                  </div>
+                </div>
+              </div>
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2">有搜尋流量的網頁數</h5>
+                    <p class="card-text">
+                    </p>
+                    <span href="#" class="rank__mark"><strong id="countryrank" class="rank_num">100</strong></span>
+                  </div>
+                </div>
+              </div>
+              <div class="col-sm-4">
+                <div class="card p-3">
+                  <div class="card-body text-center">
+                    <h5 class="card-title card__rank__title mb-2"><i class="fas fa-tags"></i>轉換訂單數</h5>
+                    <span href="#" class="rank__mark"><strong id="countryrank" class="rank_num">100</strong></span>
+                  </div>
+                </div>
+              </div>
+            </div>
+            <div class="row mb-4">
+              <div class="col-12 col-12">
+                  <!--
+                  <button type="button" class="btn btn-primary btn-block mb-4 ripple-surface">Place order</button>
+                  -->
+                <div class="card card__notHover">
+                  <div id="main" class="chart"></div>
+                </div>
+              </div>
+            </div>
+            <div class="text-muted mb-2 border-bottom">SEO</div>
+            <div class="row mb-4">
+              <div class="col-12 col-12">
+                  <!--
+                  <button type="button" class="btn btn-primary btn-block mb-4 ripple-surface">Place order</button>
+                  -->
+                <div class="card card__notHover">
+                  <div id="bar" class="chart"></div>
+                </div>
+              </div>
+            </div>
+      </div>
+    </div>
+  </div>
+  <footer class="footer text-center p-4 bg-white">
+    <div class="text-muted"> © 2021 Copyright: Googo Website Traffic</div>
+  </footer>
+  <script
+  src="https://code.jquery.com/jquery-3.6.0.min.js"
+  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
+  crossorigin="anonymous"></script>
+  <script src="https://unpkg.com/js-datepicker"></script>
+
+<script>
+  function openNav() {
+  document.getElementById("myNav").style.display = "block";
+}
+
+function closeNav() {
+  document.getElementById("myNav").style.display = "none";
+}
+
+  const input = document.getElementById("search_query");
+  const search__btn = document.getElementById("search__btn");
+  const btn__benefit = document.querySelectorAll(".btn__benefit");
+  const picker_str = datepicker('#daterng1', {id: 1});
+  const picker_end = datepicker('#daterng2', {id: 1});
+  $('.sub__date').click(function(e){
+    e.preventDefault();
+    console.log(picker_end.getRange());
+  });
+  search__btn.addEventListener("click", function(e) {
+    openNav()
+    e.preventDefault();
+    check_form();
+  })
+
+  btn__benefit.forEach((item, i) => {
+    item.addEventListener("click", function(){
+      item.toggleClass('active');
+    })
+  });
+  $('#search_query').keydown(function(e){
+    //
+    if (event.keyCode == 13){
+      document.getElementById('search__btn').click()
+      e.preventDefault();
+    }
+  });
+
+  const myChart = echarts.init(document.getElementById('main'));
+  let option;
+
+  function check_form(){
+      
+        const sitename = document.getElementById('sitename');
+        const sitetitle = document.getElementById('sitetitle');
+        const descriptions = document.getElementById('descriptions');
+        const globalrank = document.getElementById('globalrank');
+        const countryrank = document.getElementById('countryrank');    
+        const category = document.getElementById('category');    
+        response = ''
+        
+        dataOBJ = {'domain_name':$('#search_query').val()}
+        objstr = JSON.stringify(dataOBJ);
+        console.log(objstr)
+        
+        $.ajax({
+            url: 'http://www.googo.org:8001/dm',
+            //url: 'http://www.choozmo.com:8888/qqreq',
+            dataType : 'json', // 預期從server接收的資料型態
+            contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
+            type: 'post',
+            data: objstr,
+            success: function(suc_data) {
+                
+                response = suc_data
+                sitename.textContent =response.SiteName;
+                descriptions.textContent=response.Description;
+                globalrank.textContent=response.GlobalRank;
+                sitetitle.textContent=response.Title;
+                countryrank.textContent=response.CountryRank;
+                category.textContent=response.Category;
+                $('#maxflow').html(response.totalVisits)
+                key_ary=[];
+                val_ary=[];
+                
+                for (const [key, value] of Object.entries(response.EstimatedMonthlyVisits)) {
+                  key_ary.push(key);
+                  val_ary.push(value);
+                }
+                
+                option = {
+                    xAxis: {
+                        type: 'category',
+                        boundaryGap: false,
+                        data: key_ary
+                    },
+                    yAxis: {
+                        type: 'value'
+                    },
+                    series: [{
+                        data: val_ary,
+                        type: 'line',
+                        areaStyle: {}
+                    }]
+                };
+                    myChart.setOption(option);
+                    closeNav()
+              },
+            //data:JSON.stringify({n1:"12",n2:"22"}),
+            error: function (error) {
+              alert('此網頁無法查詢!')
+              closeNav()
+            }
+        });
+        
+        
+       
+      //   sitename.innerHTML =response.data
+
+      // var bar = document.getElementById('bar');
+
+      // var barChart = echarts.init(bar);
+    }
+
+
+
+</script>
+
+</body>
+
+    
+</html>

+ 51 - 0
similar_web/keywords.html

@@ -330,6 +330,57 @@ const myChart = echarts.init(document.getElementById('main'));
 let option;
 
 function check_form(){
+  dataOBJ = {'keyword':$('#following_keys').val()}
+  objstr = JSON.stringify(dataOBJ);
+  $.ajax({
+            url: 'http://www.googo.org:8001/kw_dm',
+            //url: 'http://www.choozmo.com:8888/qqreq',
+            dataType : 'json', // 預期從server接收的資料型態
+            contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
+            type: 'post',
+            data: objstr,
+            success: function(suc_data) {
+                
+                response = suc_data
+                sitename.textContent =response.SiteName;
+                descriptions.textContent=response.Description;
+                globalrank.textContent=response.GlobalRank;
+                sitetitle.textContent=response.Title;
+                countryrank.textContent=response.CountryRank;
+                category.textContent=response.Category;
+                $('#maxflow').html(response.totalVisits)
+                key_ary=[];
+                val_ary=[];
+                
+                for (const [key, value] of Object.entries(response.EstimatedMonthlyVisits)) {
+                  key_ary.push(key);
+                  val_ary.push(value);
+                }
+                
+                option = {
+                    xAxis: {
+                        type: 'category',
+                        boundaryGap: false,
+                        data: key_ary
+                    },
+                    yAxis: {
+                        type: 'value'
+                    },
+                    series: [{
+                        data: val_ary,
+                        type: 'line',
+                        areaStyle: {}
+                    }]
+                };
+                    myChart.setOption(option);
+                    closeNav()
+              },
+            //data:JSON.stringify({n1:"12",n2:"22"}),
+            error: function (error) {
+              alert('此網頁無法查詢!')
+              closeNav()
+            }
+        });
     const qry = document.getElementById('search_query').value;
     axios.get('http://www.googo.org:8080/domain/' + qry)
     .then((response) => {

+ 51 - 42
similar_web/main.py

@@ -11,6 +11,7 @@ import ast
 from fastapi.responses import JSONResponse, FileResponse
 from fastapi.middleware.cors import CORSMiddleware
 from pydantic import BaseModel
+from googlesearch import search
 
 fake_rank_plus = 700
 fake_traffic_weighted = 1.3
@@ -25,7 +26,7 @@ origins = [
     "http://googo.org",
     "http://139.162.121.30"
 ]
-
+#uvicorn main:app --host 0.0.0.0 --port 8001
 app.add_middleware(
     CORSMiddleware,
     allow_origins=origins,
@@ -36,6 +37,8 @@ app.add_middleware(
 
 class q_req(BaseModel):
     domain_name: str
+class kw_req(BaseModel):
+    keyword: str
 
 def fake_traffic(jsdict):
         print('im here')
@@ -45,25 +48,10 @@ def fake_traffic(jsdict):
         jsdict['CountryRank']-=fake_rank_plus
         jsdict['GlobalRank']-=fake_rank_plus*66
         return jsdict
-        
-@app.get("/index")
-async def index():
-    return FileResponse('index.html')
-@app.get("/echarts.min.js")
-async def index():
-    return FileResponse('echarts.min.js')
-@app.get("/reset.css")
-async def index():
-    return FileResponse('reset.css')
-@app.get("/main.css")
-async def index():
-    return FileResponse('main.css')
 
-
-@app.post("/dm")
-async def get_domain(req:q_req):
+def get_domain_data(raw_domain):
     url = "https://similarweb2.p.rapidapi.com/pageoverview"
-    domain_name=req.domain_name
+    domain_name=raw_domain
     if 'http' not in domain_name:
         domain_name='http://'+domain_name
     domain_name = domain_name.replace('%3A',':')
@@ -72,44 +60,23 @@ async def get_domain(req:q_req):
     querystring = {"website":domain_name}
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
     
-    statement = 'SELECT * FROM storage_similar_web where SiteName ="'+ req.domain_name+'"'
+    statement = 'SELECT * FROM storage_similar_web where SiteName ="'+ raw_domain+'"'
     jsdict = None
     for row in db.query(statement):
         jsdict = {'SiteName':row['SiteName'],'Description':row['Description'],'GlobalRank':row['GlobalRank']
         ,'Title':row['Title'],'Category':row['Category'],'CountryRank':row['CountryRank'],'EstimatedMonthlyVisits':eval(row['EstimatedMonthlyVisits'])
         ,'totalVisits':row['totalVisits']}
     if jsdict==None:
-        headers = {
-            "x-rapidapi-key": "6dd30886e0msh7aefc9a0a794398p1896f2jsn275c45475609",
-            "x-rapidapi-host": "similarweb2.p.rapidapi.com"
-        }
-
-        '''
-        js=''
-        for i in range(0,50):
-            print('Try'+str(i)+'times')
-            while True:
-                try:
-                    response = requests.request("GET", url, headers=headers, params=querystring)
-                    js=json.loads(response.text)
-                except:
-                    continue
-                break
-        '''
+        headers = {"x-rapidapi-key": "6dd30886e0msh7aefc9a0a794398p1896f2jsn275c45475609",
+            "x-rapidapi-host": "similarweb2.p.rapidapi.com"}
         response = requests.request("GET", url, headers=headers, params=querystring)
-        print(response)
         js=json.loads(response.text)
-
         jsdict={'SiteName':js['name'],'Description':js['siteDescription'],'GlobalRank':js['globalRank'],'Title':js['name'],'Category':js['categoryRank']['taxonomy'],'CountryRank':js['countryRank']['rank']}
-
         url = "https://similarweb2.p.rapidapi.com/trafficoverview"
-
         querystring = {"website":domain_name}
 
         response = requests.request("GET", url, headers=headers, params=querystring)
-
         js2=json.loads(response.text)
-        #print(response.text)
         jsdict['totalVisits'] = js2['engagement']['totalVisits']
         jsdict['EstimatedMonthlyVisits']=js2['monthlyVisitsEstimate']
         log_table = db['storage_similar_web']
@@ -119,6 +86,48 @@ async def get_domain(req:q_req):
 
     if 'hhh' in domain_name:   
         jsdict = fake_traffic(jsdict)
+    return jsdict
+
+def domain_filter(url_array):
+    exclude_list = ['facebook','youtube','twitter','linkedin','instagram']
+    list_filted = []
+    for url in url_array:
+        a_social_media = False
+        for ex in exclude_list:
+            if ex in url:
+                a_social_media = True
+        if !(a_social_media):
+            list_filted+=[url]
+    return list_filted
+            
+
+
+def get_domain():        
+@app.get("/index")
+async def index():
+    return FileResponse('index.html')
+@app.get("/keyword")
+async def keyword():
+    return FileResponse('keyword.html')
+@app.get("/echarts.min.js")
+async def index():
+    return FileResponse('echarts.min.js')
+@app.get("/reset.css")
+async def index():
+    return FileResponse('reset.css')
+@app.get("/main.css")
+async def index():
+    return FileResponse('main.css')
+
+@app.post("/kw_dm")
+async def get_domain_by_keyword(req:kw_req):
+    ls = domain_filter(search(req.keyword,num_results=20))
+    jsdict = get_domain(ls[0])
+    return JSONResponse(content=jsdict)
+    
+@app.post("/dm")
+async def get_domain_data(req:q_req):
+    jsdict = get_domain(req.domain_name)
     return JSONResponse(content=jsdict)