#!flask/bin/python
#from user import User
from sampleObjects.User import User
from datetime import datetime
from sampleObjects.DetectionPoint import DetectionPoint

import time, requests, random, atexit

def requestGenerator():
    userObject = randomUser()
    detectionPointObject = randomDetectionPoint()

    req = requests.post('http://localhost:5000/addevent', json = {"User": userObject.__dict__, "DetectionPoint" : detectionPointObject.__dict__, "Time" : str(datetime.now().isoformat())})
    print (req.text)

    checkResp = requests.get('http://localhost:5000/getResponses')
    print (checkResp.text)

def randomUser():
    user = random.randint(1,3)
    attacker=0
    if (user==1):
        attacker = User("Phillipo", "255.255.255.101", "xxxx")
    elif (user==2):
        attacker = User("Sergio", "109.123.234.1", "yyyy")
    elif (user==3):
        attacker = User("Anonymous", "101.101.101.87", "354343jjk23")

    return attacker



def randomDetectionPoint():
    rand = random.randint(1,2)
    dp=0
    if (rand==1):
        dp = DetectionPoint("HTTP Verb", "GET Request used where POST is expected")
    elif (rand==2):
        dp = DetectionPoint("Login Page", "Hidden field altered within the login form")
    return dp


for i in range (50):
    requestGenerator()
    time.sleep(1.5)
def closingTime():
    print ("Exiting")

atexit.register(closingTime)

[((49, 0, 49, 28), 'atexit.register', 'atexit.register', ({(49, 16, 49, 27): 'closingTime'}, {}), '(closingTime)', False, 'import time, requests, random, atexit\n'), ((16, 16, 16, 66), 'requests.get', 'requests.get', ({(16, 29, 16, 65): '"""http://localhost:5000/getResponses"""'}, {}), "('http://localhost:5000/getResponses')", False, 'import time, requests, random, atexit\n'), ((20, 11, 20, 30), 'random.randint', 'random.randint', ({(20, 26, 20, 27): '1', (20, 28, 20, 29): '3'}, {}), '(1, 3)', False, 'import time, requests, random, atexit\n'), ((34, 11, 34, 30), 'random.randint', 'random.randint', ({(34, 26, 34, 27): '1', (34, 28, 34, 29): '2'}, {}), '(1, 2)', False, 'import time, requests, random, atexit\n'), ((45, 4, 45, 19), 'time.sleep', 'time.sleep', ({(45, 15, 45, 18): '(1.5)'}, {}), '(1.5)', False, 'import time, requests, random, atexit\n'), ((23, 19, 23, 62), 'sampleObjects.User.User', 'User', ({(23, 24, 23, 34): '"""Phillipo"""', (23, 36, 23, 53): '"""255.255.255.101"""', (23, 55, 23, 61): '"""xxxx"""'}, {}), "('Phillipo', '255.255.255.101', 'xxxx')", False, 'from sampleObjects.User import User\n'), ((37, 13, 37, 83), 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', ({(37, 28, 37, 39): '"""HTTP Verb"""', (37, 41, 37, 82): '"""GET Request used where POST is expected"""'}, {}), "('HTTP Verb', 'GET Request used where POST is expected')", False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), ((25, 19, 25, 58), 'sampleObjects.User.User', 'User', ({(25, 24, 25, 32): '"""Sergio"""', (25, 34, 25, 49): '"""109.123.234.1"""', (25, 51, 25, 57): '"""yyyy"""'}, {}), "('Sergio', '109.123.234.1', 'yyyy')", False, 'from sampleObjects.User import User\n'), ((39, 13, 39, 87), 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', ({(39, 28, 39, 40): '"""Login Page"""', (39, 42, 39, 86): '"""Hidden field altered within the login form"""'}, {}), "('Login Page', 'Hidden field altered within the login form')", False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), ((27, 19, 27, 69), 'sampleObjects.User.User', 'User', ({(27, 24, 27, 35): '"""Anonymous"""', (27, 37, 27, 53): '"""101.101.101.87"""', (27, 55, 27, 68): '"""354343jjk23"""'}, {}), "('Anonymous', '101.101.101.87', '354343jjk23')", False, 'from sampleObjects.User import User\n'), ((13, 158, 13, 172), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n')]