Ejemplo n.º 1
0
def cheapestFlightResponse(variables):

    outOf = variables['from']
    to = variables['to']
    leaves = convertDate.convertDate(variables['date'])
    outOf = getAirportCode.getAirportCode(outOf)
    to = getAirportCode.getAirportCode(to)

    flightJson = getFlights.getCheapestFlights(outOf, to, leaves)
    if "message" in flightJson.keys():
        return [flightJson['message']]


    outputList = []
    for result in flightJson.get("results", [])[:3]:
        price = result.get("fare", {}).get("total_price", "Unknown")
        for flights in result.get("itineraries", []):
            connecting = flights.get("outbound", {}).get("flights", [])
            isConnecting = "Connecting Flight" if len(connecting) > 1 else "Non Stop"
            builtFlight = "Price: {}\n{}\n".format( price, isConnecting)
            for flight in connecting:
                aircraftType  = flight.get("aircraft", "Unknown")
                leaves_at = toDate.toDate(flight.get("departs_at", "Unknown"))
                seatsRemaining = flight.get("booking_info", {}).get("seats_remaining", "Unknown")
                travel_class = flight.get("booking_info", {}).get("travel_class", "Unknown")
                destination = codeToFullName(flight.get("destination", {}).get("airport", "Unknown"))
                flightNumber = flight.get("flight_number", "Unknown")
                airline = flight.get("operating_airline", "Unknown")
                origin = codeToFullName(flight.get("origin", {}).get("airport", "Unknown"))
                terminal = flight.get("origin", {}).get("terminal", "Unknown")
                flightInfo = """
Aircraft: {}
Departing at: {}
Seats Remaining: {}
Class: {}
Origin: {}
Destinaton: {}
Flight Number: {}
Airline: {}
Terminal: {}

                """.format(aircraftType, leaves_at, seatsRemaining, travel_class, origin, destination, flightNumber, airline, terminal)
                builtFlight += flightInfo
            outputList.append(builtFlight)
    return outputList
Ejemplo n.º 2
0
import random

# ここに卒論書いてる人の名前入れる
user = [ "mickey24" ]

# .user/twdataは自分で作ったアカウントのuserとpasswd入れてね
userdata = simplejson.loads(open(".user/twdata","r").read())
t = twitterscraping.Twitter(userdata)
latest = datetime.datetime.now()
for u in user:
	twitList = t.getWithUser(u)
	for uu in twitList:
		if True:
			print uu[0],
			print ":",
			print uu[1].encode("utf-8"),
			print toDate.toDate(uu[2])

		# 最終更新時刻以前のログはカット
		# timedelta内引数かえると過去n以内の発言に引っかかるようにする
		if latest - toDate.toDate(uu[2]) > datetime.timedelta(minutes =10) :
			print "pass"
			continue;

		print "hit"
		strResult = "@"+uu[0]+" "
		strResult += random.choice([u"論文かけ",u"あともうちょっとよ!",u"ほーらかかんか",u"dn"])
		strResult = strResult.encode('utf-8')
		t.put(unicode(strResult,'utf-8','ignore'))
		break
Ejemplo n.º 3
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import toDate,datetime

date = "2008-02-24T06:39:37+00:00"
apiDate = "Thu Jan 22 05:19:28 +0000 2009" 
apiFormat = "%a %b %d %H:%M:%S +0000 %Y"
scrapingFormat = "%Y-%m-%dT%H:%M:%S+00:00"
print toDate.toDate(apiDate,apiFormat)
print datetime.datetime.today()
	

Ejemplo n.º 4
0
def inspirationFlightResponse(comingFrom, date, price, duration=None):

    outOf = comingFrom
    leaves = convertDate.convertDate(date)
    money = price

    if duration is not None:
        flightJson = getFlights.getInspirationFlights(outOf, leaves, price,
                                                      duration)
    else:
        flightJson = getFlights.getInspirationFlights(outOf, leaves, price)

    if "message" in flightJson.keys():
        return [flightJson['message']]

    outputList = []
    listToSort = []
    currentPrice = 99999999.00

    for result in flightJson.get("results", [])[:3]:  #This is fine
        price = result.get("price", "Unknown")
        airline = result.get("airline", "Unknown")
        leaves_at = toDate.toDate(result.get("departure_date", "Unknown"))
        to = result.get("destination", "Unknown")
        come_back = toDate.toDate(result.get("return_date", "Unknown"))

        flightInfo = """

    Price: {}
    Airline: {}
    Departing on: {}
    Origin: {}
    Destinaton: {}
    Return Date: {}

        """.format(price, airline, leaves_at, outOf, to, come_back)

        # For cheapesst flight out of all fo them
        # if float(price) < float(currentPrice):
        #     # print(price)
        #     currentPrice = price
        #     if len(outputList) != 0:
        #         outputList.pop()
        #     else:
        #         outputList.append(flightInfo)

        #For first x number of the list
        listToSort.append(price)

    listToSort.sort()
    # Sort in greatest to least order
    listToSort[:3]  # First 3 elements of the list of prices

    for num in listToSort:
        for element in flightJson.get("results", []):
            if num == element.get("price"):
                price = element.get("price", "Unknown")
                airline = element.get("airline", "Unknown")
                leaves_at = toDate.toDate(
                    element.get("departure_date", "Unknown"))
                to = element.get("destination", "Unknown")
                come_back = toDate.toDate(element.get("return_date",
                                                      "Unknown"))

                flightInfo = """

            Price: {}
            Airline: {}
            Departing on: {}
            Origin: {}
            Destinaton: {}
            Return Date: {}

                """.format(price, airline, leaves_at, outOf, to, come_back)

                outputList.append(flightInfo)

    return outputList