-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkfolder.py
executable file
·84 lines (69 loc) · 2.45 KB
/
mkfolder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env python3
"""
Make new empty directory begining of the month.
Usage:
mkfolder.py 2020 06
"""
import sys, os, re
if len(sys.argv) < 4:
print('''[Program Usage]\n
mkfolder.py <2020> <08> \n
Please add argument of year and month in digits, and biMonth in "A" or "B"
''')
quit()
path = '/home/sung/Umami/Financial'
path_shared ='/home/sung/shared/Umami/Financials'
path_script = '/home/sung/Umami/scripts/Finance_Umami'
yr, mo, biMonth = str(sys.argv[1]), str(sys.argv[2]), str(sys.argv[3])
period = yr + "_" + mo
config_file = os.path.join(path_script, 'config.py')
with open(config_file) as reading_file:
new_file_content = ""
regex = re.compile("^yr, mo, biMonth =.*$")
for line in reading_file:
new_line = regex.sub(
f'yr, mo, biMonth = "{sys.argv[1]}", "{sys.argv[2]}", "{sys.argv[3]}"', \
line, count=1)
new_file_content += new_line
with open(config_file, 'w') as f:
f.write(new_file_content)
meta = 'meta'
report = 'report'
caviar = 'caviar'
uber = 'uber'
shift = 'shift'
square ='square'
directory = os.path.join(path_shared, period)
if os.path.isdir(directory):
print(f'Directory "{directory}" already exist!')
quit()
if not os.path.isdir(directory):
try:
os.mkdir(directory)
os.mkdir(os.path.join(path_shared, period, meta))
os.mkdir(os.path.join(path_shared, period, meta, caviar))
os.mkdir(os.path.join(path_shared, period, meta, uber))
os.mkdir(os.path.join(path_shared, period, meta, shift))
os.mkdir(os.path.join(path_shared, period, meta, square))
os.mkdir(os.path.join(path_shared, period, report))
print(f'Successfully create directory "{directory}" and sub-directories')
except OSError:
print(f'Creation of the directory "{directory}" failed!')
filepath = os.path.join(path_shared, period, meta)
month = ['A', 'B']
locs = ["Dimond", "Uptown"]
dn = ['Day', 'Night']
for loc in locs:
os.mknod(os.path.join(filepath, uber, 'Dummie__Uber_'+period+'_'+loc+'.csv'))
for m in month:
try:
os.mknod(os.path.join(filepath, square, 'Dummie__'+period+m+'_'+loc+'.csv'))
except:
pass
try:
os.mknod(os.path.join(filepath, shift, 'Dummie__'+period+m+'.csv'))
except:
pass
for i in dn:
os.mknod(os.path.join(filepath, square, 'Dummie__pmethod_'+m+'_'+loc+'_'+i+'.csv'))
print('All meta folders created!')