Пример #1
0
def initialize(host, page, language, name, overwrite=False):
    with open('locales/'+language+'/locales.json', encoding='utf-8') as json_file:
        locales = json.load(json_file)
    new_calc_host = ethercalc.EtherCalc(host)
    for i in range(5):
        no = i + 1
        new_calc_host.command(page, ["set A"+str(no+1)+" text t /"+page+"."+str(no)])
        new_calc_host.command(page, ["set B"+str(no+1)+" text t "+locales["sheet"+str(no)]])
        # sheet = script.load_ethercalc(host=host, page="w2jjmp1soy3s", sheet=no, export_format="socialcalc")
        with open('locales/'+language+"/sheet"+str(no)+".txt", "r", encoding='utf-8') as text_file:
            sheet = text_file.read().encode("utf-8")
        new_calc_host.update(sheet, format="socialcalc", id=page+"."+str(no))
    new_calc_host.command(page+".5", ["set C6 text t "+name])

    available_locales = []
    folders = os.listdir('locales/')
    for folder in folders:
        if os.path.isfile("locales/"+folder+"/locales.json"):
            available_locales.append(folder)
    new_calc_host.command(page+".5", ["set D5 text t "+script.semicolon_separated_list_from_python_list(any_list=available_locales)])

    if not os.path.exists("_credentials/calc_urls"):
        os.makedirs("_credentials/calc_urls")
    data = {'host': host, 'page': page, 'name': name}

    name_no = ""
    if name in calc_names and not overwrite:
        name_no = 2
        while name+"_"+str(name_no) in calc_names:
            name_no += 1
        name_no = "_" + str(name_no)
    file_name = name + name_no

    with open("_credentials/calc_urls/"+file_name+".json", 'w') as outfile:
        json.dump(data, outfile)
Пример #2
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    logging.debug("Enter Main()")

    local_file = False
    local_file_yn = input(
        "You can either import a local socialcalc file or copy a socialcalc sheet from the web. Enter Y for local file or N for copying: "
    )
    while not script.is_yn(local_file_yn):
        local_file_yn = input("Enter Y for local file or N for copying: ")
    if local_file_yn == "Y" or local_file_yn == "y":
        local_file = True
        path = str(input("Paste path of local socialcalc file: "))
        path = path.replace("\\", "/")
        with open(path, "r", encoding='utf-8') as text_file:
            sheet = text_file.read().encode("utf-8")
    else:
        source_host = str(
            input("Please enter the host URL of the sheet you want to copy: "))
        source_page = str(
            input(
                "Please enter the page ID for the sheet you want to copy (single sheet without '=' in front): "
            ))
        print("Trying to copy sheet from " + source_host + "/" + source_page)
        sheet = script.load_ethercalc(
            host=source_host, page=source_page,
            export_format="socialcalc").encode("utf-8")

    write = False
    while not write:
        host = str(input("Please enter the new host URL for the sheet: "))
        page = str(
            input(
                "Please enter the new page ID for the sheet (open the sheet once before proceeding): "
            ))
        existing_sheet = script.load_ethercalc(host=host,
                                               page=page,
                                               export_format="socialcalc")
        if "version:1.5\nsheet:" not in existing_sheet:
            overwrite = str(
                input(
                    "The sheet you want to replace doesn't seem to be empty! Are you sure you want to overwrite it? (Y/N) "
                ))
            while not script.is_yn(overwrite):
                overwrite = str(
                    input(
                        "Enter Y to overwrite it or N to choose a different page ID: "
                    ))
            if overwrite == "Y" or overwrite == "y":
                write = True
        else:
            write = True

    new_calc_host = ethercalc.EtherCalc(host)
    new_calc_host.update(sheet, format="socialcalc", id=page)
Пример #3
0
#!/usr/bin/env python3
import ethercalc
import pprint
pp = pprint.PrettyPrinter(indent=4)
e = ethercalc.EtherCalc("http://localhost:8000")
e.command("test", ["set C1 value n 2"])
pp.pprint(e.cells("test"))
pp.pprint(e.cells("test", "A1"))
e.command("test", [
    ethercalc.set("C1", 2),
    ethercalc.set("C2", 2),
    ethercalc.set("C3", "=C1+C2")
])
pp.pprint(e.export("test"))
Пример #4
0
#!/usr/bin/env python3

import ethercalc
import os
import sys
import requests
import os.path

cwd = os.path.dirname(os.path.realpath(sys.argv[0]))
ethercalc_dir = os.path.join(cwd, "ethercalc-data")
ec = ethercalc.EtherCalc("http://localhost/calc/")
lockfile = os.path.join("/var", "log", "bitquant", "ethercalc-init.txt")
if os.path.isfile(lockfile):
    print("ethercalc already init. exiting")
    exit(0)

for i in os.listdir(ethercalc_dir):
    if i.endswith(".clc"):
        item = i.rsplit(".", maxsplit=1)[0]
        try:
            a = ec.export(i)
        except requests.exceptions.HTTPError:
            txt = open(os.path.join(ethercalc_dir, i))
            data = txt.read()
            #            print (data)
            print(ec.update(item, data))

f = open(lockfile, "w")
f.write("This file shows that ethercalc has been init.")
f.close()
Пример #5
0
calc_configs = script.get_calc_configs()

if calc_configs:
    if len(calc_configs) == 1:
        calc_config = calc_configs[0]
    else:
        calc_names = []
        for calc_config in calc_configs:
            calc_names.append(calc_config['name'])
        print("Calcs found: " +
              script.semicolon_separated_list_from_python_list(
                  any_list=calc_names))
        calc_name = input(
            "Enter the name of the calc (see list above) for which you want to unhide rows: "
        )
        while calc_name not in calc_names:
            calc_name = input("No calc with this name found. Try again: ")
        calc_config = next(
            (item for item in calc_configs if item["name"] == calc_name), None)

    script.set_calc_data(config=calc_config)
    settings_list = script.load_ethercalc(sheet=5)
    header_lines = script.find_header_lines(settings_list=settings_list)
    print("header lines = " + str(header_lines))

    rows = input("Up to which row of " + script.calc['name'] +
                 "'s events table do you want to unhide? ")

    e = ethercalc.EtherCalc(script.calc["host"])
    e.command(script.calc["page"] + ".1",
              ["set " + str(header_lines + 1) + ":" + str(rows) + " hide"])