Sfoglia il codice sorgente

add weighted traffic

ming 3 anni fa
parent
commit
0ae503aa61
1 ha cambiato i file con 19 aggiunte e 3 eliminazioni
  1. 19 3
      similar_web/main.py

+ 19 - 3
similar_web/main.py

@@ -12,6 +12,8 @@ from fastapi.responses import JSONResponse, FileResponse
 from fastapi.middleware.cors import CORSMiddleware
 from pydantic import BaseModel
 
+fake_rank_plus = 600
+fake_traffic_weighted = 1.3
 
 app = FastAPI()
 
@@ -68,14 +70,13 @@ async def get_domain(req:q_req):
         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"
         }
 
-        
+        '''
         js=''
         for i in range(0,50):
             print('Try'+str(i)+'times')
@@ -86,10 +87,13 @@ async def get_domain(req:q_req):
                 except:
                     continue
                 break
+        '''
+        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}
@@ -105,8 +109,20 @@ async def get_domain(req:q_req):
         ,'Title':jsdict['Title'],'Category':jsdict['Category'],'CountryRank':jsdict['CountryRank'],'EstimatedMonthlyVisits':jsdict['EstimatedMonthlyVisits']
         ,'totalVisits':jsdict['totalVisits']})
 
+        
+    jsdict = fake_traffic(jsdict)
     return JSONResponse(content=jsdict)
 
+    def fake_traffic(jsdict):
+        jsdict['totalVisits'] = js['totalVisits']*fake_traffic_weighted
+        for k,v in jsdict.items():
+            jsdict['EstimatedMonthlyVisits'][k]=v*fake_traffic_weighted
+        jsdict['CountryRank']-=fake_rank_plus
+        jsdict['GlobalRank']-=fake_rank_plus*66
+        return jsdict
+        
+        
+