I am developing an application that has a website and a series of keywords and queries the Google API at what position they are up to page 5.
For example:
Website: `www.stackoverflow.com`
Keywords: `web design`, `programming`, `help`
This will search up to the 5th page on Google and if it's not found then it will create an object with the keyword and the position would be "n/a".
I have created the following recusive function:
def getRankingsFromGoogle(keyword, website, page = 1, count = 1):
if count is 5:
print "NOT ON PAGE 5"
service = build("customsearch", "v1",
developerKey="")
res = service.cse().list(
q=keyword,
cx='',
start=page,
).execute()
obj = parseGoogleResponse(res, keyword, website)
if not bool(obj):
print "adding object to database.."
return
else:
page = page + 10
count += 1
getRankingsFromGoogle(keyword, website, page, count)
def main():
websites = getTrackedWebsites();
for website in websites:
keywords = website['keywords']
for keyword in keywords:
getWebsiteRankingsByKeywords(keyword, website['website'])
The function goes into the else
statement, but never actually reaches the if count is 5
which is where I need it to be in order to create the object for the keyword was not found.
I have also created another script:
def getRankingsFromGoogle(keyword, website, page = 1, count = 1):
if count is 5:
print "YAY"
return;
page = 10
count += 1
print page
getRankingsFromGoogle("asf", "www.google.com", page, count)
getRankingsFromGoogle("af", "www.google.com", 1, 1)
Which reaches the condition count is 5
.
I don't understand why this recursive function is not working.