#!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)

[((1352, 1380), 'atexit.register', 'atexit.register', (['closingTime'], {}), '(closingTime)\n', (1367, 1380), False, 'import time, requests, random, atexit\n'), ((535, 585), 'requests.get', 'requests.get', (['"""http://localhost:5000/getResponses"""'], {}), "('http://localhost:5000/getResponses')\n", (547, 585), False, 'import time, requests, random, atexit\n'), ((643, 663), 'random.randint', 'random.randint', (['(1)', '(3)'], {}), '(1, 3)\n', (657, 663), False, 'import time, requests, random, atexit\n'), ((991, 1011), 'random.randint', 'random.randint', (['(1)', '(2)'], {}), '(1, 2)\n', (1005, 1011), False, 'import time, requests, random, atexit\n'), ((1294, 1309), 'time.sleep', 'time.sleep', (['(1.5)'], {}), '(1.5)\n', (1304, 1309), False, 'import time, requests, random, atexit\n'), ((715, 758), 'sampleObjects.User.User', 'User', (['"""Phillipo"""', '"""255.255.255.101"""', '"""xxxx"""'], {}), "('Phillipo', '255.255.255.101', 'xxxx')\n", (719, 758), False, 'from sampleObjects.User import User\n'), ((1051, 1121), 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', (['"""HTTP Verb"""', '"""GET Request used where POST is expected"""'], {}), "('HTTP Verb', 'GET Request used where POST is expected')\n", (1065, 1121), False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), ((798, 837), 'sampleObjects.User.User', 'User', (['"""Sergio"""', '"""109.123.234.1"""', '"""yyyy"""'], {}), "('Sergio', '109.123.234.1', 'yyyy')\n", (802, 837), False, 'from sampleObjects.User import User\n'), ((1155, 1229), 'sampleObjects.DetectionPoint.DetectionPoint', 'DetectionPoint', (['"""Login Page"""', '"""Hidden field altered within the login form"""'], {}), "('Login Page', 'Hidden field altered within the login form')\n", (1169, 1229), False, 'from sampleObjects.DetectionPoint import DetectionPoint\n'), ((877, 927), 'sampleObjects.User.User', 'User', (['"""Anonymous"""', '"""101.101.101.87"""', '"""354343jjk23"""'], {}), "('Anonymous', '101.101.101.87', '354343jjk23')\n", (881, 927), False, 'from sampleObjects.User import User\n'), ((467, 481), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (479, 481), False, 'from datetime import datetime\n')]