示例#1
0
文件: ftpmc.py 项目: blippy/mython
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()
示例#2
0
文件: maths.py 项目: blippy/mython
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
示例#3
0
文件: gofi.py 项目: blippy/mython
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
示例#4
0
文件: param.py 项目: blippy/mython
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
示例#5
0
文件: csvmc.py 项目: blippy/mython
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)
示例#6
0
文件: tab.py 项目: blippy/mython
def main(istream, args):
    row = read(istream)
    princ(astext(rows, args['pad'], args['delim']))
示例#7
0
文件: maths.py 项目: blippy/mython
def minlist_test():
    princ(minlist([0, 3, 2]))
    princ(minlist([4, 1, 3, 2]))
    princ(minlist([4, 1, 3, 2, -2]))
示例#8
0
文件: gofi.py 项目: blippy/mython
def show(s, v):
    fmt = "%-5.5s %7.2f"
    txt = fmt % (s, v)
    princ(txt)
示例#9
0
文件: gofi.py 项目: blippy/mython
def print_commands(options, args):
    "Print options and args, then exit"
    princ("Options:", options)
    princ("Args:", args)
    sys.exit(0)
示例#10
0
文件: gofi.py 项目: blippy/mython
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]))
示例#11
0
文件: gofi.py 项目: blippy/mython
def print_basic(quote):
    # print('Called basic')
    princ(quote["l"])
示例#12
0
文件: gofi.py 项目: blippy/mython
def download_syms_sync(syms):
    for s in syms:
        princ("download_syms_sync():", s.gepic)
        s.response = download_all_fields(s.gepic)
示例#13
0
文件: gofi.py 项目: blippy/mython
        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"])
示例#14
0
文件: csvmc.py 项目: blippy/mython
def astext(filename):
    c = read_csv(filename, True)
    princ(tab.astext(c))