-
Notifications
You must be signed in to change notification settings - Fork 9
/
utils.py
51 lines (42 loc) · 1.81 KB
/
utils.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
# -*- coding: utf-8 -*-
import argparse
import os
from os.path import expanduser, exists, join
import pandas as pd
import numpy as np
from unidecode import unidecode_expect_nonascii as ud
import functools as tools
# # Pondera libraries & vars
PATH_PONDERA = join(expanduser('~'), 'Pondera')
PATH_D4E = join(*[PATH_PONDERA, 'playground', 'data4eco_itam'])
def get_parser():
"""Get parser for command line arguments."""
description = ("Utils for the *data4eco* course."
""
"Run handy commands for administering the files & stuff of the course."
"- alumnifolders: Organize alumni folders.")
parser = argparse.ArgumentParser(description=description)
parser.add_argument('do',
help='The command to execute')
return parser
def makefolders(root_dir, subfolders):
concat_path = tools.partial(join, root_dir)
map(os.makedirs, map(concat_path, subfolders))
if __name__ == '__main__':
parser = get_parser()
args = parser.parse_args()
if args.do == 'alumnifolders':
PATH = join(PATH_D4E, 'alumni')
list_file = join(PATH, 'alumnilist.xlsx')
if exists(list_file):
df = pd.read_excel(list_file, dtype={'cu': 'object',
'name': 'object', 'surname': 'object'})
for i, r in df.iterrows():
if (not pd.isnull(r['name'])) and (not pd.isnull(r['surname'])):
fname = '_'.join([str(r['cu']), ud(r['name'].split(' ')[0]),
ud(r['surname'].split(' ')[0])])
print(fname)
try:
os.mkdir(join(PATH, fname))
except Exception as e:
print('Ya existe el directorio ' + fname)