import ucsv as csv
import os, glob
import sys
import xlsxwriter
import tinys3
import time
import json
from ctext import convert

with open('/data/config.json') as jsonFile:
    data = json.load(jsonFile)

if data["parameters"]["#S3key"] == '' or data["parameters"]["#S3secretKey"] == '' or data["parameters"]["bucketName"] == '':
    print " === config json parameters empty ==="
    sys.exit(1)

if __name__ == '__main__':
    listOfFiles = glob.glob("/data/in/tables/*.csv")
    list_of_indexes = []
    for index, fileInList in enumerate(listOfFiles):
        fileName  = fileInList[0:fileInList.find('.')]
        excelFile = xlsxwriter.Workbook(fileName + '.xlsx')
        worksheet = excelFile.add_worksheet()
        with open(fileInList, 'rb') as f:
            content = csv.reader(f)
            for index_row, data_in_row in enumerate(content):
                for index_col, data_in_cell in enumerate(data_in_row):

                    if type(data_in_cell) == unicode  and index_row != 0:
                        list_of_indexes.append(index_col)
    excelFile.close()
    list_of_indexes = dict.fromkeys(list_of_indexes).keys()
    print " === indexes are saved  ==="
    convert(list_of_indexes)



conn = tinys3.Connection(data["parameters"]["#S3key"],data["parameters"]["#S3secretKey"])
listOfFiles2 = glob.glob("/data/in/tables/*.xlsx")
for file in listOfFiles2:
    temp = os.path.splitext(file[16:len(file)])
    print " === uploading " + temp[0]+'_'+time.strftime("%Y-%m-%d")+temp[1] + " ==="
    conn.upload(temp[0]+'_'+time.strftime("%Y-%m-%d")+temp[1],open(file,'rb'),data["parameters"]["bucketName"])
    print " === " + temp[0]+'_'+time.strftime("%Y-%m-%d")+temp[1] + " uploaded ==="

import ucsv as csv
import os, glob
import sys
import xlsxwriter
import tinys3
import time
import json
from ctext import convert

with open('/data/config.json') as jsonFile:
    data = json.load(jsonFile)

if data["parameters"]["#S3key"] == '' or data["parameters"]["#S3secretKey"] == '' or data["parameters"]["bucketName"] == '':
    print " === config json parameters empty ==="
    sys.exit(1)

if __name__ == '__main__':
    listOfFiles = glob.glob("/data/in/tables/*.csv")
    list_of_indexes = []
    for index, fileInList in enumerate(listOfFiles):
        fileName  = fileInList[0:fileInList.find('.')]
        excelFile = xlsxwriter.Workbook(fileName + '.xlsx')
        worksheet = excelFile.add_worksheet()
        with open(fileInList, 'rb') as f:
            content = csv.reader(f)
            for index_row, data_in_row in enumerate(content):
                for index_col, data_in_cell in enumerate(data_in_row):

                    if type(data_in_cell) == unicode  and index_row != 0:
                        list_of_indexes.append(index_col)
    excelFile.close()
    list_of_indexes = dict.fromkeys(list_of_indexes).keys()
    print " === indexes are saved  ==="
    convert(list_of_indexes)



conn = tinys3.Connection(data["parameters"]["#S3key"],data["parameters"]["#S3secretKey"])
listOfFiles2 = glob.glob("/data/in/tables/*.xlsx")
for file in listOfFiles2:
    temp = os.path.splitext(file[16:len(file)])
    print " === uploading " + temp[0]+'_'+str(int(time.strftime("%V"))-1)+temp[1] + " ==="
    conn.upload(temp[0]+'_'+str(int(time.strftime("%V"))-1)+temp[1],open(file,'rb'),data["parameters"]["bucketName"])
    print " === " + temp[0]+'_'str(int(time.strftime("%V"))-1)+temp[1] + " uploaded ==="

Update current date to week - 1