Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import requests
  2.  
  3.  
  4. googleUpdates = ["2019-11-20", "2019-03-01", "2018-08-01"]
  5. domains = ["amazon.com", "sistrix.com"]
  6. baseUrl = "https://api.sistrix.com/domain.sichtbarkeitsindex?api_key=S6wam3Uq3KdcuEHYb4nSTmR8EhapBjjj&format=json"
  7.  
  8. def calculateTrend(date1, date2):
  9.   perc = (date1 / date2) * 100
  10.   return round(perc - 100, 1)
  11.  
  12. myDict = {}
  13. for domain in domains:
  14.   i = 0
  15.   while i < len(googleUpdates) - 1:
  16.     url1 = f"{baseUrl}&domain={domain}&date={googleUpdates[0]}"
  17.     url2 = f"{baseUrl}&domain={domain}&date={googleUpdates[i+1]}"
  18.     df1 = requests.get(url1).json()["answer"][0]["sichtbarkeitsindex"][0]["value"]
  19.     df2 = requests.get(url2).json()["answer"][0]["sichtbarkeitsindex"][0]["value"]
  20.     trend = f"{calculateTrend(df1, df2)}%"
  21.     if domain in myDict:
  22.       myDict[domain].append(trend)
  23.     else:
  24.       myDict[domain] = [trend]
  25.     i += 1
  26.  
  27. print(myDict)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement