Beispiel #1
0
def main(argv):
    api_url = "https://api.tripit.com"
    consumer_key = "a5c76f91ba397d94a3129a2b86889e11ba998259"
    consumer_secret = "18e27c9af57f274c30347b1740194f06b6442d6b"

    oauth_credential = tripit.OAuthConsumerCredential(
        oauth_consumer_key=consumer_key, oauth_consumer_secret=consumer_secret)
    t = tripit.TripIt(oauth_credential, api_url=api_url)
    pokke = t.get_request_token()
    print pokke
    print "https://www.tripit.com/oauth/authorize?oauth_token=%(oauth_token)s&oauth_callback=https://www.bitlbee.org/main.php/oauth2.html" % pokke

    raw_input(
        "Open that in your browser and hit enter when it's done. (Ignore the bitlbee.org page it forwards you to.)"
    )

    oauth_credential = tripit.OAuthConsumerCredential(
        consumer_key, consumer_secret, pokke["oauth_token"],
        pokke["oauth_token_secret"])
    t = tripit.TripIt(oauth_credential, api_url=api_url)
    takke = t.get_access_token()

    print("Pass the following 5 arguments to co2.py, example.py or others:")
    print(" ".join([
        api_url, consumer_key, consumer_secret,
        "%(oauth_token)s %(oauth_token_secret)s" % takke
    ]))
    print("Possibly best to create a co2.sh?")
Beispiel #2
0
def main(argv):
    if len(argv) < 5:
        print "Usage: example.py api_url consumer_key consumer_secret authorized_token authorized_token_secret"
        return 1

    api_url = argv[0]
    consumer_key = argv[1]
    consumer_secret = argv[2]
    authorized_token = argv[3]
    authorized_token_secret = argv[4]

    oauth_credential = tripit.OAuthConsumerCredential(consumer_key,
                                                      consumer_secret,
                                                      authorized_token,
                                                      authorized_token_secret)
    t = tripit.TripIt(oauth_credential, api_url=api_url)
    ob = t.list_trip([('past', 'true'), ('include_objects', 'true')])
    docs = []
    for otype, values in ob.iteritems():
        if isinstance(values, list):
            print "Processing", otype
            for d in values:
                doc = {'type': otype}
                doc.update(d)
                doc['_id'] = getId(doc)
                cleanup(doc)
                docs.append(doc)

    DB.update(docs)
Beispiel #3
0
def main(argv):
    trip_xml = "<Request><Trip>" \
               "<start_date>2009-12-09</start_date>" \
               "<end_date>2009-12-27</end_date>" \
               "<primary_location>New York, NY</primary_location>" \
               "</Trip></Request>"

    trip_xml2 = "<Request><Trip>" \
                "<start_date>2010-12-09</start_date>" \
                "<end_date>2010-12-27</end_date>" \
                "<primary_location>Boston, MA</primary_location>" \
                "</Trip></Request>"

    if len(argv) < 5:
        print "Usage: make_post_request.py request_url consumer_key consumer_secret access_token access_token_secret"
        return 1

    request_url = argv[0]
    consumer_key = argv[1]
    consumer_secret = argv[2]
    access_token = argv[3]
    access_token_secret = argv[4]

    oauth_credential = tripit.OAuthConsumerCredential(consumer_key,
                                                      consumer_secret,
                                                      access_token,
                                                      access_token_secret)
    t = tripit.TripIt(oauth_credential, api_url=request_url)
    r = t.create(trip_xml)
    print 'RESPONSE: %s' % r
    id = r.get_children()[0].get_attribute_value('id')
    r = t.replace_trip(id, trip_xml2)
    print '\nRESPONSE: %s' % r
Beispiel #4
0
def main(argv):
    if len(argv) < 5:
        print "Usage: example.py api_url consumer_key consumer_secret authorized_token authorized_token_secret"
        return 1
    
    api_url = argv[0]
    consumer_key = argv[1]
    consumer_secret = argv[2]
    authorized_token = argv[3]
    authorized_token_secret = argv[4]

    oauth_credential = tripit.OAuthConsumerCredential(consumer_key, consumer_secret, authorized_token, authorized_token_secret)
    t = tripit.TripIt(oauth_credential, api_url = api_url)
    print t.list_trip()
    print t.response
def main(argv):
    if len(argv) < 5:
        print "Usage: get_authorized_token.py api_url consumer_key consumer_secret request_token request_token_secret"
        return 1

    api_url = argv[0]
    consumer_key = argv[1]
    consumer_secret = argv[2]
    request_token = argv[3]
    request_token_secret = argv[4]

    oauth_credential = tripit.OAuthConsumerCredential(consumer_key,
                                                      consumer_secret,
                                                      request_token,
                                                      request_token_secret)
    t = tripit.TripIt(oauth_credential, api_url=api_url)
    print t.get_access_token()
Beispiel #6
0
def main(argv):
    api_url = ""
    consumer_key = ""
    consumer_secret = ""

    if len(argv) < 3:
        print "Usage: get_request_token.py api_url consumer_key consumer_secret"
        return 1
    else:
        api_url = argv[0]
        consumer_key = argv[1]
        consumer_secret = argv[2]

    oauth_credential = tripit.OAuthConsumerCredential(
        oauth_consumer_key=consumer_key, oauth_consumer_secret=consumer_secret)

    t = tripit.TripIt(oauth_credential, api_url=api_url)
    print t.get_request_token()
Beispiel #7
0
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import getpass
import os
import tripit


def get_credential():
    username = raw_input('Username: '******'Password: '******'https://api.tripit.com'

api_url = os.getenv('API_URL') or 'https://api.tripit.com'
print "api_url: %s" % api_url
cred = get_credential()
t = tripit.TripIt(cred, api_url=api_url)
Beispiel #8
0
def main(argv):
    if len(argv) < 5:
        print("Usage: co2.py api_url consumer_key consumer_secret authorized_token authorized_token_secret")
        return 1

    # Dump xml data in an intermediate file, so if you want to make any
    # changes to the code below, you can test without triggering new API
    # calls on every run. (Just set this if to False.)
    if True:
        api_url = argv[0]
        consumer_key = argv[1]
        consumer_secret = argv[2]
        authorized_token = argv[3]
        authorized_token_secret = argv[4]

        oauth_credential = tripit.OAuthConsumerCredential(consumer_key, consumer_secret, authorized_token, authorized_token_secret)
        t = tripit.TripIt(oauth_credential, api_url = api_url)

        t.list_object({"include_objects": "true", "past": "true", "type": "air"})
        open("flights.xml", "w").write(t.response)

    # Can't believe I still have to deal with decrepit Python2 without
    # ordered dicts!
    columns = [('who',
                ['../Traveler/first_name',
                 '../Traveler/middle_name',
                 '../Traveler/last_name']),
               ('date', 'StartDateTime/date'),
               ('src', 'start_airport_code'),
               ('dst', 'end_airport_code'),
               ('flight', ['marketing_airline_code',
                           'marketing_flight_number']),
               ('aircraft', 'aircraft'),
               ('aircraft_desc', 'aircraft_display_name'),
               ('distance', 'distance'),
               ('class', 'service_class'),
               ('co2', 'Emissions/co2'),
               ('class_exact', ''),
               ('co2_exact', '')]

    parsed = etr.fromstring(open("flights.xml", "r").read())
    out = csv.writer(open("co2.csv", "w"))
    out.writerow([k for k, v in columns])
    for trip in parsed:
        for seg in trip.findall("Segment"):
            ret = {}
            for k, v in columns:
                val = ""
                if not isinstance(v, list):
                    v = [v]
                for path in v:
                    if path.startswith("../"):
                        el = trip.find(path[3:])
                    else:
                        el = seg.find(path)
                    if el is not None:
                        val += el.text
                ret[k] = val
            who = ret["who"]
            # Modify this if your results contain trips of TripIt
            # contacts of yours.
            #if who and not ("wilmer" in who.lower()):
            #    continue
            if ret["distance"].endswith("km"):
                ret["distance"] = re.sub(r"[^0-9]", "", ret["distance"])
            rc = ret["class"].lower()
            if not ret["distance"]:
                # Skip corrupt entries. (Had some from Jeju Air)
                continue
            # Vague attempt at converting at least BA terminology.
            if "club" in rc:
                ret["class_exact"] = "business"
            elif "first" in rc:
                ret["class_exact"] = "first"
            elif "plus" in rc:
                ret["class_exact"] = "premium_economy"
            elif "premium" in rc:
                ret["class_exact"] = "premium_economy"
            elif int(ret["distance"]) > 4000:
                # And then resort to my own rule of never flying economy
                # unless it's short-haul.
                ret["class_exact"] = "premium_economy"
            else:
                ret["class_exact"] = "economy"
            print(ret)
            out.writerow([ret[k] for k, v in columns])   # Yeah seriously man, f*****g Python2..