PYAUTOGUI IN FOR LOOP Python - pyautogui

I am trying to do a series of steps on each file in the directory. For each file, I want to copy the name of the file and then paste it at specified coordinates on the screen. The first three lines of code in the if statement seem to get ignored and all I see happen is the cursor move to the destination. None of the file names are getting copied to the clipboard and none are pasted. Please see error picture message attached. Any advice is much appreciated.
pythonPicError
import pyautogui,os
directory = 'C:\\Users\\johna\\Desktop\\pdfs'
for filename in os.listdir(directory):
if filename.endswith('.txt'):
pyautogui.click()
pyautogui.press('f2') #select file name
pyautogui.hotkey('ctrl','c') #copy file name
pyautogui.moveTo(153,1054,duration=2)
pyautogui.click() #click on destination
pyautogui.hotkey('ctrl','v') #paste file name

Print something after each line of code, to see where exactly is the problem. But I guess
pyautogui.hotkey('ctrl','c') #copy file name
ctrl+c is just killing your script :)
Just noticed:
pyautogui.click()
You didn't provide any coords for this click, so it's clicking just after you run the program in the place where your coursor is.

I programmed coordinates and now it works.
import pyautogui,os
directory = 'C:\\Users\\johna\\Desktop\\pdfs'
x=226
y=280
for filename in os.listdir(directory):
if filename.endswith('.txt'):
pyautogui.click(x,y)
pyautogui.press('f2')
pyautogui.hotkey('ctrl','c')
y=y+30
pyautogui.moveTo(107,559,duration=2)
pyautogui.click()
pyautogui.hotkey('ctrl','v')

Related

EOFError: Ran out of input with pickle while the file is not empty

This is a part of my code where I open the file and face this error while the file is not empty. Because I opened it and wrote it hundreds of time during my code and it didn't have this problem. The file size on my disk is 25MB so it's not definitely empty. Here is were I open it:
file_to_read = open("attribute.pickle", "rb")
unpickler = pickle.Unpickler(file_to_read);
attribute = unpickler.load()
file_to_read.close()
The attribute file is updated (appended) during the code and here is where I save it to the file:
geeky_file = open("attribute.pickle", 'wb')
pickle.dump(attribute, geeky_file)
geeky_file.close()
So this openning, appending, and saving has been done in loop hundreds of time without any problem. Now that I wanted to rerun the code, it faced the "EOFError: Ran out of input" error when loading at
attribute = unpickler.load()
I tried reading the post for the same error but all answers say the file might be empty while mine definitely isn't.

File not found when appending a csv file

Stata version: 12.1
I get an error "file not found" using this code:
cd "$path_in"
insheet using "df_mcd_clean.csv", comma clear
append using "df_mcd15_clean.csv" #where error happens
append using "df_ingram_liu1998_clean.csv"
append using "df_wccd_clean.csv"
I double checked that the file is indeed called that and located in the directory.
append is for appending .dta files. Therefore, if you ask to append foo.csv Stata assumes you are referring to foo.csv.dta, which it can't find.
The solutions include
Combine the .csv files outside Stata.
Read in each .csv file, save as .dta, then append.
The current version of the help for append says this:
append appends Stata-format datasets stored on disk to the end of the dataset in memory. If any filename is
specified without an extension, .dta is assumed.
and that was true too in Stata 12. (Whether the wording was identical, you can say.)

Merge csv in another folder location

I'm trying to merge csv files into one text file using a batch file.
My batch file is located in C:\Users\aallen and the CSV files are located in C:\Users\aallen\Test
The batch file will only work when its located in the same location as the csv.
I have tried the following commands with no joy:
1) cd "C:\Users\aallen\Test" copy *csv test.csv
2) copy "C:\Users\aallen\Test" *csv test.csv
What I'm I missing?
Collecting the information from Question and Comments, you want to combine several CSV files into one, but only keep the headerline once.
more +1 is able to show a file, skipping first lines (see more /?), but more +1 *.csv does only skip the first line of the first file and keeps it at all other files (just the opposite of what you need). So you have to process one file after the other with a for loop and check for first file yourself (can be done with a flag-variable (flag here). Redirect the whole loop to your resultfile.
#echo off
set "first=yes"
(for %%a in ("C:\Users\aallen\Test\*.csv") do (
if defined first (
type "%%a"
set "first="
) else (
more +1 "%%a"
)
))>"d:\new location\test.csv"
Note: more at command line prints just one screen and then pauses until you press a key. But when you use it in a batchfile, it doesn't (well, to be honest, it does, but after ~65000 lines. I hope, your files are shorter)

Stata doesn't save output file

I'm having difficulties to save the output of my regression. Stata is supposed to save the file as "output.dta" in the defined directory, however the file is not saved in this folder (and also nowhere else on my PC). Here is the final piece of code, where I want it to be saved:
if (`counter'==1) {
save "C:\Users\Milla\Code\output", replace
local counter = `counter' + 1
}
if (`counter'!=1) {
cap append using "C:\Users\Milla\Code\output"
duplicates drop *, force
cap save "C:\Users\Milla\Code\output", replace
}
Does anyone have an idea why could this happen? The code runs well and throws no errors or warnings. But it also doesn't say "output.dta is saved" as it normally does, when one saves anything in Stata.
Thanks ahead and best regards,
Milla
try
save "C:\Users\Milla\Code\output.dta", r

Can't import csv to neo4j

My code:
LOAD CSV FROM "C:\Users\Elmar\Desktop\tmp-raise.csv" AS line
WITH line
RETURN line
The error that it gives:
Invalid input ':': expected 'o/O' (line 1, column 18 (offset: 17))
"LOAD CSV FROM "C:\Users\Elmar\Desktop\tmp-raise.csv" AS line"
^
I have also tried:
USING PERIODIC COMMIT 10000
LOAD CSV FROM ""C:\Users\Elmar\Desktop\tmp-raise.csv" AS line
WITH line
RETURN line
What is the problem? Can anyone help me?
According to the CSV import guide, your path should be prefixed with file: and should use forward slashes. The example path given in the guide for windows is file:c:/path/to/data.csv (though I have seen example paths starting with file://). Give this a try:
USING PERIODIC COMMIT 10000
LOAD CSV FROM 'file:c:/Users/Elmar/Desktop/tmp-raise.csv' AS line
WITH line
RETURN line
If that doesn't work, give it a try with file:// as the path prefix.
EDIT: Looks like CSV loads use a relative path from the default.graphdb/import folder. I had thought that was for Mac/Unix only, but it looks like Windows does the same. If you move CSVs you want to import into the import folder, you should be able to load them using file:///theFileName.csv
Load csv from "file:///C:/xyz.csv" as line
return line
The above code works well. But do comment out the configuration
dbms.directories.import=import
in the settings.
Other solution is you can drop a (.txt, .cyp, .cql) file in the drag to import box.