Created
June 23, 2016 10:05
-
-
Save ecarreras/edb5db3b9546b0b47fbfb5fac6f2fbff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import optparse | |
import csv | |
import time | |
parser = optparse.OptionParser(version="[GISCE ERP] Migrations") | |
group = optparse.OptionGroup(parser, "REE Related") | |
group.add_option("-f", "--csv", dest="csv_file", help="specify the CLMAG file") | |
group.add_option("-p", "--period", dest="period", help="specify the period for AUTOBJEAGCL ex (08/2009)") | |
group.add_option("-e", "--fversion", dest="fversion", help="specify the file version") | |
parser.add_option_group(group) | |
options = optparse.Values() | |
options.fversion = 'V' | |
parser.parse_args(values=options) | |
period = options.period | |
csv_file = options.csv_file | |
try: | |
mesos = ['12', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11'] | |
month,year = period.split('/') | |
index = (int(month)+1)%12 | |
n_month = mesos[index] | |
n_year = year | |
if index == 1: | |
n_year = str(int(year)+1) | |
__motivo__ = ";%s/%s/01 00;%s/%s/01 00;002;0;0;POR MOTIVOS AJENOS A LA EMPRESA NO SE HA PODIDO ENVIAR EL FICHERO EN LA FECHA ESTABLECIDA" % (year, month, n_year, n_month) | |
comers = {} | |
reader = csv.reader(open(csv_file), delimiter=';') | |
for line in reader: | |
comer = line[4] | |
if not comers.has_key(comer): | |
comers[comer] = [] | |
line_tmp = line[3:5] | |
line_tmp.extend(line[6:10]) | |
line_tmp.extend(line[5:6]) | |
line_to_append = ';'.join(line_tmp) | |
line_to_append += __motivo__ | |
if line_to_append not in comers[comer]: | |
comers[comer].append(line_to_append) | |
for comer in comers.keys(): | |
sorted(comers[comer]) | |
distri = comers[comer][0][0:4] | |
filename = 'AUTOBJEAGCL_%s_%s_9999_%s%s_%s.%s' % (distri, comer, year, month, time.strftime('%Y%m%d'), options.fversion ) | |
f = open(filename, 'wb') | |
f.write('\n'.join(comers[comer])) | |
f.write('\n') | |
f.flush() | |
f.close() | |
print "**** COMER: %s [%s] ****" % (comer, filename) | |
print '\n'.join(comers[comer]) | |
except KeyboardInterrupt: | |
print 'Shutting Down...' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment