test.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from valeurs import *
  2. from scanValeur import *
  3. from timer import *
  4. from achatVente import *
  5. import time
  6. from threading import Thread, RLock
  7. f = open('cac.txt','r')
  8. valeur=[]
  9. for i in f:
  10. t = i.split(';')
  11. url = t[1]
  12. nom = t[0]
  13. valeur.append(Valeur(nom,url))
  14. f.close()
  15. tempsdepart =time.time()
  16. class AchatVente(Thread):
  17. def __init__(self):
  18. Thread.__init__(self)
  19. def run(self):
  20. i=0
  21. gain =0.0
  22. while 1:
  23. with verrou:
  24. if valeur[i].getAAnule() == 1:
  25. valeur[i].Anulation()
  26. if valeur[i].getAVendre() == 1:
  27. gain=gain+valeur[i].Vente()
  28. print ("Gain Total: "+ str(gain)+ " en " + str(time.time()-tempsdepart) + "s")
  29. if valeur[i].getMise()==0:
  30. valeur[i].Achat(250)
  31. time.sleep(00.001)
  32. i=i+1
  33. if i>39:
  34. i=0
  35. class Scan(Thread):
  36. def __init__(self):
  37. Thread.__init__(self)
  38. def run(self):
  39. i=0
  40. while 1:
  41. with verrou:
  42. tmp=valeur[i].getNewTaux()- valeur[i].getTaux()
  43. if tmp > 0.5:
  44. valeur[i].MiseEnVente()
  45. time.sleep(0.4)
  46. i=i+1
  47. if i>39:
  48. i=0
  49. class Timer(Thread):
  50. def __init__(self):
  51. Thread.__init__(self)
  52. def run(self):
  53. i=0
  54. while 1:
  55. with verrou:
  56. if valeur[i].tempsRestant() < 30:
  57. if valeur[i].getNewTaux() > 0:
  58. valeur[i].MiseEnVente()
  59. else:
  60. valeur[i].MiseEnAnnulation()
  61. time.sleep(0.4)
  62. i=i+1
  63. if i>39:
  64. i=0
  65. verrou = RLock()
  66. threadAchat = AchatVente()
  67. threadTimer = Timer()
  68. threadScan = Scan()
  69. threadAchat.start()
  70. threadTimer.start()
  71. threadScan.start()
  72. threadAchat.join()
  73. threadTimer.join()
  74. threadScan.join()
  75. #~ print(str(valeur[1].getTaux()))
  76. #~ print(str(valeur[1].getNewTaux()))