Advertisement
MyNamesNotReallyDave

u/aggiefury101 - adjusted

Feb 13th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. import csv
  2. import json
  3. import time
  4. import os
  5. import pandas as pd
  6. from selenium import webdriver
  7.  
  8. # Load Chrome Driver
  9. CHROMEDRIVER_PATH = 'C:/Users/rgraham_adm/Desktop/WebScraper2020/chromedriver.exe'
  10.  
  11. # ------ changes ------
  12. # Names to Be Renamed - This is referenced in the renaming loop
  13. newNames = 'C:/Users/rgraham_adm/Desktop/RedditScript/Forms/NewNames.csv'
  14.  
  15. with open(newNames, 'r') as f: # Removed quotes around newNames variable - mb
  16.     reader = csv.reader(f)
  17.     newNameList = list(reader)
  18. # ------ /changes ------
  19.  
  20. appState = {
  21.     "recentDestinations": [
  22.         {
  23.             "id": "Save as PDF",
  24.             "origin": "local",
  25.             "account": ""
  26.         }
  27.     ],
  28.     "selectedDestinationId": "Save as PDF",
  29.     "version": 2
  30. }
  31.  
  32. downloadPath = 'C:/Users/rgraham_adm/Desktop/RedditScript/Forms'
  33.  
  34. profile = {'printing.print_preview_sticky_settings.appState': json.dumps(appState),
  35.            'savefile.default_directory': downloadPath}
  36.  
  37. options = webdriver.ChromeOptions()
  38. options.add_experimental_option('prefs', profile)
  39. options.add_argument('--kiosk-printing')
  40. driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)
  41. with open('C:/Users/rgraham_adm/Desktop/RedditScript/Test.csv') as example_file:
  42.     example_reader = csv.reader(example_file)
  43.     for row in example_reader:
  44.         driver.get(row[0]), time.sleep(5), driver.execute_script('window.print();')
  45.  
  46. driver.quit()
  47.  
  48. for index, item in enumerate(os.listdir(downloadPath)):
  49.     print(f'{downloadPath}\{item}', f'{downloadPath}\{str(newNameList[index][0])}.pdf') # Adapted this code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement