producer.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #-*-coding:utf-8 -*-
  2. import os,sys
  3. import requests
  4. def get_imgs(task_id):
  5. data = []
  6. root = os.path.dirname(os.path.abspath(__file__))
  7. filelist = os.listdir(".")
  8. filelist.sort()
  9. for file in filelist:
  10. if file.endswith(".jpg") or file.endswith(".png"):
  11. newfile = "{}_{}".format(task_id,file.split("_")[1])
  12. os.rename(file,newfile)
  13. filelist = os.listdir(".")
  14. filelist.sort()
  15. for name in filelist:
  16. if name.endswith(".jpg") or name.endswith(".png"):
  17. data.append(os.path.join(root,name))
  18. return data
  19. def producer(task_id):
  20. #url = "http://47.108.130.28:8000/v1/common/uppapers"
  21. url = "http://192.168.117.131:8000/v1/common/uppapers"
  22. imgs = get_imgs(task_id)
  23. for img in imgs:
  24. name = os.path.split(img)[-1]
  25. files = {"datafile":(name,open(img,"rb"))}
  26. res = requests.post(url,files=files)
  27. print(res.json())
  28. if __name__ == "__main__":
  29. task_id = raw_input(u"please input task_id...\n")
  30. producer(task_id)