Example #1
0
    def init():

        from items import Item
        from classes import Class, Subclass
        from pets import Pet
        from mounts import Mount

        weapon_class = Class(operation, request, 2)
        battle_pet_class = Class(operation, request, 17)
        misc_class = Class(operation, request, 15)
        staff_subclass = Subclass(operation, request, 2, 10)
        pet_subclass = Subclass(operation, request, 17, 0)
        mount_subclass = Subclass(operation, request, 15, 5)

        existing_pet = Pet(operation, request, 40)
        existing_mount = Mount(operation, request, 240)

        new_item_item = Item(operation, request, 25)
        new_item_pet = Item(operation, request, 82800, pet_data={"_id":39, "quality":3, "level":1, "breed_id":5})
        new_item_mount = Item(operation, request, 34060)
        new_items = (new_item_item, new_item_pet, new_item_mount)

        rebuild_item_item = Item(**{"_id":35, "pet":{"_id":0}, "mount":{"_id":0}, "level":1, "name":"Bent Staff", "quality":"Common", "item_class":2, "item_subclass":10, "type":"TWOHWEAPON", "subtype":"Two-Hand", "sold":0, "price":0, "mean_price":0, "Pet":None, "Mount":None, "Class":weapon_class, "Subclass":staff_subclass})
        rebuild_item_pet = Item(**{"_id":82800, "pet":{"_id":40}, "mount":{"_id":0},"level":25, "name":"Pet Cage", "quality":"Rare", "item_class":17, "item_subclass":0, "type":"NON_EQUIP", "subtype":"Non-equippable", "sold":0, "price":0, "mean_price":0, "Pet":existing_pet, "Mount":None, "Class":battle_pet_class, "Subclass":pet_subclass})
        rebuild_item_mount = Item(**{"_id":41058, "pet":{"_id":0}, "mount":{"_id":240},"level":30, "name":"Mechano-Hog","quality":"Epic", "item_class":15, "item_subclass":5, "type":"NON_EQUIP", "subtype":"Non-equippable", "sold":0, "price":0, "mean_price":0, "Pet":None, "Mount":existing_mount, "Class":misc_class, "Subclass":mount_subclass})
        rebuild_items = (rebuild_item_item, rebuild_item_pet, rebuild_item_mount)

        return new_items, rebuild_items
Example #2
0
def update_pets(id):
    pet = Pet.find(redis, id)
    if pet:
        payload = request.get_json()
        if Pet.validate(payload):
            pet = Pet.from_dict(payload)
            pet.save(redis)
            message = pet.serialize()
            rc = HTTP_200_OK
        else:
            message = { 'error' : 'Pet data was not valid' }
            rc = HTTP_400_BAD_REQUEST
    else:
        message = { 'error' : 'Pet %s was not found' % id }
        rc = HTTP_404_NOT_FOUND

    return make_response(jsonify(message), rc)
Example #3
0
def editing(chosen_pet: Pet):
    print(f"You have chosen to edit {chosen_pet.GetPetName()}.")
    print("Press the enter key at the prompt if you would like to keep the current value.")
    new_name = input("New name: ")
    if new_name.lower() == "quit":
        print("Exiting the Pet Chooser...")
        return True
    new_age = input("New age: ")
    if new_age.lower() == "quit":
        print("Exiting the Pet Chooser...")
        return True

    if new_name == "":
        print("Name of pet not changed.")
    # Do not allow integer names
    elif new_name.isnumeric() == True:
        print("Name of pet must not be a number. Name not changed.")
    else:
        print(chosen_pet.GetID())
        name_update = f"update pets set name = '{new_name}' where id = {chosen_pet.GetID()};"
        myConnection.cursor().execute("use pets;")
        myConnection.cursor().execute(name_update)
        myConnection.commit()
        print(f"Pet's name successfully updated to {new_name}")

    if new_age == "":
        print("Age of pet not changed.")
    # Do not allow non positive integer ages
    elif new_age.isnumeric() == False:
        print("Invalid age entered. Age not updated.")
    else:
        age_update = f"update pets set age = '{new_age}' where id = {chosen_pet.GetID()};"
        myConnection.cursor().execute(age_update)
        myConnection.commit()
        print(f"Pet's age successfully updated to {new_age}")

    # Update class object by pulling updated information from sql server
    sqlSelect = f"select id, name, age from pets where id = {chosen_pet.GetID()};"
    with myConnection.cursor() as cursor:
        cursor.execute(sqlSelect)
        for row in cursor:
            chosen_pet.SetPetName(row['name'])
            chosen_pet.SetPetAge(row['age'])

    # Return false as user did not choose to quit
    return False
Example #4
0
def get_pets(id):
    pet = Pet.find(redis, id)
    if pet:
        message = pet.serialize()
        rc = HTTP_200_OK
    else:
        message = { 'error' : 'Pet with id: %s was not found' % str(id) }
        rc = HTTP_404_NOT_FOUND

    return make_response(jsonify(message), rc)
Example #5
0
def hatch_egg():
	subjects = ["A stranger in the night", "A wild Skitty appears and", "Some rando", "An unladen swallow flies by and somehow"]
	print("No save file found. " + choice(subjects) + " hands you an egg:")

	# newEgg = Pet()
	# petType = newEgg.hatch()
	# petType = Pet.hatch()
	# ourPet = eval(pet_type + "()")
	our_pet = Pet.hatch()
	our_pet.print_pet()
	print("Congratulations! Your new " + our_pet.type + " Pet has hatched!")
	our_pet.rename()
	our_pet.set_level(1)
	our_pet.xp_increase(1)
	return our_pet
Example #6
0
def create_pets():
    id = 0
    payload = request.get_json()
    if Pet.validate(payload):
        pet = Pet(id, payload['name'], payload['category'])
        pet.save(redis)
        id = pet.id
        message = pet.serialize()
        rc = HTTP_201_CREATED
    else:
        message = { 'error' : 'Data is not valid' }
        rc = HTTP_400_BAD_REQUEST

    response = make_response(jsonify(message), rc)
    if rc == HTTP_201_CREATED:
        response.headers['Location'] = url_for('get_pets', id=id)
    return response
Example #7
0
	def __init__(self, name, chases_cats):
		Pet.__init__(self, name, "Dog")
		self.chases_cats = chases_cats
Example #8
0
# Now that we are connected, execute a query
#  and do something with the result set.
try:
    with myConnection.cursor() as cursor:
        # ==================

        # Create list holding each pet object
        pets_list = []

        sqlSelect = """select pets.id, pets.name, pets.age,
             owners.name, types.animal_type 
            from pets join owners on pets.owner_id=owners.id 
            join types on pets.animal_type_id=types.id;"""

        # Execute select
        cursor.execute(sqlSelect)
        for row in cursor:
            # Create pet object for each returned row from sql server and append it to the list
            pets_list.append(Pet(row['name'], row['age'], row['owners.name'], row['animal_type'], row['id']))

        main_menu()
except Exception as e:
    print(f"An error has occurred.  Exiting: {e}")
    print("Thank you for using the Pet Chooser!")
    print()

finally:
    myConnection.close()
    print("Connection closed.")

Example #9
0
 def __init__(self, name, chases_cats):
     Pet.__init__(self, name, "Dog")
     self.chases_cats = chases_cats
Example #10
0
def delete_pets(id):
    pet = Pet.find(redis, id)
    if pet:
        pet.delete(redis)
    return make_response('', HTTP_204_NO_CONTENT)
Example #11
0
def data_load(payload):
    pet = Pet(0, payload['name'], payload['category'])
    pet.save(redis)
Example #12
0
    def init(section=None):
        from mounts import Mount
        from pets import Pet
        from classes import Class, Subclass
        from items import Item
        from auctions import Auction, SoldAuction

        if section == "insert":
            operation.realms = [
                realm,
            ]
            operation.live_data = {
                "auctions": {
                    realm.id: {}
                },
                "items": {
                    82800: {}
                },
                "classes": {},
                "subclasses": {},
                "pets": {},
                "mounts": {}
            }
            [Mount(operation, request, _id) for _id in (69, 85)]
            [Pet(operation, request, _id) for _id in (39, 40)]

            auction_1 = Auction(
                realm, operation, request, False,
                *(10569, 25, {
                    "_id": 0
                }, 1, 52, "SHORT", 24.9, 52))
            auction_2 = Auction(
                realm, operation, request, False,
                *(10570, 35, {
                    "_id": 0
                }, 1, 68, "MEDIUM", 62.5, 68))
            auction_2.time_posted = auction_2.time_posted - datetime.timedelta(
                hours=1)
            auction_2.last_updated = auction_2.time_posted

            operation.insert_data["auctions"][realm.id] = [
                auction_1, auction_2
            ]
            operation.live_data["auctions"][realm.id] = {
                10569: auction_1,
                10570: auction_2
            }

            sold_auction = SoldAuction(
                operation, False,
                *(auction_2, 10570, 35, {
                    "id": 0
                }, 1, 68, "MEDIUM", 62.5, 68, auction_2.time_posted, False))
            operation.insert_data["sold_auctions"][realm.id] = [sold_auction]

        elif section == "update":
            operation.update_data = {"auctions": {}}
            time = dt.now()
            item = operation.live_data["items"][25]
            auction = operation.live_data["auctions"][realm.id][10569]
            auction.last_updated = time
            item.mean_price = 1

            operation.update_data["items"] = [
                item,
            ]
            operation.update_data["auctions"][realm.id] = [
                auction,
            ]
Example #13
0
#!/usr/bin/python

from pets import Pet

mydog=Pet("Bobby","dog")

print "My petname is",mydog.getName()
print "My pet is a",mydog.getSpecies()
print "Info summary:",mydog.__str__()

print "Second way to obtain name:",Pet.getName(mydog)

print mydog

mydog.age=5

if hasattr(mydog,'age'):
 print "Dog age is",mydog.age

print "=" * 20

mycat=Pet("Michy","cat")
print mycat

myhorse=Pet("Mr.T","horse")
print myhorse
Example #14
0
from pets import Pet

boby = Pet("Boby", "dog")
print "Name: %s" % boby.getName()
print "Specie: %s" % boby.getSpecies()
print boby

print boby.num_of_pets
from pets import Pet

# Create an instance of pet

ginger_cat = Pet("Ginger", "Cat")

print(ginger_cat.getName())

print(ginger_cat.getSpecies())

print(ginger_cat)


yorkshire = Pet("Yorkshire Terrier", "Dog")

print(yorkshire.getName())

print(yorkshire)
Example #16
0

def show_commands(commands):
	title = "------ Python Pet, version " + str(VERSION) + " ------"
	print(title)
	print("Author:  Emilie Barnard")
	print("Website: emilie.codes")
	print()
	print("Type 'help' to see this list.")
	#print("Type 'help name' to find out more about the command 'name'.")
	print()
	col_width = max(map(len,commands)) + 1
	for command in sorted(commands.keys()):
		print("%s %s" % ((command + ":").ljust(col_width), commands[command]))
		# print(col_width)
	print("-" * len(title))


# Only runs if this was the file run as the main module
if __name__ == "__main__":
	main()



#testing
x = Pet()
x.print_pet()
print(x.type)
print(x.name)
x.xp_increase(12)
Example #17
0
try:
    with myConnection.cursor() as cursor:
        # ==================

        # Create list holding each pet object
        pets_list = []

        sqlSelect = """select pets.id, pets.name, pets.age,
             owners.name, types.animal_type 
            from pets join owners on pets.owner_id=owners.id 
            join types on pets.animal_type_id=types.id;"""

        # Execute select
        cursor.execute(sqlSelect)

        for row in cursor:
            # Create pet object for each returned row from sql server and append it to the list
            pets_list.append(
                Pet(row['name'], row['age'], row['owners.name'],
                    row['animal_type']))

        menu()
except Exception as e:
    print(f"An error has occurred.  Exiting: {e}")
    print("Thank you for using the Pet Chooser!")
    print()

finally:
    myConnection.close()
    print("Connection closed.")
Example #18
0
        self.chases_cats = chases_cats

    def chasesCats(self):
        return self.chases_cats

class Cat(Pet):

    def __init__(self, name, hates_dogs):
        Pet.__init__(self, name, "Cat")
        self.hates_dogs = hates_dogs

    def hatesDogs(self):
        return self.hates_dogs
    
from pets import Pet, Dog
mister_pet = Pet("Mister", "Dog")
mister_dog = Dog("Mister", True)
isinstance(mister_pet, Pet)
True
isinstance(mister_pet, Dog)
False
isinstance(mister_dog, Pet)
True
isinstance(mister_dog, Dog)
True

from pets import Cat, Dog
fido = Dog("Fido", True)
rover = Dog("Rover", False)
mittens = Cat("Mittens", True)
fluffy = Cat("Fluffy", False)
from pets import Pet

# Create an instance of pet

ginger_cat = Pet("Ginger", "Cat")

print(ginger_cat.getName())

print(ginger_cat.getSpecies())

print(ginger_cat)

yorkshire = Pet("Yorkshire Terrier", "Dog")

print(yorkshire.getName())

print(yorkshire)
Example #20
0
    def __init__(self,
                 operation=None,
                 request=None,
                 _id=None,
                 pet_data=None,
                 test=False,
                 **kwargs):
        """constructor for Item class"""

        insert_new_item = operation is not None and not kwargs
        insert_item = operation is not None and kwargs
        test_item = test
        rebuild_item = operation is None and kwargs

        if test_item:
            self.id = _id
            self.kwargs = self.setData(operation, request, None, test=True)

        elif rebuild_item or insert_item:
            self.pet_id = kwargs["pet"]["_id"]
            self.mount_id = kwargs["mount"]["_id"]
            self.name = kwargs["name"]
            self.level = kwargs["level"]
            self.quality = kwargs["quality"]
            self.class_id = kwargs["item_class"]
            self.subclass_id = kwargs["item_subclass"]
            self.type = kwargs["type"]
            self.subtype = kwargs["subtype"]
            self.sold = kwargs["sold"]
            self.price = kwargs["price"]
            self.mean_price = kwargs["mean_price"]

            if rebuild_item:
                self.id = _id
                self.Pet = kwargs["Pet"]
                self.Mount = kwargs["Mount"]
                self.Class = kwargs["Class"]
                self.Subclass = kwargs["Subclass"]

        elif insert_new_item:
            self.id = _id
            self.Pet = None
            self.Mount = None
            status, data = self.setData(operation, request, pet_data)
            if status:
                new_pet = self.id == 82800 and self.pet_id not in operation.live_data[
                    "pets"]
                existing_pet = self.id == 82800 and self.pet_id in operation.live_data[
                    "pets"]
                new_class = self.class_id not in operation.live_data["classes"]
                existing_class = self.class_id in operation.live_data[
                    "classes"]
                new_subclass = self.class_id not in operation.live_data[
                    "classes"] or self.subclass_id not in operation.live_data[
                        "classes"][self.class_id].subclasses
                existing_subclass = self.class_id in operation.live_data[
                    "classes"] and self.subclass_id in operation.live_data[
                        "classes"][self.class_id].subclasses
                new_mount = not self.mount_id == 0 and self.mount_id not in operation.live_data[
                    "mounts"]
                existing_mount = not self.mount_id == 0 and self.mount_id in operation.live_data[
                    "mounts"]

                if new_pet:
                    self.Pet = Pet(operation, request, self.pet_id)
                    operation.live_data["pets"][self.pet_id] = self.Pet

                elif existing_pet:
                    self.Pet = operation.live_data["pets"][self.pet_id]

                elif new_mount:
                    self.Mount = Mount(operation, request, self.mount_id)
                    operation.live_data["mounts"][self.mount_id] = self.Mount

                elif existing_mount:
                    self.Mount = operation.live_data["mounts"][self.mount_id]

                if new_class:
                    self.Class = Class(operation, request, self.class_id)
                    operation.live_data["classes"][self.class_id] = self.Class

                elif existing_class:
                    self.Class = operation.live_data["classes"][self.class_id]

                if new_subclass:
                    self.Subclass = Subclass(operation, request, self.class_id,
                                             self.subclass_id)
                    operation.live_data["classes"][self.class_id].subclasses[
                        self.subclass_id] = self.Subclass

                elif existing_subclass:
                    self.Subclass = operation.live_data["classes"][
                        self.class_id].subclasses[self.subclass_id]

                self.insert(operation)
                return

            if status == False:
                operation.logger.log(
                    True, msg="Encountered an item without data from api")
                self.id = data["id"]
                self.pet_id = data["pet_id"]
                self.mount_id = data["mount_id"]
                self.name = ""
                self.level = data["level"]
                self.quality = ""
                self.class_id = 0
                self.subclass_id = 0
                self.type = ""
                self.subtype = ""
                self.sold = 0.0
                self.price = 0.0
                self.mean_price = 0.0

                self.insert(operation)
                return