def test_five_different_books(self):
     basket = [
         "0000000001", "0000000001",
         "0000000002", "0000000002",
         "0000000003", "0000000003",
         "0000000004",
         "0000000005"
     ]
     self.assertEqual(4 * 8 * 0.8 + 4 * 8 * 0.8, price(basket))
 def test_any_single_copy_of_a_book_should_cost_8_euros(self):
     baskets = (
         ["0000000001"],
         ["0000000002"],
         ["0000000003"],
         ["0000000004"],
         ["0000000005"]
     )
     for basket in baskets:
         self.assertEqual(8, price(basket))
示例#3
0
def for_host():
    if request.method == 'POST':
        x1 = request.form.get('neighbourhood')
        x2 = request.form.get('room_type')
        x3 = request.form.get('accommodates')
        x4 = request.form.get('bathrooms')
        x5 = request.form.get('bedrooms')
        x6 = request.form.get('cleanliness')
        x7 = request.form.get('communication')
        x8 = request.form.get('location')
        x9 = price(x1, x2, x3, x4, x5, x6, x7, x8)
    return render_template("hostparams.html")
示例#4
0
def handle(query):
    res = ''
    query = query.lower()
    if len(query.split()) > 1:
        while Switch((query.split()[0]).lower()):
            if case('prix'):
                res = price(query.split())
                break
            if case('price'):
                res = price(query.split())
                break
            if case('conv'):
                res = conv(query.split())
                break
            if case('chart'):
                res = chart.chart(query.split()[1])
                break
            if case('book'):
                res = book.book(query.split()[1])
                break
            break
    return res
示例#5
0
def price_recommendation():
    if request.method == 'POST':
        x1 = request.form.get('neighbourhood')
        x2 = request.form.get('room_type')
        x3 = request.form.get('accommodates')
        x4 = request.form.get('bathrooms')
        x5 = request.form.get('bedrooms')
        x6 = request.form.get('cleanliness')
        x7 = request.form.get('communication')
        x8 = request.form.get('location')
        x9 = price(x1, x2, x3, x4, x5, x6, x7, x8)

        labels_2016 = ['transport', 'clean', 'quiet', 'host']
        values = [0.67, 0.34, 0.75, 0.55]
        colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
        explode = (0, 0, 0.1, 0)
        plt.figure(figsize=(10, 10))
        plt.pie(values,
                explode=explode,
                labels=labels_2016,
                colors=colors,
                autopct='%1.1f%%',
                shadow=True,
                startangle=90)
        plt.savefig('static/images/key_word.png')
        plt.close()

    return render_template('hostoutput.html',
                           neighbourhood=x1,
                           room_type=x2,
                           accommodates=x3,
                           bathrooms=x4,
                           bedrooms=x5,
                           cleanliness=x6,
                           communication=x7,
                           location=x8,
                           price=x9)
示例#6
0
# coding: utf-8

from __future__ import division
from __future__ import print_function

import igraph
import price

# Define variables
sv = 3      # starting vertices
at = .8     # attractivity
ns = 20     # network size

""" Create a graph, and print out its properties
"""
p = price.price(sv, at, ns)

# Summary
print()
print("Starting vertices: ", sv)
print("Attractivity: ", at)
print("Network size: ", ns)
print()

print("vcount: ", p.vcount())
print("ecount: ", p.ecount())

print("directed: ", p.is_directed())

print("indegree: ", p.indegree())
print("outdegree:", p.outdegree())
示例#7
0
Author: Sedrick Thomas
Created at: May 7th 2020

This is basically the file that writes all the information that we calculated in the 
other modules to a CSV file to be read and interpreted. There may be a few values that
don't return a value due to the inaccessibilty of those items from scraping those websites
"""

from csv import writer
from price import price
from listofstocks import stockslist
from pe_ratio import p_e_ratio

# Create instances of the imported lists
list_of_stocks = stockslist()
stock_prices = price()
ratio_list = p_e_ratio()

with open('live_stock_more_info.csv', 'w') as f:
    csv_writer = writer(f)
    headers = ['Company', 'Stock Price', 'P/E Ratio']
    csv_writer.writerow(headers)
    # For loop that iterates over the length of this list to write each stock and its price
    for i in range(len(list_of_stocks)):
        try:
            csv_writer.writerow(
                [list_of_stocks[i], stock_prices[i], ratio_list[i]])
        except IndexError:
            csv_writer.writerow([list_of_stocks[i], stock_prices[i], 'null'])
        else:
            continue
 def test_no_book(self):
     basket = []
     self.assertEqual(0, price(basket))
 def test_three_different_books(self):
     basket = ["0000000001", "0000000002", "0000000003"]
     self.assertEqual(3 * 8 * 0.90, price(basket))
 def test_two_different_books_among_three(self):
     basket = ["0000000001", "0000000002", "0000000001"]
     self.assertEqual(2 * 8 * 0.95 + 8, price(basket))
 def test_two_different_books_should_have_5_percent_discount(self):
     basket = ["0000000001", "0000000002"]
     self.assertEqual(2 * 8 * 0.95, price(basket))
 def test_two_times_the_same_book_should_have_no_discount(self):
     basket = ["0000000001", "0000000001"]
     self.assertEqual(2 * 8, price(basket))
示例#13
0
            else:
                print(
                    Fore.RED +
                    "\nCould not retrieve network stats, please try again. \n")

            continue

        elif command.startswith('p') or command.startswith('price'):

            #get out of this conditional if anything other than p or price. needed since first elif needs to take into account the numbers as well, not just the command itself
            if command not in price_commands:
                print(Fore.RED + f"\nSorry, command not recognized: {inp}\n")
                continue

            if command and not command_args:  #if command passed true and arent any additional args
                price_info = price()  # get info
                if price_info['received_info']:  # if succesfully received

                    print("\nCurrent price: $" + str(price_info['mk_usd']) +
                          " or Ł" + str(price_info['mk_ltc']) + "(litoshis)")
                    print(
                        Fore.YELLOW +
                        " \nYou can also try 'price <amount> to calculate how much your TRTLs are worth. \n"
                    )

                    continue

                else:
                    print(
                        Fore.RED +
                        "\nCould not retrieve price stats, please try again.\n"
示例#14
0
def main():
    argv_length = len(sys.argv)
    if argv_length == 5:
        init()
        TIME = timeman.timeConvertor(sys.argv[1])
        try:
            FROM = stations.getStationCode(sys.argv[2])['station_code']
        except:
            print "出发站点不存在!"
            exit(1)
        try:
            TO = stations.getStationCode(sys.argv[3])['station_code']
        except:
            print "目的站点不存在!"
            exit(1)
        print "查询中..."

        CDN = sys.argv[4]

        session = requests.Session()
        session.headers = {
	    "Host": "kyfw.12306.cn",
	    "Connection": "keep-alive",
	    "Cache-Control": "max-age=0",
	    "Upgrade-Insecure-Requests": "1",
	    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
	    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
	    "Accept-Encoding": "gzip, deflate, sdch, br",
	    "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6",
        }
        queryResult =  querier.querier(TIME, FROM, TO, "ADULT", session, CDN)
        length = queryResult.length
        for i in range(length):
            print "=" * 36

            train_no = queryResult.getTrainNo(i)
            from_station_no = queryResult.getFromStationNo(i)
            to_station_no = queryResult.getToStationNo(i)
            seat_types = queryResult.getSeatTypes(i)
            train_date = TIME

            print "座位类型 :",seat_types


            priceResult = price.price(train_no, from_station_no, to_station_no, seat_types, train_date, session, CDN)

            qita_price = "--"
            wuzuo_price = "--"
            yingzuo_price = "--"
            yingwo_price = "--"
            ruanzuo_price = "--"
            ruanwo_price = "--"
            gaojiruanwo_price = "--"
            erdengzuo_price = "--"
            yidengzuo_price = "--"
            tedengzuo_price = "--"
            shangwuzuo_price = "--"

            if tools.checkStringChars(seat_types, "OOMP"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = priceResult.getPrice("P")
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "OMP"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = priceResult.getPrice("P")
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "O9OMP"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = priceResult.getPrice("P")
                shangwuzuo_price = "A9"
            elif tools.checkStringChars(seat_types, "O9MP"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = priceResult.getPrice("P")
                shangwuzuo_price = priceResult.getPrice("A9")
            elif tools.checkStringChars(seat_types, "O9OM"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = "--"
                shangwuzuo_price = "A9"
            elif tools.checkStringChars(seat_types, "1413"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = priceResult.getPrice("A1")
                yingwo_price = priceResult.getPrice("A3")
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "OM9"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = "--"
                shangwuzuo_price = priceResult.getPrice("A9")
            elif tools.checkStringChars(seat_types, "OMO"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = priceResult.getPrice("M")
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "14136"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = priceResult.getPrice("A1")
                yingwo_price = priceResult.getPrice("A3")
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = priceResult.getPrice("A6")
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "113"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = priceResult.getPrice("A1")
                yingwo_price = priceResult.getPrice("A3")
                ruanzuo_price = "--"
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "O4"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = "--"
                erdengzuo_price = priceResult.getPrice("O")
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "24"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = priceResult.getPrice("A2")
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "4"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "112"):
                qita_price = "--"
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = priceResult.getPrice("A1")
                yingwo_price = "--"
                ruanzuo_price = priceResult.getPrice("A2")
                ruanwo_price = "--"
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "1416H3"):
                qita_price = priceResult.getPrice("OT")[0]
                wuzuo_price = priceResult.getPrice("WZ")
                yingzuo_price = priceResult.getPrice("A1")
                yingwo_price = priceResult.getPrice("A3")
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = priceResult.getPrice("A6")
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "43"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = priceResult.getPrice("A3")
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = "--"
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            elif tools.checkStringChars(seat_types, "46"):
                qita_price = "--"
                wuzuo_price = "--"
                yingzuo_price = "--"
                yingwo_price = "--"
                ruanzuo_price = "--"
                ruanwo_price = priceResult.getPrice("A4")
                gaojiruanwo_price = priceResult.getPrice("A6")
                erdengzuo_price = "--"
                yidengzuo_price = "--"
                tedengzuo_price = "--"
                shangwuzuo_price = "--"
            else:
                print "座位类型无法解析!"


            print "列车号 : ", queryResult.getStationTrainCode(i)
            print "列车编号 : ", queryResult.getTrainNo(i)
            print "是否可凭身份证进出站 : ", queryResult.getIsSupportCard(i)
            print "首发站 : ", queryResult.getStartStationName(i)
            print "终点站 : ", queryResult.getEndStationName(i)
            print "起始站 : ", queryResult.getFromStationName(i)
            print "到达站 : ", queryResult.getToStationName(i)
            print "出发时间 : ", queryResult.getStartTime(i)
            print "到达时间 : ", queryResult.getArriveTime(i)
            print "历时 : ", queryResult.getLishi(i)
            print "其他 [", qita_price, "] :", queryResult.getQitaNumber(i)
            print "无座 [", wuzuo_price, "] :", queryResult.getWuzuoNumber(i)
            print "硬座 [", yingzuo_price, "] :", queryResult.getYingzuoNumber(i)
            print "硬卧 [", yingwo_price, "] :", queryResult.getYingwoNumber(i)
            print "软座 [", ruanzuo_price, "] :", queryResult.getRuanzuoNumber(i)
            print "软卧 [", ruanwo_price, "] :", queryResult.getRuanwoNumber(i)
            print "高级软卧 [", gaojiruanwo_price, "] :", queryResult.getGaojiruanwoNumber(i)
            print "二等座 [", erdengzuo_price, "] :", queryResult.getErdengzuoNumber(i)
            print "一等座 [", yidengzuo_price, "] :", queryResult.getYidengzuoNumber(i)
            print "特等座 [", tedengzuo_price, "] :", queryResult.getTengdengzuoNumber(i)
            print "商务座 [", shangwuzuo_price, "] :", queryResult.getShangwuzuoNumber(i)
    else:
        print "命令 :"
        print "    python %s [TIME] [FROM] [TO] [CDN]" % (sys.argv[0])
        print "参数 : "
        print "    [TIME] : 出发的日期 (今天|明天|后天|7天后|2017-02-26)"
        print "    [FROM] : 出发地的中文名 , 支持模糊查询"
        print "    [TO] : 目的地的中文名 , 支持模糊查询"
        print "    [CDN] : 使用何地的CDN服务器(即网站的IP地址 , 可以通过 ping kyfw.12306.cn 获得)(123.123.123.123|kyfw.12306.cn)(如果使用本地CDN不能查询到票 , 可以对别的地域进行查询)"
示例#15
0
#!/usr/bin/env python
# coding: utf-8

from __future__ import division
from __future__ import print_function

import igraph
import price

# Define variables
sv = 3  # starting vertices
at = .8  # attractivity
ns = 20  # network size
""" Create a graph, and print out its properties
"""
p = price.price(sv, at, ns)

# Summary
print()
print("Starting vertices: ", sv)
print("Attractivity: ", at)
print("Network size: ", ns)
print()

print("vcount: ", p.vcount())
print("ecount: ", p.ecount())

print("directed: ", p.is_directed())

print("indegree: ", p.indegree())
print("outdegree:", p.outdegree())