示例#1
0
文件: mavgs.py 项目: gollum2411/antec
    # Rearrange table: companies where price is above MAs appear first
    above = filter(lambda e: "above" in e[6], table)
    above = sorted(above, key=lambda a: len(a[6]), reverse=True)
    table = above + filter(lambda e: "below" in e[6], table)

    print tabulate.tabulate(table, headers=headers, tablefmt="grid")

    # Stop
    if not opts.plot:
        return 0

    print
    print "Getting plot links..."

    for ticker in all_tickers:
        url = get_shorturl(get_mavgs_url(ticker))
        print "\t{ticker} : {url}".format(
                ticker=ticker,
                url=url
              )

if __name__ == "__main__":
    if len(sys.argv) == 1:
        show_usage_and_die(usage)

    parser = get_default_optparser()
    parser.add_option("-p", "--plot", dest="plot", default=False,
        action="store_true", help="Get links to Yahoo plots. This will be slow.")
    sys.exit(main(*parser.parse_args()))

示例#2
0
            # Each entry in table:
            table_entry = [ticker,
                    price,
                    high,
                    "ABOVE" if is_above else "below"
                    ]
            table.append(table_entry)
    except urllib2.HTTPError as e:
        sys.stderr.write("warning: failed retrieving data for {0}: {1}".format(
            ticker, str(e)))

    headers = ["Company", "Price", "{0}-day high".format(opts.ndays), "Price vs. {0}-day high".format(
        opts.ndays)]

    # Lets rearrange the table so all ABOVEs appear before belows
    aboves = filter(lambda a: a[3] == "ABOVE", table)
    table = aboves + filter(lambda a: a[3] == "below", table)

    print tabulate.tabulate(table, headers=headers, tablefmt="grid")

if __name__ == "__main__":
    if len(sys.argv) == 1:
        common.show_usage_and_die(usage)

    parser = common.get_default_optparser()
    parser.add_option("-n", "--ndays", dest="ndays", default=20,
        action="store", help="Number of days. Defaults to 20")

    sys.exit(main(*parser.parse_args()))