Guest User

Untitled

a guest
Nov 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. from automagica import *
  2. import csv
  3.  
  4. # Business Objects
  5.  
  6.  
  7. def AttachToNotepad():
  8. isRunning = ProcessRunning(name="notepad")
  9. if not isRunning:
  10. notepad = OpenNotepad()
  11. else:
  12. DeleteContentsOnNotepad()
  13. isRunning = ProcessRunning(name="notepad")
  14.  
  15. return isRunning
  16.  
  17.  
  18. def DeleteContentsOnNotepad():
  19. ClickOnPosition(540, 400)
  20. PressHotkey("ctrl", "a")
  21. Backspace()
  22.  
  23.  
  24. def GetCSVRows(path):
  25. with open(path) as csv_file:
  26. csv_reader = csv.reader(csv_file)
  27. columns, *rows = [row for row in csv_reader]
  28. return [columns, rows]
  29.  
  30.  
  31. def TypeInNotepad(*data):
  32. if AttachToNotepad():
  33. WriteCSVDataInNotepad(*data)
  34.  
  35.  
  36. def WriteCSVDataInNotepad(columns, rows):
  37. for column in columns:
  38. Type(f"{column} | ")
  39. Enter()
  40. for cell in rows:
  41. Enter()
  42. for value in map(lambda c: f"{c} | ", cell):
  43. Type(value)
  44.  
  45.  
  46. def CloseNotepad():
  47. while(ProcessRunning(name="notepad")):
  48. ClickOnPosition(*closePos)
  49. ClickOnPosition(*dontSavePos)
  50.  
  51.  
  52. def ScreenShot(name="screenshot.jpg"):
  53. image = PIL.ImageGrab.grab()
  54. image.save(name)
  55. return name
  56.  
  57. # Variables
  58.  
  59.  
  60. path = ""
  61. if(len(sys.argv) > 1):
  62. path = sys.argv[1]
  63. path = rf"{path}" or r"C:\Users\ralph.eclipse\Documents\BluePrism RPA Training\02 - Foundation Course\Orders.csv"
  64. print(path)
  65. closePos = [1140, 189]
  66. dontSavePos = [684, 400]
  67.  
  68. # Process
  69.  
  70. data = GetCSVRows(path)
  71. TypeInNotepad(*data)
  72. imagePath = ScreenShot()
  73. OpenImage(imagePath)
  74. CloseNotepad()
Add Comment
Please, Sign In to add comment