Added archetypes, Added New Post
This commit is contained in:
parent
35cf51675c
commit
8a7d97f4be
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: about
|
||||
---
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
type: archive
|
||||
description:
|
||||
titleWrap: wrap # wrap, noWrap
|
||||
---
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
author:
|
||||
authorEmoji: 🤖
|
||||
authorImage: "/images/whoami/avatar.jpg"
|
||||
authorImageUrl: ""
|
||||
authorDesc:
|
||||
socialOptions:
|
||||
email: ""
|
||||
phone: ""
|
||||
facebook: ""
|
||||
twitter: ""
|
||||
github: ""
|
||||
stack-overflow: ""
|
||||
instagram: ""
|
||||
google-plus: ""
|
||||
youtube: ""
|
||||
medium: ""
|
||||
tumblr: ""
|
||||
linkedin: ""
|
||||
pinterest: ""
|
||||
stack-exchange: ""
|
||||
telegram: ""
|
||||
steam: ""
|
||||
weibo: ""
|
||||
douban: ""
|
||||
csdn: ""
|
||||
gitlab: ""
|
||||
mastodon: ""
|
||||
jianshu: ""
|
||||
zhihu: ""
|
||||
signal: ""
|
||||
whatsapp: ""
|
||||
matrix: ""
|
||||
xmpp: ""
|
||||
dev-to: ""
|
||||
gitea: ""
|
||||
google-scholar: ""
|
||||
twitch: ""
|
||||
---
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: contact
|
||||
service: formspree # formspree, getform
|
||||
formId: ""
|
||||
getformToken: ""
|
||||
---
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
author: "Devoalda"
|
||||
authorEmoji: 🐺
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
draft: false
|
||||
hideToc: false
|
||||
enableToc: true
|
||||
enableTocContent: true
|
||||
tocPosition: inner
|
||||
tocLevels: ["h2", "h3", "h4"]
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
image:
|
||||
---
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: gallery
|
||||
mode: at-once # at-once or one-by-one
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
images: # when mode is one-by-one, images front matter works
|
||||
- image:
|
||||
caption:
|
||||
---
|
|
@ -0,0 +1,88 @@
|
|||
---
|
||||
header:
|
||||
- type: text
|
||||
height: 235
|
||||
paddingX: 50
|
||||
paddingY: 0
|
||||
align: left
|
||||
title:
|
||||
- header title1
|
||||
- header title2
|
||||
subtitle:
|
||||
- header subtitle1
|
||||
- header subtitle2
|
||||
titleColor:
|
||||
titleShadow: false
|
||||
titleFontSize: 44
|
||||
subtitleColor:
|
||||
subtitleCursive: false
|
||||
subtitleFontSize: 16
|
||||
spaceBetweenTitleSubtitle: 20
|
||||
|
||||
- type: img
|
||||
image: images/header/background.png
|
||||
height: 235
|
||||
paddingX: 50
|
||||
paddingY: 0
|
||||
align: center
|
||||
title:
|
||||
- header title1
|
||||
- header title2
|
||||
subtitle:
|
||||
- header subtitle1
|
||||
- header subtitle2
|
||||
titleColor:
|
||||
titleShadow: false
|
||||
titleFontSize: 44
|
||||
subtitleColor:
|
||||
subtitleCursive: false
|
||||
subtitleFontSize: 16
|
||||
spaceBetweenTitleSubtitle: 20
|
||||
|
||||
- type: slide
|
||||
height: 235
|
||||
options:
|
||||
startSlide: 0
|
||||
auto: 5000
|
||||
draggable: true
|
||||
autoRestart: true
|
||||
continuous: true
|
||||
disableScroll: true
|
||||
stopPropagation: true
|
||||
slide:
|
||||
- paddingX: 50
|
||||
paddingY: 0
|
||||
align: left
|
||||
image: images/header/background.png
|
||||
title:
|
||||
- header title1
|
||||
subtitle:
|
||||
- header subtitle1
|
||||
titleFontSize: 44
|
||||
subtitleFontSize: 16
|
||||
spaceBetweenTitleSubtitle: 20
|
||||
|
||||
- paddingX: 50
|
||||
paddingY: 0
|
||||
align: center
|
||||
image: images/header/background.png
|
||||
title:
|
||||
- header title2
|
||||
subtitle:
|
||||
- header subtitle2
|
||||
titleFontSize: 44
|
||||
subtitleFontSize: 16
|
||||
spaceBetweenTitleSubtitle: 20
|
||||
|
||||
- paddingX: 50
|
||||
paddingY: 0
|
||||
align: right
|
||||
image: images/header/background.png
|
||||
title:
|
||||
- header title3
|
||||
subtitle:
|
||||
- header subtitle3
|
||||
titleFontSize: 44
|
||||
subtitleFontSize: 16
|
||||
spaceBetweenTitleSubtitle: 20
|
||||
---
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: presentation
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
plugins:
|
||||
- highlight
|
||||
- zoom
|
||||
- notes
|
||||
- math
|
||||
highlightTheme: monokai # monokai, zenburn
|
||||
revealTheme: beige # beige, black, blood, league, monokai, moon, night, serif, simple, sky, solarized, white
|
||||
revealBackgroundColor: "" # #fff or rgba() or hsl()
|
||||
revealBackgroundImage: "" # /images/myImage.png <= static folder path
|
||||
revealBackgroundPosition: "" # left top, left center, left bottom, right top, right center ...
|
||||
revealBackgroundRepeat: "" # repeat, repeat-x, repeat-y, no-repeat, inherit
|
||||
revealBackgroundOpacity: "" # 0~1
|
||||
revealBackgroundVideo: "" # /videos/myVideo.mp4 <= static folder path, A single video source, or a comma separated list of video sources.
|
||||
revealBackgroundVideoLoop: false # true, false
|
||||
revealBackgroundVideoMuted: false # true, false
|
||||
revealBackgroundSize: "" # cover, contain, ...
|
||||
reveal:
|
||||
- main:
|
||||
- sub:
|
||||
- |
|
||||
|
||||
- sub:
|
||||
- |
|
||||
|
||||
- main:
|
||||
- sub:
|
||||
- |
|
||||
|
||||
---
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
shorttitle:
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: publication
|
||||
authors: []
|
||||
publication:
|
||||
abstract:
|
||||
links:
|
||||
- name:
|
||||
link:
|
||||
ENTRYTYPE: "misc"
|
||||
enableToc: false
|
||||
enableWhoami: true
|
||||
pinned: false
|
||||
publishDate: {{ dateFormat "2006-01-02" .Date }}
|
||||
---
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
type: resume
|
||||
enableToc: false
|
||||
header:
|
||||
image:
|
||||
src:
|
||||
height:
|
||||
alt:
|
||||
infos:
|
||||
name:
|
||||
email:
|
||||
phone:
|
||||
website:
|
||||
addr:
|
||||
items:
|
||||
- title:
|
||||
sections:
|
||||
- title:
|
||||
subtitle:
|
||||
startDate:
|
||||
endDateText:
|
||||
endDate:
|
||||
contents: |
|
||||
|
||||
- title:
|
||||
sections:
|
||||
- title:
|
||||
subtitle:
|
||||
startDate:
|
||||
endDateText:
|
||||
endDate:
|
||||
contents: |
|
||||
---
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
libraries:
|
||||
- katex
|
||||
- mathjax
|
||||
- chart
|
||||
- flowchartjs
|
||||
- msc
|
||||
- katex
|
||||
- mermaid
|
||||
- viz
|
||||
- wavedrom
|
||||
---
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
description:
|
||||
link:
|
||||
repo:
|
||||
pinned: true
|
||||
thumb:
|
||||
weight:
|
||||
links:
|
||||
- name:
|
||||
icon:
|
||||
link:
|
||||
shields:
|
||||
- name:
|
||||
image:
|
||||
link:
|
||||
---
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: "{{ replace .Name "-" " " | title }}"
|
||||
date: {{ .Date }}
|
||||
publishDate: {{ .Date }}
|
||||
description:
|
||||
tags:
|
||||
-
|
||||
series:
|
||||
-
|
||||
categories:
|
||||
-
|
||||
titleWrap: wrap # wrap, noWrap
|
||||
---
|
|
@ -0,0 +1,218 @@
|
|||
---
|
||||
author: "Devoalda"
|
||||
authorEmoji: 🐺
|
||||
title: "Directory Cleanup"
|
||||
date: 2020-07-06T11:07:16+08:00
|
||||
description: Directory Cleanup with python
|
||||
draft: false
|
||||
hideToc: false
|
||||
enableToc: true
|
||||
enableTocContent: true
|
||||
tocPosition: inner
|
||||
tocLevels: ["h2", "h3", "h4"]
|
||||
tags:
|
||||
- python
|
||||
- automation
|
||||
- script
|
||||
series:
|
||||
- Python
|
||||
categories:
|
||||
- python
|
||||
- script
|
||||
image: images/postImages/Broom.png
|
||||
---
|
||||
|
||||
## Introduction
|
||||
This is a script to automate cleanups in any directory. It will move files into folders according to the file extension.
|
||||
|
||||
### Why?
|
||||
A clean home/project directory allows us to be able to work productively, without spending much time searching for the particular document/file we need.
|
||||
|
||||
This is a simple script to help you clean your directory in seconds
|
||||
|
||||
### Caution
|
||||
__DO NOT__ run the script on any directory containing system/important files.
|
||||
|
||||
## Dependencies
|
||||
* [Python3.8](https://www.python.org/)
|
||||
|
||||
## Code
|
||||
|
||||
### Imports
|
||||
This is a python script, we will be using modules [os](https://docs.python.org/3/library/shutil.html) and [shutil](https://docs.python.org/3/library/shutil.html). First of all, create a new script called script.py, and import the modules required for this
|
||||
```python
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import shutil
|
||||
```
|
||||
Notice the first line ___#!/usr/bin/env python___. This is called a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). It allows us to run the script as an executable, with the command
|
||||
```bash
|
||||
./script.py
|
||||
```
|
||||
Without the shebang, we will need to use the full command
|
||||
```bash
|
||||
python3 script.py
|
||||
```
|
||||
### Defining Main
|
||||
This step is __optional__, although it will make the code look cleaner
|
||||
```python
|
||||
def main():
|
||||
print('Hello, World!')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
This is how I usually start my code, you will be able to run your code now with the command
|
||||
```bash
|
||||
./script.py
|
||||
# Output: Hello,World!
|
||||
```
|
||||
|
||||
### Defining a dictionary
|
||||
A dictionary has a key, value pair, similar to a JSON file structure. In this script, we will create a dictionary of File type(Key) and File Extensions (Value).
|
||||
|
||||
Insert the following ___above___ the line ```def main():```
|
||||
```python
|
||||
DIRECTORIES_DICTIONARY = {
|
||||
'Document': ['.doc','.docx','.pdf','.log','.txt','.rtf','.asp','.aspx','.csv','.html','.css','.js','.xml','.xls'],
|
||||
'Folder': [],
|
||||
'Audio' : ['.aif','.m3u','mp3','flac','.mpa','.wav','.m4a'],
|
||||
'Video' : ['.mp4','.flv','.mov','.vob'],
|
||||
'Image' : ['.jpg','.jpeg','.png'],
|
||||
'Zip' : ['.zip', '.7z', '.tar.gz', '.deb', '.rpm'],
|
||||
'Executables': ['.apk','.exe','.jar'],
|
||||
'Others': []
|
||||
}
|
||||
```
|
||||
You are able to expand this dictionary by adding your own file types and file extensions in a similar structure.
|
||||
|
||||
### Creating folders based on directory key
|
||||
In ```def main():```, add the following lines
|
||||
```python
|
||||
DIRECTORIES= []
|
||||
|
||||
for dir in DIRECTORIES_DICTIONARY:
|
||||
if not os.path.isdir(dir):
|
||||
print("Creating Directory '{}'".format(dir))
|
||||
os.mkdir(dir)
|
||||
DIRECTORIES.append(dir)
|
||||
```
|
||||
_Note_ the indentation of the lines!
|
||||
|
||||
When you run the script, you will see new folders being created in your directory
|
||||
### Moving file to correct directories
|
||||
Append the following lines to your main function
|
||||
```python
|
||||
file_moved_counter = 0
|
||||
file_list = os.listdir('.')
|
||||
|
||||
for file in file_list:
|
||||
if 'directory_cleanup' not in file and file not in DIRECTORIES:
|
||||
# Check if file is a folder first
|
||||
if os.path.isdir(file):
|
||||
shutil.move(file, './Folder/{}'.format(file))
|
||||
file_moved_counter += 1
|
||||
else:
|
||||
print('Current File: ' + file + '\n')
|
||||
filename, file_extension = os.path.splitext(file)
|
||||
for dir in DIRECTORIES_DICTIONARY:
|
||||
if file_extension in DIRECTORIES_DICTIONARY[dir]:
|
||||
os.rename(file, './'+dir+'/'+ file)
|
||||
print('MOVED FILE: ' + file + '\n')
|
||||
file_moved_counter += 1
|
||||
|
||||
#Moving files with unknown file extensions to Others folder
|
||||
new_file_list = os.listdir('.')
|
||||
for file in new_file_list:
|
||||
if 'directory_cleanup' not in file and file not in DIRECTORIES:
|
||||
os.rename(file, './Others/'+ file)
|
||||
file_moved_counter += 1
|
||||
|
||||
print('Files Organized!\nTotal file moved: ' + str(file_moved_counter))
|
||||
```
|
||||
These lines will move files to their folder based on their file extensions, and move undefined extensions to the 'Others' directory.
|
||||
|
||||
In this script, I've used both modules os and shutil to move files to show the difference in syntax for each of the modules.
|
||||
|
||||
### Running the script
|
||||
```bash
|
||||
./script.py
|
||||
```
|
||||
To test the script, you should add/create files with any extensions in the same directory as your script. Upon running the script, you should see all your files moved and categorized according to their file extensions.
|
||||
|
||||
## Tips
|
||||
* I usually create a project folder for any scripts that I create, and run the script in the folder. This prevents any unwanted modifications to any directory.
|
||||
* Note that indentations in a python script is very __important__.
|
||||
* This script is useful in certain directories, like Documents or Downloads, as it categorizes those files accordingly and cleans the directory.
|
||||
## Summary
|
||||
Thats it! You have yourself a cleanup script that you can use to clean any directory you want! The full code is below, do take a look if you are facing any problems!
|
||||
|
||||
### Full Code
|
||||
{{< expand "Python Code" >}}
|
||||
``` python
|
||||
#!/usr/bin/env python
|
||||
|
||||
#Done By: Devoalda
|
||||
#Downloads Directory Cleanup
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
DIRECTORIES_DICTIONARY = {
|
||||
'Document': ['.doc','.docx','.pdf','.log','.txt','.rtf','.asp','.aspx','.csv','.html','.css','.js','.xml','.xls'],
|
||||
'Folder': [],
|
||||
'Audio' : ['.aif','.m3u','mp3','flac','.mpa','.wav','.m4a'],
|
||||
'Video' : ['.mp4','.flv','.mov','.vob'],
|
||||
'Image' : ['.jpg','.jpeg','.png'],
|
||||
'Zip' : ['.zip', '.7z', '.tar.gz', '.deb', '.rpm'],
|
||||
'Executables': ['.apk','.exe','.jar'],
|
||||
'Others': []
|
||||
}
|
||||
|
||||
def main():
|
||||
file_moved_counter = 0
|
||||
file_list = os.listdir('.')
|
||||
DIRECTORIES= []
|
||||
|
||||
for dir in DIRECTORIES_DICTIONARY:
|
||||
if not os.path.isdir(dir):
|
||||
print("Creating Directory '{}'".format(dir))
|
||||
os.mkdir(dir)
|
||||
DIRECTORIES.append(dir)
|
||||
|
||||
for file in file_list:
|
||||
if 'directory_cleanup' not in file and file not in DIRECTORIES:
|
||||
# Check if file is a folder first
|
||||
if os.path.isdir(file):
|
||||
shutil.move(file, './Folder/{}'.format(file))
|
||||
file_moved_counter += 1
|
||||
else:
|
||||
print('Current File: ' + file + '\n')
|
||||
filename, file_extension = os.path.splitext(file)
|
||||
for dir in DIRECTORIES_DICTIONARY:
|
||||
if file_extension in DIRECTORIES_DICTIONARY[dir]:
|
||||
os.rename(file, './'+dir+'/'+ file)
|
||||
print('MOVED FILE: ' + file + '\n')
|
||||
file_moved_counter += 1
|
||||
|
||||
#Moving files with unknown file extensions to Others folder
|
||||
new_file_list = os.listdir('.')
|
||||
for file in new_file_list:
|
||||
if 'directory_cleanup' not in file and file not in DIRECTORIES:
|
||||
os.rename(file, './Others/'+ file)
|
||||
file_moved_counter += 1
|
||||
|
||||
print('Files Organized!\nTotal file moved: ' + str(file_moved_counter))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
{{< /expand >}}
|
||||
|
||||
## Credits
|
||||
|
||||
{{< expand "Credits" >}}
|
||||
<a target="_blank" href="https://icons8.com/icons/set/broom">Broom icon</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
|
||||
{{< /expand >}}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
Loading…
Reference in New Issue