#!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, 'atexit.register', 'atexit.register', False, 'import time, requests, random, atexit\n'), (16, 'requests.get', 'requests.get', False, 'import time, requests, random, atexit\n'), (20, 'random.randint', 'random.randint', False, 'import time, requests, random, atexit\n'), (34, 'random.randint', 'random.randint', False, 'import time, requests, random, atexit\n'), (45, 'time.sleep', 'time.sleep', False, 'import time, requests, random, atexit\n'), (23, 'sampleObjects.User.User', 'User', False, 'from sampleObjects.User import User\n'), (37, 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), (25, 'sampleObjects.User.User', 'User', False, 'from sampleObjects.User import User\n'), (39, 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), (27, 'sampleObjects.User.User', 'User', False, 'from sampleObjects.User import User\n'), (13, 'datetime.datetime.now', 'datetime.now', False, 'from datetime import datetime\n')]