コード例 #1
0
def run_client():
    resp, s = get_client()
    not_error = [100, 101, 200, 201, 202]
    if resp['response'] not in not_error:
        print(f"error: {resp['response'], resp['alert']}")
    else:
        menu = ["Send data", "Exit"]
        actions = {"1": send_data, "2": exit_program}
        while True:
            print_menu(menu)
            command = get_command(menu)
            actions[command](s)
コード例 #2
0
def main(argv):

    # Make sure we received a target user
    if len(argv) != 2:
        print "usage: python follow_unfollowed_followers.py username"
        sys.exit()

    # create twitter client
    client = get_client()

    # create Twitter...
    twitter = Twitter(client, "state")

    # follow unfollowed followers
    twitter.follow_my_followers(argv[1])
コード例 #3
0
    def post(self):

        data = request.get_json()  # status code
        # Authorize
        # call
        # prepare result
        amadeus_client = config.get_client()
        try:
            '''
            Find best flight offers from Madrid to New York
            '''
            response = amadeus_client.shopping.flight_offers.get(
                origin='MAD', destination='NYC', departureDate='2020-06-01')
            return jsonify({'return': response.data})
        # print(response.data)
        except ResponseError as error:
            raise error
コード例 #4
0
def run_client():
    log.info("Client started")
    resp, s = get_client()
    al = str(resp['alert'])
    print(al)
    not_error = [100, 101, 200, 201, 202]
    if resp['response'] not in not_error:
        log.error("%", al)
        print(f"error: {resp['response'], resp['alert']}")
    else:
        log.info("%s", al)
        menu = ["Send data", "Exit"]
        actions = {"1": send_data, "2": exit_program}
        while True:
            print_menu(menu)
            command = get_command(menu)
            actions[command](s)
コード例 #5
0
def main(argv):

    # Make sure we received target tweet text
    if len(argv) != 2:
        print "usage: python update.py 'status update text'"
        sys.exit()

    UPDATE_TEXT = argv[1]

    # create twitter client
    client = get_client()

    # create Twitter...
    twitter = Twitter(client)

    # post an update
    twitter.update(UPDATE_TEXT)
コード例 #6
0
def main():
    client = config.get_client()
    previous_buckets = get_buckets(client)

    while True:
        time.sleep(SCAN_INTERVAL)
        try:
            buckets = get_buckets(client)
        except boto3.exceptions.botocore.errorfactory.ClientError:
            buckets = None

        if buckets is not None:
            created_buckets, deleted_buckets = compare_buckets(
                previous_buckets, buckets)
            if len(created_buckets) > 0:
                print(created_buckets)

            if len(deleted_buckets) > 0:
                print(deleted_buckets)

            previous_buckets = buckets
コード例 #7
0
ファイル: stan.py プロジェクト: cherdt/sycophant-bot
def main(argv):

    # Make sure we received a target user
    if len(argv) != 2:
        print "usage: python sycophant.py username"
        sys.exit()

    TARGET_USER = argv[1]
    LAST_TWEET = TARGET_USER + "_last_tweet"

    # create twitter client
    client = get_client()

    # create twitter wrapper
    twitter = Twitter(client)

    # open & read target user state file
    last_id = get_last_seen_tweet_id(client, TARGET_USER,
                                     STATE_DIR + LAST_TWEET)

    # Get the user's timeline since the tweet in the target state file
    response = client.api.statuses.user_timeline.get(
        screen_name=str(TARGET_USER),
        since_id=str(last_id),
        exclude_replies='true')

    if len(response.data) > 0:

        last_id = int(response.data[0].id)

        if not response.data[0].favorited:
            twitter.favorite(last_id)

        if not response.data[0].retweeted:
            twitter.retweet(last_id)

        # update the last tweet we've seen
        update_last_seen_tweet_id(STATE_DIR + LAST_TWEET, last_id)
コード例 #8
0
    def post(self):
        # constant variables
        num_of_return_flights = 30

        data_from_frontend = request.get_json()  # status code
        data_from_frontend_dict = dict(data_from_frontend)
        print(data_from_frontend_dict)
        # Authorize
        # call
        # prepare result
        amadeus_client = config.get_client()

        # request data from amadeus
        try:
            '''
            Find best flight offers for outbound flight
            '''
            response_outbound = amadeus_client.shopping.flight_offers.get(
                origin=data_from_frontend_dict['origin'],
                destination=data_from_frontend_dict['destination'],
                departureDate=data_from_frontend_dict['fromDate'])
            '''
            Find best flight offers for inbound flight
            '''
            response_inbound = amadeus_client.shopping.flight_offers.get(
                origin=data_from_frontend_dict['destination'],
                destination=data_from_frontend_dict['origin'],
                departureDate=data_from_frontend_dict['toDate'])
        except ResponseError as error:
            print("Amadeus Error")
            raise error

        # preprocess and filter data
        # data_outbound = response_outbound.data
        trips_outbound_data = []
        trips_inbound_data = []
        # extract data for sending to frontend
        # flights data outbound
        for flight in response_outbound.data:
            trip_outbound_data = {}
            trip_outbound_data["departureOrigin"] = flight["offerItems"][0][
                "services"][0]["segments"][0]["flightSegment"]["departure"][
                    "iataCode"]
            trip_outbound_data["departureDestination"] = self.get_final_dest(
                flight["offerItems"][0]["services"][0]["segments"])
            trip_outbound_data["departureBoardingDateTime"] = flight[
                "offerItems"][0]["services"][0]["segments"][0][
                    "flightSegment"]["departure"]["at"]
            trip_outbound_data["departurePrice"] = str(
                round(
                    float(flight["offerItems"][0]["price"]["total"]) +
                    float(flight["offerItems"][0]["price"]["totalTaxes"]), 2))
            trips_outbound_data.append(trip_outbound_data)
            # print(trips_outbound_data)
        # flights data inbound
        for flight in response_inbound.data:
            trip_inbound_data = {}
            trip_inbound_data["returnOrigin"] = flight["offerItems"][0][
                "services"][0]["segments"][0]["flightSegment"]["departure"][
                    "iataCode"]
            trip_inbound_data["returnDestination"] = self.get_final_dest(
                flight["offerItems"][0]["services"][0]["segments"])
            trip_inbound_data["returnBoardingDateTime"] = flight["offerItems"][
                0]["services"][0]["segments"][0]["flightSegment"]["departure"][
                    "at"]
            trip_inbound_data["returnPrice"] = str(
                round(
                    float(flight["offerItems"][0]["price"]["total"]) +
                    float(flight["offerItems"][0]["price"]["totalTaxes"]), 2))
            trips_inbound_data.append(trip_inbound_data)
        # combine in and outbound flights
        # sort outbount & inbound lists
        trips_outbound_data.sort(key=lambda k: float(k['departurePrice']))
        trips_inbound_data.sort(key=lambda k: float(k['returnPrice']))
        # create all combinations of top X in- and outbound flights
        roundtrip_combinations = self.create_combinations_of_top_x_dictionaries(
            trips_outbound_data, trips_inbound_data,
            math.ceil(math.sqrt(num_of_return_flights)))
        # sort combinations
        roundtrip_combinations.sort(
            key=lambda k: float(k['departurePrice']) + float(k['returnPrice']))
        # return best(first) Y combinations
        #  limit output roundtrips
        roundtrip_combinations_limited = []
        for x in range(0, num_of_return_flights - 1):
            roundtrip_combinations_limited.append(roundtrip_combinations[x])
        # print
        # for round_trip in roundtrip_combinations_limited:
        #     print(round_trip)
        # print(float(round_trip["departurePrice"]) + float(round_trip["returnPrice"]))

        # send data to frontend
        return roundtrip_combinations_limited
コード例 #9
0
ファイル: wumpus.py プロジェクト: cherdt/wumpus-twitter
from state import State
from board import Board
from config import get_client
from birdy.twitter import UserClient
from twitter import Twitter
import re
import random
import sys

state = State("state")
board = Board()
# create twitter client
client = get_client()
# create twitter wrapper
twitter = Twitter(client, "twitter_state")
game_over = False


def is_debug_mode():
    return False


def end_game(msg):
    global game_over
    game_over = True
    state.delete()
    tweet(msg + "\n\nDM me any time to start a new game!")


def tweet(msg):
    if is_debug_mode():
コード例 #10
0
ファイル: client.py プロジェクト: ovevan89/PythonLevel2
from menu import get_command, print_menu
import json


def send_data(sock):
    data = {"text": input("Input text: ")}

    sock.send(json.dumps(data).encode("utf-8"))

    print("the message is sent")


def exit_program(sock):
    sock.send(json.dumps({"exit": ""}).encode("utf-8"))
    print("Exit")
    exit()


if __name__ == "__main__":
    resp, s = get_client()
    not_error = [100, 101, 200, 201, 202]
    if resp['response'] not in not_error:
        print(f"error: {resp['response'], resp['alert']}")
    else:
        menu = ["Send data", "Exit"]
        actions = {"1": send_data, "2": exit_program}
        while True:
            print_menu(menu)
            command = get_command(menu)
            actions[command](s)