Guest User

Untitled

a guest
Jul 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import re
  2. import csv
  3.  
  4. DOf = ""
  5. ROf = ""
  6. WOf = ""
  7. SOf = ""
  8. DIf = ""
  9. RIf = ""
  10. WIf = ""
  11. SIf = ""
  12.  
  13.  
  14. with open("\\\\server\\..folders..\\CSV.csv") as VBAWT:
  15. csvreader = csv.reader(VBAWT)
  16. for row in csvreader:
  17. DOf = row[0]
  18. ROf = row[1]
  19. WOf = row[2]
  20. SOf = row[3]
  21. DIf = row[4]
  22. RIf = row[5]
  23. WIf = row[6]
  24. SIf = row[7]
  25.  
  26.  
  27. DO = str(int(float(DOf) * 100)) #Excel Cell D38
  28. RO = str(int(float(ROf) * 100)) #F38
  29. WO = str(int(float(WOf) * 100)) #H38
  30. SO = str(int(float(SOf) * 100)) #J38
  31. DI = str(int(float(DIf) * 100)) #N38
  32. RI = str(int(float(RIf) * 100)) #P38
  33. WI = str(int(float(WIf) * 100)) #R38
  34. SI = str(int(float(SIf) * 100)) #T38
  35.  
  36. #print (DO + ' ' + RO + ' ' + WO + ' ' + SO + ' ' + DI + ' ' + RI + ' ' + WI + ' ' + SI)
  37. #the below lines are what we are replacing in the text file (Actually the HTML master file, so the numbers show updated)
  38. lin61 = " complete = htmlStringStart + \""+ DO +"%\" + htmlStringRet + \""+ RO +"%\" + htmlStringWhol + \""+ WO +"%\" + htmlStringShel + \""+ SO +"%\" + htmlStringEnd; \n"
  39. lin65 = " complete = htmlStringStart + \""+ DI +"%\" + htmlStringRet + \""+ RO +"%\" + htmlStringWhol + \""+ WI + "%\" + htmlStringShel + \""+ SI +"%\" + htmlStringEnd; \n"
  40.  
  41. old61 = ""
  42. old65 = ""
  43. linarr = []
  44.  
  45. #Creates an array of the file lines, then sets a variable to what the current lines 61, 65 are so we can identify them for replacing
  46. with open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "r") as fs:
  47. for line in fs:
  48. linarr.append(line)
  49. old61 = linarr[61]
  50. old65 = linarr[65]
  51.  
  52. #Now we look for those old lines, saying if it looks like the contents of the old61 variable, replace it with lin61 (and 65)
  53. fr = open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "r").read()
  54. fr = fr.replace(old61, lin61)
  55. fr = fr.replace(old65, lin65)
  56. fw = open("\\\\server\\C$\\inetpub\\wwwroot\\Folder\\file.txt", "w")
  57. fw.write(fr)
  58. fw.close()
Add Comment
Please, Sign In to add comment