generated from lucien/api-template
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
import requests
|
|
from time import sleep
|
|
from random import randint
|
|
|
|
HOST = "http://192.168.200.15/"
|
|
|
|
"""Affichage des actions mises en vente par une entreprise
|
|
input :
|
|
- idComp : Identifiant de l'entreprise
|
|
"""
|
|
def getShares(idComp):
|
|
url = HOST + 'api/companies/'+idComp+'/shares'
|
|
r = requests.get(url)
|
|
return r.json()
|
|
|
|
"""Création d'une action par une entreprise
|
|
input :
|
|
- idComp : identifiant de l'entreprise
|
|
- price : prix de l'action sur le marché
|
|
"""
|
|
def emitShare(idComp, price):
|
|
url = HOST + 'api/shares/emit'
|
|
obj={'company_id':idComp,'price':price}
|
|
r = requests.post(url, json=obj)
|
|
return r.json()
|
|
|
|
"""Affichage des informations d'une enteprise
|
|
input :
|
|
- idComp : identifiant de l'entreprise
|
|
"""
|
|
def getCompany(idComp):
|
|
url = HOST + 'api/companies/'+idComp
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
"""Affichage les enteprises """
|
|
def getCompanies():
|
|
url = HOST + 'api/companies/'
|
|
r=requests.get(url)
|
|
return r.json()
|
|
|
|
if __name__ == "__main__":
|
|
while True:
|
|
companies = getCompanies()
|
|
|
|
for company in companies:
|
|
price = randint(20, 2000)
|
|
for i in range(randint(0, 10)):
|
|
emitShare(company["id"], price)
|
|
|
|
sleep(30)
|
|
|