Example #1
0
def test_bug_fix_for_issue_2():
    data = {}
    data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
    data.update({"Sheet 2": [[u"row 1", u"Héllô!", u"HolÁ!"]]})
    save_data("your_file.ods", data)
    new_data = get_data("your_file.ods")
    assert new_data["Sheet 2"] == [[u'row 1', u'H\xe9ll\xf4!', u'Hol\xc1!']]
Example #2
0
def test_issue_13():
    test_file = "test_issue_13.ods"
    data = [[1, 2], [], [], [], [3, 4]]
    save_data(test_file, {test_file: data})
    written_data = get_data(test_file, skip_empty_rows=False)
    eq_(data, written_data[test_file])
    os.unlink(test_file)
Example #3
0
    def extrair_dados(self, caminho):
        try:
            data = get_data(caminho)
            nova = list()
            for i in xrange(len(data)):
                if data[i]:
                    nova.append(data[i])

            return nova
        except:
            trace = traceback.format_exc()
            file("trace.log","a").write(trace)
Example #4
0
def test_bug_fix_for_issue_1():
    data = get_data(os.path.join("tests", "fixtures", "repeated.ods"))
    assert data == [['repeated', 'repeated', 'repeated', 'repeated']]
Example #5
0
 def __init__(self, pth):
     self.pth = pth
     self.data = get_data(pth)
Example #6
0
def test_issue_19():
    test_file = "pyexcel_81_ods_19.ods"
    data = get_data(get_fixtures(test_file), skip_empty_rows=True)
    eq_(data["product.template"][1][1], "PRODUCT NAME  PMP")
def main():
    """ overall function, checks the spreadsheet and outputs the errors """

    #workbook = open_workbook(sys.argv[1], on_demand=True)
    data = get_data(sys.argv[1])
    workbookString = json.dumps(data)
    workbookDict = ast.literal_eval(workbookString)

    errorMessageList_setup = []
    errorMessageList_questions = []
    errorMessageList_choices = []

    print ""

    if not check4correctSheets(workbookDict, errorMessageList_setup):
        for error in errorMessageList_setup:
            print error
        print "FATAL ERROR  --  incorrect sheets in workbook"
        return False
    print "checking for correct worksheets.......................................OK!"

    # I wonder if it's ok to only have user input questions, and then no choices sheet or a blank one?
    # This definitely has to get checked and parsed before the survey questions can get checked
    if not choicesSheetHasCorrectSetup(workbookDict, errorMessageList_setup):
        for error in errorMessageList_setup:
            print error
        print "FATAL ERROR  --  choices could not be parsed"
        return False

    choicesDict = parseChoices(workbookDict, errorMessageList_choices)
    print "checking choices sheet setup..........................................OK!"

    if not surveySheetHasCorrectSetup(workbookDict, errorMessageList_setup):
        for error in errorMessageList_setup:
            print error
        print "FATAL ERROR  --  survey could not be parsed"
        return False
    questionsList = parseQuestions(workbookDict, errorMessageList_questions)
########SKETCHY#########
    questionsList = questionsList[:263]
    #print "there are this many questions: "+str(len(questionsList))
#    print questionsList[-3].__dict__
    print "checking survey sheet setup...........................................OK!"

    checkQuestions(questionsList, errorMessageList_questions, choicesDict)


    # This matters less so I put it below the other two so that they could still get checked if this fails
    if not settingsSheetHasCorrectSetup(workbookDict, errorMessageList_setup):
        for error in errorMessageList_setup:
            print error
        print "FATAL ERROR  --  survey could not be parsed"
        return False
    print "checking settings sheet setup.........................................N/A"

    print ""

    if len(errorMessageList_choices) > 0:
        for error in errorMessageList_choices:
            print error
            print ""

    if len(errorMessageList_questions) > 0:
        for error in errorMessageList_questions:
            print error
            print ""

    print "Enjoy your survey!....................................................OK!"
    print ""
    return True
Example #8
0
            del row[15]
            del row[13]

            del row[9]
            del row[8]
            del row[7]
            del row[6]
            del row[5]
            del row[4]
            del row[3]
            del row[2]
            del row[1]
            del row[0]

    def tostr(i, v):
        try:
            return str(int(v)) if float(v) == int(v) else str(float(v))
        except:
            return str(v)

    with open("TShips.pck", "w") as of:
        of.write("".join(r[0] + "\n" for r in data[0:2]))
        of.write("".join((";".join(tostr(i, v) for i, v in enumerate(r)) + ";\n") for r in data[2:] if r))


if __name__ == "__main__":
    xlsfile = "tships.xls"
    data = get_data("tships.ods")["tships"]

    export(data)
Example #9
0
def test_bug_fix_for_issue_1():
    data = get_data(get_fixtures("repeated.ods"))
    eq_(data["Sheet1"], [["repeated", "repeated", "repeated", "repeated"]])
Example #10
0
def test_issue_27():
    test_file = get_fixtures("issue_27.ods")
    data = get_data(test_file, skip_empty_rows=True)
    eq_(data["VGPMX"], [["", "Cost Basis", "0"]])
Example #11
0
def test_issue_24():
    test_file = get_fixtures("comment-in-cell.ods")
    data = get_data(test_file)
    eq_(data["Sheet1"], [["test"]])
Example #12
0
def test_pr_22():
    test_file = get_fixtures("white_space.ods")
    data = get_data(test_file)
    eq_(data["Sheet1"][0][0], "paragraph with tab(\t),    space, \nnew line")
Example #13
0
        del row[0]
    for row in data[3:]:
        if row:
            del row[21]
            del row[19]
            del row[7]
            del row[6]
            del row[5]
            del row[4]
            del row[3]
            del row[2]
            del row[1]
            del row[0]

    def tostr(i, v):
        if 16<=i<=18:
            return str(float(v))
        try:
            return str(int(v)) if float(v) == int(v) else str(float(v))
        except:
            return str(v)

    with open('TBullets.pck', 'w') as of:
        of.write(''.join(r[0]+'\n' for r in data[0:2]))
        of.write(''.join((';'.join(tostr(i, v) for i, v in enumerate(r))+';\n') for r in data[2:] if r))

if __name__ == '__main__':
    data = get_data("tbullets.ods")['tbullets']

    export(data)
rows = cursor.fetchall()
if not rows: # inserir na tabela tipo_item_pesquisa caso não haja linhas
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(1, 'Recursos Humanos')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(2, 'Planejamento Urbano')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(3, 'Recursos para Gestão')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(4, 'Terceirização e Informatização')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(5, 'Gestão ambiental')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(pesquisa_munic.id_tipo_item_pesquisa, descricao) values(6, 'Articulação Interinstituicional')")
    cursor.execute("insert into  pesquisa_munic.tipo_item_pesquisa(id_ pesquisa_munic.tipo_item_pesquisa, descricao) values(7, 'Variáveis Externas')")
    cursor.execute("commit")
# fim tipo_item_pesquisa
#Ajustar o path(file_name_with_path)
file_name_with_path = "C:\desenv\dados\Base_MUNIC_2015_ods\Base_MUNIC_2015.ods"
#abrir o arquivo ods que possui a munic
from pyexcel_ods import get_data
data = get_data(file_name_with_path)

cursor.execute("select * from  pesquisa_munic.item_composicao_quadro_pessoal where pesquisa_munic.id_tipo_item_pesquisa=1")
rows = cursor.fetchall()
if not rows: # inserir na tabela pesquisa_munic.item_composicao_quadro_pessoal caso não haja linhas, mas antes inserir na munic.esfera_municipal
   sheet_recursos_humanos = data.get('Recursos_humanos')
   id_esfera_municipal = 1
   for row in  sheet_recursos_humanos:
       if row[0] == 'A1':
           continue
       #insert into pesquisa_munic.esfera_municipal
       #cursor.execute("SELECT nextval('pesquisa_munic.s_esfera_municipal')")
       codigo_municipio = row[2]
       geocodigo = row[0]
       url_nome_municipio = 'http://idehco4.tk/instituicoes/ibge/bcim/municipios/'+ geocodigo + '/nome'
       url_geometry = 'http://idehco4.tk/instituicoes/ibge/bcim/municipios/'+ geocodigo + '/geom'
Example #15
0
#!/usr/bin/env python3
"""Напечатать список проектов, по которым не определены дальнейшие действия в taskwarrior"""

from os.path import expanduser
from subprocess import check_output

from pyexcel_ods import get_data

DATA = get_data(expanduser("~/.db/wiki/excel/prj.ods"))

def check_learning():
    """Проверить все направления изучения"""
    data = [v for v in DATA['Learning'][1:] if len(v) >= 3]
    for [code, _type, desc, *_] in data:
        if _type != 'Книга':
            have = have_tasks(code)
            if not have:
                print("task add", ("project:"+code).ljust(50), '   # '+desc)

class PrjRow():
    """Проект личный, по работе"""
    def __init__(self, row):
        self.row = row

    def have_data(self):
        """Есть ли данные в строке"""
        return len(self.row) > 0

    def finished(self):
        """Закончен ли проект"""
        if self.completed() != "":
Example #16
0
#!/usr/bin/env python
from pyexcel_ods import get_data
data = get_data('sum.ods')
import json
k = json.dumps(data)
print(k)
print(int(k[13]+k[14]) + int(k[17]+k[18]))
Example #17
0
def test_issue_14():
    # pyexcel issue 61
    test_file = "issue_61.ods"
    data = get_data(get_fixtures(test_file), skip_empty_rows=True)
    eq_(data["S-LMC"], [[u"aaa"], [0]])
Example #18
0
 def handle(self, *args, **options):
     self.handle1(get_data(FILE_NAME1))
Example #19
0
def test_issue_6():
    test_file = "12_day_as_time.ods"
    data = get_data(get_fixtures(test_file), skip_empty_rows=True)
    eq_(data["Sheet1"][0][0].days, 12)
Example #20
0
from pyexcel_ods import get_data
data=get_data("/home/anant/Desktop/foss/pyth.ods")
import json
k=json.dumps(data)
sum=int(k[13])+int(k[16])
print sum

import sys 
from pyexcel_ods import get_data
import pyexcel as pe
import pyexcel.ext.ods
import ast

import json
import pudb


data = get_data(sys.argv[1])
workbook = json.dumps(data)
d = ast.literal_eval(workbook)
print d.keys()
print len(d['choices'])
print d['choices'][1][:5]
#book = pe.get_book(file_name=sys.argv[1])
#sheets = book.to_dict()

#for name in sheets.keys():
#    print name