generated from lucien/api-template
38 lines
899 B
Python
38 lines
899 B
Python
import requests
|
|
from time import sleep
|
|
from random import randint
|
|
|
|
HOST = "http://192.168.200.15/"
|
|
|
|
def getShares(idComp):
|
|
url = HOST + 'api/companies/'+idComp+'/shares'
|
|
r = requests.get(url)
|
|
return r.json()
|
|
|
|
def emitShare(idComp, price):
|
|
url = HOST + 'api/shares/emit'
|
|
obj={'company_id':idComp,'price':price}
|
|
r = requests.post(url, json=obj)
|
|
return r.json()
|
|
|
|
def getCompany(idComp):
|
|
url = HOST + 'api/companies/'+idComp
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
def getCompanies():
|
|
url = HOST + 'api/companies/'
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
if __name__ == "__main__":
|
|
while True:
|
|
companies = getCompanies()
|
|
|
|
price = randint(20, 2000)
|
|
for i in range(randint(0, 4)):
|
|
emitShare(randint(0, len(companies) - 1), price)
|
|
sleep(1)
|
|
|
|
sleep(30)
|
|
|