read_data.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import csv
  2. import re
  3. def read_dimensions(file_out, num):
  4. with open(file_out) as csv_file:
  5. csv_reader = csv.reader(csv_file, delimiter=';')
  6. line_count = 0
  7. durchmesser = False
  8. vorzeichen1 = "nix"
  9. is2vorzeichen = False
  10. vorzeichen2 = "nix"
  11. isos = []
  12. dimensions = []
  13. for row in csv_reader:
  14. #print(row)
  15. line_count += 1
  16. if "ISO" in row[num]:
  17. isos.append(row[num])
  18. if durchmesser:
  19. #print("Durchmesser: " + row[1])
  20. dimensions.append("Durchmesser: " + row[num])
  21. durchmesser = False
  22. continue
  23. if row[num] == "%%c":
  24. durchmesser = True
  25. continue
  26. if vorzeichen1 != "nix" and (row[num] == "-" or row[num] == "+"):
  27. is2vorzeichen = True
  28. vorzeichen2 = row[num]
  29. continue
  30. if row[num] == "-" or row[num] == "+":
  31. vorzeichen1 = row[num]
  32. continue
  33. isnumber = re.findall(r"\d*\,\d+", row[num]) #regex to get number out of line
  34. if isnumber:
  35. print(isnumber)
  36. if vorzeichen1 != "nix":
  37. #print(vorzeichen + isnumber[0])
  38. dimensions.append(vorzeichen1 + isnumber[0])
  39. else:
  40. if row[num][0]!="?":
  41. #print(isnumber[0])
  42. dimensions.append(isnumber[0])
  43. if is2vorzeichen is True:
  44. vorzeichen1 = vorzeichen2
  45. is2vorzeichen = False
  46. if row[num][0] == "?":
  47. #print("+/- " + row[1][1:])
  48. dimensions.append("+/- " + row[num][1:])
  49. #print(isos)
  50. print(dimensions)
  51. print(f'Processed {line_count} lines.')
  52. dim = []
  53. dim_count = 0
  54. for x in dimensions:
  55. if x == "Durchmesser: ":
  56. dim_count = 0
  57. if dim_count > 2:
  58. dim_count = 0
  59. if dim_count == 0:
  60. print("Maße: " + "\n" + x)
  61. dim_count += 1
  62. continue
  63. if dim_count == 1:
  64. print("Toleranzen: " + "\n" + x)
  65. dim_count += 1
  66. if "+/-" in x:
  67. dim_count += 1
  68. continue
  69. if dim_count == 2:
  70. print(x)
  71. dim_count += 1
  72. continue