فهرست منبع

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/kw_tools into master

Your Name 3 سال پیش
والد
کامیت
e55047c244
4فایلهای تغییر یافته به همراه262 افزوده شده و 64 حذف شده
  1. BIN
      similar_server/__pycache__/main.cpython-39.pyc
  2. 7 6
      similar_server/main.py
  3. 143 58
      similar_web/index.html
  4. 112 0
      similar_web/main.py

BIN
similar_server/__pycache__/main.cpython-39.pyc


+ 7 - 6
similar_server/main.py

@@ -12,7 +12,6 @@ from fastapi.responses import JSONResponse
 from fastapi.middleware.cors import CORSMiddleware
 db = dataset.connect('sqlite:///similar.db')
 
-
 app = FastAPI()
 
 origins = [
@@ -33,19 +32,21 @@ app.add_middleware(
 )
 
 
-@app.get("/query/{qq}")
-async def query(qq):
-    print(qq)
-    return JSONResponse(content={'query':qq})
+@app.get("/index")
+async def index():
+    return FileResponse('index.html')
 
 
 
-@app.get("/dm/{domain_name}")
+@app.post("/dm/{domain_name}")
 async def get_domain(domain_name):
     url = "https://similarweb2.p.rapidapi.com/pageoverview"
 
     if 'http' not in domain_name:
         domain_name='http://'+domain_name
+    domain_name = domain_name.replace('%3A',':')
+    domain_name = domain_name.replace('%2F','/')
+    print(domain_name)
     querystring = {"website":domain_name}
 
     headers = {

+ 143 - 58
similar_web/index.html

@@ -32,8 +32,67 @@
   ></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 -->
@@ -93,8 +152,8 @@
       <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="Search" aria-label="Domain Name" id="search_query"/>
-          <button class="btn btn-primary search__btn" type="button" data-mdb-ripple-color="dark" id="search__btn">
+          <input type="search" class="form-control search__bar" placeholder="Search" aria-label="Domain Name" id="search_query"  />
+          <button class="btn btn-primary search__btn" type="button" data-mdb-ripple-color="dark" id="search__btn" >
               Search
           </button>
         </form>
@@ -172,7 +231,7 @@
                     <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>
+                    <span href="#" class="rank__mark"><strong id="maxflow" class="rank_num">1000</strong></span>
                   </div>
                 </div>
               </div>
@@ -229,94 +288,120 @@
   <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
-  });
+  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();
   })
-  input.addEventListener("keyup", function(event) {
-    // Number 13 is the "Enter" key on the keyboard
-    if (event.keyCode === 13) {
-      check_form();
-      event.preventDefault();
-  //    document.getElementById("myBtn").click();
-    }
-  });
 
   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 qry = document.getElementById('search_query').value;
-      axios.get('http://www.googo.org:8080/dm/' + qry)
-
-      //      axios.get('http://www.googo.org:8080/domain/' + qry)
-      .then((response) => {
+      
         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');    
-
-        console.log(response.data); 
-        //    alert(response.data.SiteName);
-        //    var obj = JSON.parse(response.data);
-        //    alert(obj);
-        sitename.textContent =response.data.SiteName;
-        descriptions.textContent=response.data.Description;
-        globalrank.textContent=response.data.GlobalRank;
-        sitetitle.textContent=response.data.Title;
-        countryrank.textContent=response.data.CountryRank;
-        category.textContent=response.data.Category;
-    
-        const key_ary=[];
-        const val_ary=[];
-        for (const [key, value] of Object.entries(response.data.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);
+        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>

+ 112 - 0
similar_web/main.py

@@ -0,0 +1,112 @@
+import rpyc
+import time
+from fastapi import FastAPI
+import sys
+import os
+import dataset
+import requests
+import datetime
+import json
+import ast
+from fastapi.responses import JSONResponse, FileResponse
+from fastapi.middleware.cors import CORSMiddleware
+from pydantic import BaseModel
+
+
+app = FastAPI()
+
+origins = [
+    "http://www.googo.org",
+    "http://www.googo.org:8080",
+    "http://0.0.0.0:8080",
+    "http://googo.org:8080",
+    "http://googo.org",
+    "http://139.162.121.30"
+]
+
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=origins,
+    allow_credentials=True,
+    allow_methods=["*"],
+    allow_headers=["*"],
+)
+
+class q_req(BaseModel):
+    domain_name: str
+
+
+@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):
+    url = "https://similarweb2.p.rapidapi.com/pageoverview"
+    domain_name=req.domain_name
+    if 'http' not in domain_name:
+        domain_name='http://'+domain_name
+    domain_name = domain_name.replace('%3A',':')
+    domain_name = domain_name.replace('%2F','/')
+    print(domain_name)
+    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+'"'
+    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']}
+    print(jsdict)
+    if jsdict==None:
+        headers = {
+            "x-rapidapi-key": "6dd30886e0msh7aefc9a0a794398p1896f2jsn275c45475609",
+            "x-rapidapi-host": "similarweb2.p.rapidapi.com"
+        }
+
+        response = requests.request("GET", url, headers=headers, params=querystring)
+        #print(response.text)
+        js=json.loads(response.text)
+        #print(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']
+        log_table.insert({'SiteName':jsdict['SiteName'],'Description':jsdict['Description'],'GlobalRank':jsdict['GlobalRank']
+        ,'Title':jsdict['Title'],'Category':jsdict['Category'],'CountryRank':jsdict['CountryRank'],'EstimatedMonthlyVisits':jsdict['EstimatedMonthlyVisits']
+        ,'totalVisits':jsdict['totalVisits']})
+
+    
+#    desc=js['siteDescription']
+#    ustr=desc.encode('utf-8').decode('utf-8')
+#    print(ustr)
+    return JSONResponse(content=jsdict)
+
+
+
+
+
+