Skip to content

Instantly share code, notes, and snippets.

@natalyjazzviolin
Created July 12, 2021 19:32
Show Gist options
  • Save natalyjazzviolin/595078774ab24dcd2c0af23dac1dd30e to your computer and use it in GitHub Desktop.
Save natalyjazzviolin/595078774ab24dcd2c0af23dac1dd30e to your computer and use it in GitHub Desktop.
# Identifier '--name--' is never reassigned; use 'const' instead of 'let'. #
#!env/bin/python
import pyperclip, time, re
import keyboard
import pyautogui as pug
import click
pug.PAUSE = 1
pug.FAILSAFE = True
@click.command()
def cli():
print('-----------------------------\n1. Expand VSCode file in laptop monitor.\n2. Expand left panel.\n-----------------------------\nClick CTRL + C to quit!\n-----------------------------')
print('Backspace - replace.\nEscape - skip.')
def copyText():
pug.hotkey('ctrl', 'c')
time.sleep(.01)
return pyperclip.paste()
try:
# While there are files in the list:
while True:
pug.click(374, 75) # Click into VSCode
pug.hotkey('shift', 'end') # Select 1st line: error message
instructions = copyText() # Copy line into variable
# Get all search terms
instructions = re.sub(r"'(\d+|\w\s)","",instructions)
instructions = re.findall("'.*?'",instructions)
# Separate search terms
variable = instructions[0][1:-1] # Variable name
useThis = instructions[1][1:-1] # Updated declaration
notThis = instructions[2][1:-1]# Outdate declaration
# Select file name
pug.press('down')
pug.press('home')
pug.hotkey('shift', 'end')
fileName = copyText()
# Paste filename & open
pug.click(508, 555)
pug.rightClick()
pug.press('enter')
# Find variable
pug.hotkey('ctrl', 'f')
old = notThis + ' ' + variable
new = useThis + ' ' + variable
pyperclip.copy(old)
pug.hotkey('ctrl', 'v')
pyperclip.copy(new)
pug.hotkey('alt', 'enter')
# If needed replace variable, save & close file
keyboard.read_key()
if keyboard.is_pressed('backspace') == True:
pug.hotkey('ctrl', 'v')
pug.hotkey('ctrl', 's')
time.sleep(.1)
pug.hotkey('ctrl', 'w')
if keyboard.is_pressed('esc') == True:
pug.hotkey('ctrl', 'w')
# Delete lines 1 & 2, move on to next file
pug.click(374, 75)
pug.hotkey('shift', 'end')
pug.hotkey('shift', 'down')
pug.hotkey('shift', 'end')
pug.hotkey('shift', 'right')
pug.press('delete')
# Exit program with Ctrl + C
except KeyboardInterrupt:
print('\nDone.')
if __name__ == '__main__':
cli()
from setuptools import setup
setup(
name="rename",
version='0.1.0',
py_modules=['rename'],
install_requires=[
'Click',
'pyperclip',
'keyboard',
'pyautogui',
],
entry_points={
'console_scripts': [
'rename = rename:cli'
]
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment