0

I'm sorry if there was such a topic but I could not find an answer. So, let's start: someone created such a code for me, but unfortunately he did not tell me how to run it and the mess itself and not write back. I tried to solve the problem myself but unfortunately my knowledge is not yet at this level. Well, when I try to fire the code in VSC I see such a mistake

c:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts>main.py
dane.xlsx
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts\main.py",line 21, in <module>
if __name__ == "__main__": main()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts\main.py", line 8, in main
xl = pd.ExcelFile(input("dane.xlsx"))
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\excel.py", line 394, in __init__
self.book = xlrd.open_workbook(self._io)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlrd\__init__.py", line 116, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory:

Here I give the code of 2 files, maybe there is a mistake in them: main.py

from wp import wp
import time
import pandas as pd
from selenium import webdriver

def main():
chromedriver = "chromedriver.exe"
xl = pd.ExcelFile(input("C:\Praca\dane.xlsx"))

# Print the sheet names
driver = webdriver.Chrome(executable_path=chromedriver)

# Load a sheet into a DataFrame by name: df1
df1 = xl.parse('Sheet1')
for data in df1.index:
    _wp = wp(driver,df1['Strona'][data])
    _wp._login()
    _wp._send_data(df1['Tytul'][data],df1['Tresc'][data],df1['Data'][data],df1['Logo'][data],df1['Medium'][data],df1['Link'][data],df1['LinkA'][data])


if __name__ == "__main__": main()

wp.py

from datetime import datetime
import time


def get_time():
return str(datetime.now().strftime('[%H:%M:%S] '))




class wp():

def __init__(self,driver,base_url):
    self.base_url = base_url
    self.login = "xxx"
    self.password = "xxx"
    self.driver = driver

def _login(self):
    self.driver.get(self.base_url+"/wp-login.php")

    self.driver.find_element_by_id("user_login").send_keys(self.login)
    self.driver.find_element_by_id("user_pass").send_keys(self.password)

    self.driver.find_element_by_id("wp-submit").click()


def _send_data(self,title,content,date,logo,medium,link,linka):
    self.driver.get(self.base_url+"/wp-admin/post-new.php")
    self.driver.find_element_by_id("title").send_keys(title)
    self.driver.find_element_by_id("content").send_keys(content)

    self.driver.execute_script("document.getElementsByClassName('edit-timestamp hide-if-no-js')[0].click();")

    date = date.split(".")
    if date[1][0:1] == "0": date[1] = date[1][1:2]

    self.driver.find_element_by_id("jj").send_keys(date[0])
    self.driver.find_element_by_xpath('//*[@id="mm"]/option['+date[1]+']').click()
    self.driver.find_element_by_id("aa").send_keys(date[2])


    self.driver.execute_script("document.getElementsByClassName('save-timestamp hide-if-no-js button')[0].click();")
    self.driver.execute_script("document.getElementById('set-post-thumbnail').click();")

    self.driver.execute_script("document.getElementById('media-search-input').value='"+medium+"';")

    time.sleep(1)

    self.driver.execute_script("document.getElementsByClassName('thumbnail')[0].click();")

    self.driver.execute_script("document.getElementsByClassName('button media-button button-primary button-large media-button-select')[0].click();")





    self.driver.execute_script("document.getElementById('insert-media-button').click();")


    self.driver.execute_script("document.getElementsByClassName('search')[1].value='"+logo+"';")

    time.sleep(1)

    self.driver.execute_script("document.getElementsByClassName('attachments ui-sortable ui-sortable-disabled')[1].getElementsByClassName('thumbnail')[0].click();")
    time.sleep(1)

    self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('input')[1].value='"+link+"';")
    self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('input')[2].value='"+link+"';")
    self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('textarea')[1].value='"+link+"';")

    self.driver.execute_script("document.getElementsByClassName('attachment-display-settings')[0].getElementsByTagName('input')[0].value='"+linka+"';")
    time.sleep(1)

    self.driver.execute_script("document.getElementsByClassName('button media-button button-primary button-large media-button-insert')[0].click();")

    self.driver.execute_script("document.getElementById('publish').click();")
    time.sleep(1)

I apologize in advance for ambiguity and thank you for your help

2
  • 1
    You aren't going to learn to program by having others write code for you and then trying to understand it. That being said, you have indentation errors all throughout your code. Commented Jun 15, 2018 at 15:40
  • Error message complains about xl = pd.ExcelFile(input("C:\Praca\dane.xlsx")) and states that there is no such file. Commented Jun 15, 2018 at 15:42

2 Answers 2

3

Since you are probably attempting to hardcode your filepath and not ask for user input (input()), you should probably replace

xl = pd.ExcelFile(input("C:\Praca\dane.xlsx"))

with

xl = pd.ExcelFile(r"C:\Praca\dane.xlsx")
Sign up to request clarification or add additional context in comments.

Comments

0

The file your script is looking for doesn't exist. In your example, you executed main.py from the directory "c:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts". So, "dane.xlsx" does not exist in the directory "c:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts". You can either move it there or enter the full path to dane.xlsx, not just the filename.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.