Skip to content

Instantly share code, notes, and snippets.

@bdnf
Created June 30, 2020 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdnf/ef3192f1de2289f8e5e3735c802bff5d to your computer and use it in GitHub Desktop.
Save bdnf/ef3192f1de2289f8e5e3735c802bff5d to your computer and use it in GitHub Desktop.
Generate clickstream events
import requests
import random
import sys
import argparse
def getClicked(rate):
if random.random() <= rate:
return True
else:
return False
def httpGetImpression():
url = args.target + '?browseraction=Impression'
r = requests.get(url)
def httpGetClick():
url = args.target + '?browseraction=Click'
r = requests.get(url)
sys.stdout.write('+')
parser = argparse.ArgumentParser()
parser.add_argument("target",help="<http...> the http(s) location to send the GET request")
args = parser.parse_args()
i = 0
while (i < 2500):
httpGetImpression()
if(i<1950 or i>=2000):
clicked = getClicked(.1)
sys.stdout.write('_')
else:
clicked = getClicked(.5)
sys.stdout.write('-')
if(clicked):
httpGetClick()
i = i + 1
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment