main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from FTPModule import FTPS
  2. from threading import *
  3. import os
  4. from SysInfo import Informator
  5. import requests
  6. import time
  7. import config
  8. import random
  9. def read_authdata(filename):
  10. with open(filename,"r") as file:
  11. l = file.readline().split(",")
  12. print(l)
  13. return l
  14. l = read_authdata("authdata")
  15. print(l)
  16. user = l[0]
  17. passw= l [1]
  18. informator = Informator()
  19. ftps = FTPS(user,passw,str(os.getcwd())+"/storage/")
  20. def start_server():
  21. ftps.start_server(('127.0.0.1',21))
  22. def register_node():
  23. resp1 = requests.get(f"{config.coord_server}/reg?ip={informator.ip}&rg={informator.user_country}&u={user}&pass={passw}")
  24. print("REGISTRATION ",resp1.status_code)
  25. resp2 = requests.get(f"{config.coord_server}/update-info?ip={informator.ip}&rg={informator.user_country}&free_space={informator.getFreeDiskSpace()}")
  26. print("UPDATE ",resp2.status_code)
  27. def update_info():
  28. while True:
  29. time.sleep(15)
  30. resp2 = requests.get(f"{config.coord_server}/update-info?ip={informator.ip}&rg={informator.user_country}&free_space={informator.getFreeDiskSpace()}")
  31. print("UPDATE ", resp2.status_code)
  32. if __name__=="__main__":
  33. register_node()
  34. thread_update_info = Thread(target=update_info)
  35. thread_ftps = Thread(target=start_server)
  36. thread_ftps.start()
  37. thread_update_info.start()