Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description='Send file to Netgear FTP')
    parser.add_argument('-c', dest = 'commands', 
                        default = False,
                        action= "store_true",
                        help = 'Print commands and exit')

    parser.add_argument('--put', dest = 'put', default = False,
                        action= "store_true", help= 'assumes upload')
    parser.add_argument('--source-dir', dest = 'sdir')
    parser.add_argument('--source-file', dest = 'sfile')
    parser.add_argument('--server', dest = 'server')
    parser.add_argument('--dest-dir' , dest ='ddir')
    args = parser.parse_args()
    if args.commands: princ(args) ; exit(0)

    #sys.stderr.write("ERR: args.server='{0}'\n".format(args.server))

    try:
        f = ftplib.FTP(args.server)
    except:
        sys.stderr.write("ERR: args.server='{0}'\n".format(args.server))
        raise
    f.login()
    try:
        f.cwd(args.ddir)
    except:
        print("ERR changing to dir:", args.ddir)
        raise
    fname = args.sfile
    fp = open(args.sdir + "/" + fname, 'rb')
    f.storbinary('STOR ' + fname, fp)
    fp.close()
    # f.retrlines('LIST')
    f.quit()
Exemple #2
0
def xirr_test():
    from datetime import date

    tas = [(date(2010, 12, 29), -10000), (date(2012, 1, 25), 20), (date(2012, 3, 8), 10100)]
    princ(xirr(tas))  # 0.0100612640381
    tas = [(date(2012, 1, 25), 20), (date(2010, 12, 29), -10000), (date(2012, 3, 8), 10100)]
    princ(xirr(tas))  # 0.0100612640381
Exemple #3
0
def unpack_response(lines):
    # http://coreygoldberg.blogspot.co.uk/2011/09/python-stock-quotes-from-google-finance.html
    try:
        lines = lines.decode("latin-1")
    except AttributeError:
        princ("ERR. lines is: ", lines)
        raise
    # princ(".",)
    lines = lines.split("\n")
    lines_string = [x.strip("\n") for x in lines]
    merged = "".join([x for x in lines_string if x not in ("// [", "]")])
    vals1 = json.loads(merged)
    vals2 = {k: v.replace(",", "") for k, v in vals1.items()}
    return vals2
Exemple #4
0
def example():
    @Param(42)
    def hi(newval):
        pass

    princ(hi())  # 42
    princ(hi(12))  # 12
    princ(hi())  # 12
    hi(13)  # sets it to 13
    princ(hi())  # 13
Exemple #5
0
def main():
    parser = argparse.ArgumentParser(description='CSV processing')
    parser.add_argument('-c', '--commands', dest = 'commands', 
                        default = False,
                        action= "store_true",
                        help = 'Print commands and exit')

    parser.add_argument('--from-tab', 
                        action= "store_true",
                        help = 'convert to csv format from tab-format')
    parser.add_argument('-a', '--ascii', action = 'store_true', 
                        help = 'convert to ASCII format')
    parser.add_argument("file")

           
    args = parser.parse_args()   

    if args.commands: princ(args) ; exit(0)
    if args.from_tab: tab_to_csv()
    if args.ascii is not None: astext(args.file)
Exemple #6
0
def main(istream, args):
    row = read(istream)
    princ(astext(rows, args['pad'], args['delim']))
Exemple #7
0
def minlist_test():
    princ(minlist([0, 3, 2]))
    princ(minlist([4, 1, 3, 2]))
    princ(minlist([4, 1, 3, 2, -2]))
Exemple #8
0
def show(s, v):
    fmt = "%-5.5s %7.2f"
    txt = fmt % (s, v)
    princ(txt)
Exemple #9
0
def print_commands(options, args):
    "Print options and args, then exit"
    princ("Options:", options)
    princ("Args:", args)
    sys.exit(0)
Exemple #10
0
def print_perform(quote):
    "Verbose output"
    fields = [("t", "Ticker"), ("l", "Price"), ("c", "Change (p)"), ("cp", "Change (%)")]
    for f in fields:
        k, desc = f
        princ("{0:<10s} {1:>6s}".format(desc, quote[k]))
Exemple #11
0
def print_basic(quote):
    # print('Called basic')
    princ(quote["l"])
Exemple #12
0
def download_syms_sync(syms):
    for s in syms:
        princ("download_syms_sync():", s.gepic)
        s.response = download_all_fields(s.gepic)
Exemple #13
0
        princ("download_syms_sync():", s.gepic)
        s.response = download_all_fields(s.gepic)


def download_syms(syms, async=True):
    """Download multiple units and symbols"""
    if async:
        download_syms_async(syms)
    else:
        download_syms_sync(syms)

    for s in syms:
        # s.price = unitise_price(s.unit, extract_price(s.thr.response))
        r = s.response
        if r is None:
            princ("ERR: received no response for symbol: '" + s.gepic + "'")
            exit(1)
        r = unpack_response(r)
        s.quote = r
        p = extract_price(r)
        p = unitise_price(s.unit, p)
        s.price = p


########################################################################


def print_basic(quote):
    # print('Called basic')
    princ(quote["l"])
Exemple #14
0
def astext(filename):
    c = read_csv(filename, True)
    princ(tab.astext(c))