├── .gitignore ├── README.md ├── actions-sample.json ├── actions.py ├── actions.reg ├── app.ico ├── config.ini ├── index.html └── samples ├── cdftv-cac.prproj ├── cdftv-decode-cdf-2030.prproj ├── cdftv-dicionario-do-programador.prproj ├── cdftv-instagram-devminute.prproj ├── cdftv-instagram-stories.prproj ├── cdftv-mao-no-codigo.prproj ├── cdftv-vlog.prproj ├── miniatura.psd └── texto-animado.psd /.gitignore: -------------------------------------------------------------------------------- 1 | settings.json 2 | .vscode 3 | __pycache__ 4 | build 5 | dist 6 | *.spec -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Automated Actions 2 | 3 | This project is a simple script that creates folder and download files from internet according to a JSON file. 4 | 5 | The main goal is simplify the creation of projects for: video makers, developers, designers, photographers or any kind of professional that need automated some things. 6 | 7 | The most simple project creation ever! :p 8 | 9 | ## Getting Started 10 | 11 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. 12 | 13 | ### Prerequisites 14 | 15 | What things you need to install the software and how to install them. 16 | 17 | ``` 18 | Python 3.x 19 | ``` 20 | 21 | ### Installing 22 | 23 | A step by step series of examples that tell you how to get a development env running 24 | 25 | Install Python 3.x with pip 26 | 27 | Install Path Validate, a Python Library for file validation. 28 | 29 | ``` 30 | pip install pathvalidate 31 | ``` 32 | 33 | Install PyInstaller, to generate .exe file (for Windows). 34 | 35 | ``` 36 | pip install pyinstaller 37 | ``` 38 | 39 | Run a Live Server or any http service or port 5500. This is optional, you can also customize the *actions-sample.json* and *config.ini* with your own URLs. 40 | 41 | ## Running the tests 42 | 43 | ### Linux, Mac OS X, BSD and most OSes except Windows 44 | Turn script executable: 45 | 46 | ``` 47 | chmod +x actions.py 48 | ``` 49 | 50 | Call script inside a folder with photos: 51 | 52 | ``` 53 | ./actions.py . 54 | ``` 55 | 56 | ### Windows 57 | 58 | To run a test, call the script inside a folder with photos. 59 | 60 | ``` 61 | python actions.py . 62 | ``` 63 | 64 | **For Windows in Context Menu:** 65 | 66 | 1. To generate *actions.exe* file to run on Windows. 67 | 68 | ``` 69 | pyinstaller -c -F ----icon=app.ico actions.py 70 | ``` 71 | 72 | 2. Add the keys on Registry or run *actions.reg*. 73 | 3. Copy .exe file on *C:\Program Files\CDFTV Actions* 74 | 4. Add *C:\Program Files\CDFTV Actions* in the *Path* on Windows Environment Variable. 75 | 76 | ## Contributing 77 | 78 | Feel free to submitting pull requests to us. 79 | 80 | ## Authors 81 | 82 | * **Gabriel Froes** - *Initial work* - [Twitter](https://www.twitter.com/gabrielfroes) 83 | * **Vanessa Weber** - *Initial work* - [Twitter](https://www.twitter.com/nessaweberfroes) 84 | 85 | ## License 86 | 87 | This project is licensed under the [GNU General Public License](https://opensource.org/licenses/GPL-3.0). 88 | 89 | ## Acknowledgments 90 | 91 | * First steps in Python language 92 | * Create simple and useful things 93 | * Produce a [video lesson](https://youtu.be/eosclmulqqo) coding this little project 94 | * Build code for [Código Fonte TV](https://www.youtube.com/codigofontetv), our Youtube Channel. 95 | -------------------------------------------------------------------------------- /actions-sample.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "type": "Mão no Código", 3 | "actions": { 4 | "folders": [ 5 | "video", 6 | "audio", 7 | "imagens/fotos" 8 | ], 9 | "files": [{ 10 | "from": "http://127.0.0.1:5500/samples/cdftv-mao-no-codigo.prproj", 11 | "to": "" 12 | }, 13 | { 14 | "from": "http://127.0.0.1:5500/samples/miniatura.psd", 15 | "to": "imagens" 16 | }, 17 | { 18 | "from": "http://127.0.0.1:5500/samples/texto-animado.psd", 19 | "to": "imagens" 20 | } 21 | 22 | ] 23 | } 24 | }, 25 | { 26 | "type": "Vlog", 27 | "actions": { 28 | "folders": [ 29 | "video", 30 | "audio", 31 | "imagens/fotos" 32 | ], 33 | "files": [{ 34 | "from": "http://127.0.0.1:5500/samples/cdftv-vlog.prproj", 35 | "to": "" 36 | }, 37 | { 38 | "from": "http://127.0.0.1:5500/samples/miniatura.psd", 39 | "to": "imagens" 40 | } 41 | ] 42 | } 43 | }, 44 | { 45 | "type": "CAC", 46 | "actions": { 47 | "folders": [ 48 | "video", 49 | "audio", 50 | "imagens/fotos" 51 | ], 52 | "files": [{ 53 | "from": "http://127.0.0.1:5500/samples/cdftv-cac.prproj", 54 | "to": "" 55 | }, 56 | { 57 | "from": "http://127.0.0.1:5500/samples/miniatura.psd", 58 | "to": "imagens" 59 | } 60 | ] 61 | } 62 | }, 63 | { 64 | "type": "Dicionário do Programador", 65 | "actions": { 66 | "folders": [ 67 | "video", 68 | "audio", 69 | "imagens/fotos" 70 | ], 71 | "files": [{ 72 | "from": "http://127.0.0.1:5500/samples/cdftv-dicionario-do-programador.prproj", 73 | "to": "" 74 | }, 75 | { 76 | "from": "http://127.0.0.1:5500/samples/miniatura.psd", 77 | "to": "imagens" 78 | } 79 | ] 80 | } 81 | }, 82 | { 83 | "type": "Decode CDF 2030", 84 | "actions": { 85 | "folders": [ 86 | "video", 87 | "audio", 88 | "imagens/fotos" 89 | ], 90 | "files": [{ 91 | "from": "http://127.0.0.1:5500/samples/cdftv-decode-cdf-2030.prproj", 92 | "to": "" 93 | }, 94 | { 95 | "from": "http://127.0.0.1:5500/samples/miniatura.psd", 96 | "to": "imagens" 97 | } 98 | ] 99 | } 100 | }, 101 | { 102 | "type": "DevMinute (Instagram)", 103 | "actions": { 104 | "folders": [ 105 | "video", 106 | "audio" 107 | ], 108 | "files": [{ 109 | "from": "http://127.0.0.1:5500/samples/cdftv-instagram-devminute.prproj", 110 | "to": "" 111 | }] 112 | } 113 | }, 114 | { 115 | "type": "Stories (Instagram)", 116 | "actions": { 117 | "folders": [ 118 | "video", 119 | "audio" 120 | ], 121 | "files": [{ 122 | "from": "http://127.0.0.1:5500/samples/cdftv-instagram-stories.prproj", 123 | "to": "" 124 | }] 125 | } 126 | } 127 | ] -------------------------------------------------------------------------------- /actions.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import json 4 | import urllib.request 5 | from pathvalidate import sanitize_filename 6 | import configparser 7 | import ssl 8 | 9 | ssl._create_default_https_context = ssl._create_unverified_context 10 | 11 | class Actions: 12 | 13 | def __init__(self, path=''): 14 | path_config_file = self.__getIniPath('config.ini') 15 | config = configparser.ConfigParser() 16 | config.read(path_config_file) 17 | config_link = config['DEFAULT']['config_link'] 18 | 19 | self.path = path 20 | self.config = self.__loadConfig(config_link) 21 | self.actions = self.__loadActions(self.config) 22 | 23 | def __loadConfig(self, link): 24 | with urllib.request.urlopen(link) as url: 25 | data = json.loads(url.read().decode()) 26 | return data 27 | 28 | def __loadActions(self, config): 29 | return [item['type'] for item in config] 30 | 31 | def __getIniPath(self, filename): 32 | return filename if os.path.isfile(filename) else os.path.join(os.path.dirname(sys.executable), filename) 33 | 34 | def __createFoldersFromList(self, folders, baseFolder=''): 35 | baseFolder = sanitize_filename(baseFolder) 36 | 37 | for folder in folders: 38 | folderName = os.path.join(self.path, baseFolder, folder) 39 | os.makedirs(folderName, True) 40 | 41 | def __downloadFilesFromList(self, files, baseFolder=''): 42 | baseFolder = sanitize_filename(baseFolder) 43 | for file in files: 44 | link = file["from"] 45 | destination = file["to"] 46 | fileName = link.rsplit("/", 1)[-1] 47 | fullPathFile = os.path.join( 48 | self.path, baseFolder, destination, fileName) 49 | 50 | if not os.path.isfile(fullPathFile): 51 | print(f'BAIXANDO.... {link}') 52 | urllib.request.urlretrieve(link, fullPathFile) 53 | 54 | def doActions(self, actionType, folderName): 55 | [actions] = [item['actions'] 56 | for item in self.config if (item['type'] == actionType)] 57 | 58 | self.__createFoldersFromList(actions['folders'], folderName) 59 | self.__downloadFilesFromList(actions['files'], folderName) 60 | 61 | 62 | def initApp(myActions): 63 | # INTERFACE VIA TERMINAL 64 | print("============================================") 65 | print(" ESCOLHA UMA OPÇÃO: ") 66 | print("============================================") 67 | optionNumber = 0 68 | for action in myActions.actions: 69 | optionNumber += 1 70 | print(f" {optionNumber} - {action}") 71 | optionSelected = int(input("> ")) 72 | 73 | print("============================================") 74 | print(" NOME DA PASTA: ") 75 | print("============================================") 76 | folderName = input("> ") 77 | 78 | print("============================================") 79 | print(" CONFIRMA? (s/n) ") 80 | print(f": {myActions.actions[optionSelected-1]}") 81 | print(f": {folderName}") 82 | print("============================================") 83 | confirm = (input("> ")) 84 | # ./INTERFACE VIA TERMINAL 85 | 86 | if confirm == "s": 87 | myActions.doActions(myActions.actions[optionSelected-1], folderName) 88 | 89 | input(": Pressione ENTER para Terminar... ") 90 | 91 | 92 | path = '.' if sys.argv else sys.argv[1] 93 | action = Actions(path) 94 | initApp(action) 95 | -------------------------------------------------------------------------------- /actions.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/actions.reg -------------------------------------------------------------------------------- /app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/app.ico -------------------------------------------------------------------------------- /config.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | config_link=http://127.0.0.1:5500/actions-sample.json -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/index.html -------------------------------------------------------------------------------- /samples/cdftv-cac.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-cac.prproj -------------------------------------------------------------------------------- /samples/cdftv-decode-cdf-2030.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-decode-cdf-2030.prproj -------------------------------------------------------------------------------- /samples/cdftv-dicionario-do-programador.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-dicionario-do-programador.prproj -------------------------------------------------------------------------------- /samples/cdftv-instagram-devminute.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-instagram-devminute.prproj -------------------------------------------------------------------------------- /samples/cdftv-instagram-stories.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-instagram-stories.prproj -------------------------------------------------------------------------------- /samples/cdftv-mao-no-codigo.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-mao-no-codigo.prproj -------------------------------------------------------------------------------- /samples/cdftv-vlog.prproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/cdftv-vlog.prproj -------------------------------------------------------------------------------- /samples/miniatura.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/miniatura.psd -------------------------------------------------------------------------------- /samples/texto-animado.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrielfroes/python-automated-actions/b04ed8a90a07f3517711b5e2149180bd6b705f3f/samples/texto-animado.psd --------------------------------------------------------------------------------