Beispiel #1
0
def make_message(channel, timestamp, nickname, text):
    # (message "{channel}" {unix timestamp} "{nickname}" "{text}")
    root = Compound([
        Identifier("message"),
        String(channel),
        Number(int(timestamp)),
        String(nickname),
        String(text),
    ])

    return str(root) + '\n'
Beispiel #2
0
class RouteRun(Base):
    __tablename__ = tb_routes

    id = Column(Integer, Sequence(route_id), primary_key=True)
    name = Column("name", String(50), nullable=False)
    location = Column("location", String(30), nullable=False)
    distance = Column("distance", Float, nullable=False)

    # self representation
    def __repr__(self):
        return "New Route for Running:\n%s\n%s\n%.2f" % (
            newR.name, newR.location, newR.distance)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_routes)

    # new Route for running
    @classmethod
    def new(self):
        print()
        newR = RouteRun()
        # Ask for Name of Route
        newR.name = input("Enter Name of Route: ")
        # Ask for Location
        newR.location = input("Enter Location: ")
        # Ask for distance of Route & convert distance to Float
        newR.distance = convertStringToFloat(
            input("Enter Distance of Route in km: "))
        # Print what was entered
        horizontalSeperator()
        print("New Route for Running:\n%s\n%s\n%.2f" %
              (newR.name, newR.location, newR.distance))
        # Ask if User wants to save new route
        saveNewInput("Route for Running", newR)

    # selecting a Sport from the list in postgreSQL
    @classmethod
    def select(self):
        routes = readTableFromDB(tb_routes)
        print(tabulate(routes, headers="keys", tablefmt="psql"))
        while True:
            selection = input("Select Route: ")
            selection = int(selection)
            if selection in sports:
                break
            else:
                invalidInput()
        return selection
Beispiel #3
0
class Mountain(Base):
    __tablename__ = tb_mountains

    id = Column(Integer, Sequence(mountain_id), primary_key=True)
    name = Column("name", String(80), nullable=False)
    mrange = Column("mountainrange", String(50))
    elevation = Column("elevation", Integer, nullable=False)

    mtype_id = Column(Integer, ForeignKey("%s.id" % (tb_mtype)))
    mtype = relationship("MountainType")

    country_id = Column(Integer, ForeignKey("%s.id" % (tb_country)))
    country = relationship("Country")

    # self representation
    def __repr__(self):
        return "<Mountains (id = '%s', name='%s', country='%s', mountainrange='%s', elevation='%s', mountaintype='%s')>" % (
            self.id, self.name, self.country.name, self.mrange, self.elevation,
            self.mtype.name)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        countries = readTableFromDB(tb_country)
        mountains = readTableFromDB(tb_mountains)
        mtype = readTableFromDB(tb_mtype)
        mountains["mname"] = mountains.mtype_id.map(mtype.name.to_dict())
        mountains["country"] = mountains.country_id.map(
            countries.code.to_dict())
        return mountains

    # new Mountain
    @classmethod
    def new(self):
        print()
        newM = Mountain()
        # Ask for Name of Route
        newM.name = input("Enter Name of Summit: ")
        # Ask for Location
        newM.countrycode = input("Enter Countrycode: ")
        # Ask for distance of Route
        newM.mrange = input("Enter Mountainrange: ")
        # Ask for distance of Route
        newM.elevation = input("Enter Elevation: ")
        # Ask for distance of Route
        newM.mtype = input("Enter Mountaintype (Pass, Mountain, Vulcan): ")
        # Print what was entered
        horizontalSeperator()
        print("New Mountain:\n%s" % (newM.name))
        saveNewInput("mountain", newM)
Beispiel #4
0
def parser(token):
    if token == '':
        return Atom('')

    if type(token) == list:
        if len(token) == 0:
            raise Exception("empty compounds not allowed")

        return Compound([parser(x) for x in token])

    if type(token) == str:
        if len(token) >= 2 and token[0] == '"' and token[-1] == '"':
            return String(token[1:-1])

        if token == '#f':
            return Boolean(False)

        if token == '#t':
            return Boolean(True)

        num = maybe_number(token)
        if num is not None:
            return Number(num)

        if is_identifier(token):
            return Identifier(token)

    raise Exception(f"invalid token: {token}")
Beispiel #5
0
class Country(Base):
    __tablename__ = tb_country

    id = Column(Integer, Sequence(country_id), primary_key=True)
    name = Column("name", String(80), nullable=False)
    code = Column("code", String(5), nullable=False)

    # self representation
    def __repr__(self):
        return "<Country (id = '%s', name='%s', countrycode='%s')>" % (
            self.id, self.name, self.code)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_country)
Beispiel #6
0
def parser(token):
    if token == '':
        return Atom('')

    if type(token) == list:
        ## What about empty compounds, are they allowed by the grammar?
        return Compound([parser(x) for x in token])

    if type(token) == str:
        if len(token) >= 2 and token[0] == '"' and token[-1] == '"':
            return String(token[1:-1])

        if token == '#f':
            return Boolean(False)

        if token == '#t':
            return Boolean(True)

        num = maybe_number(token)
        if num is not None:
            return Number(num)

        if is_identifier(token):
            return Identifier(token)

    ## Actually nice error messages
    raise Exception(f"invalid token: {token}")
Beispiel #7
0
    def process_string(self):
        position = self.position
        char = self.expr[position]
        if char != "\"":
            return False

        whole_string = "\""

        while True:
            if position + 1 == len(self.expr):
                # at least two chars
                if position == self.position:
                    return False
                # always ends with " if singleton
                if self.expr[position] != "\"":
                    return False

            position += 1
            char = self.expr[position]

            # end of string
            if char == "\"":
                whole_string += "\""
                position += 1
                break

            # special char sequences \" and \\
            elif char == "\\":

                if position + 1 >= len(self.expr):
                    return False

                second_char = self.expr[position + 1]
                if second_char == "\\" or second_char == "\"":
                    # special seq cannot
                    if not position + 2 <= len(self.expr):
                        raise NotParsable
                    if second_char == "\"":
                        if not position + 2 != len(self.expr):
                            raise NotParsable
                    whole_string += self.expr[position:position + 2]
                    position += 1
                else:
                    return False  # standalone '\' not permitted

            else:
                whole_string += char

            # anything else not valid
            # else:
            #     return False

        # if not whole_string:
        #     return False

        self.expressions.append(String(whole_string))
        self.position = position
        return True
Beispiel #8
0
class Difficulty(Base):
    __tablename__ = tb_difficulty

    id = Column(Integer, Sequence(difficulty_id), primary_key=True)
    code = Column("code", String(10), nullable=False)
    description = Column("description", Text)
    sport_id = Column(Integer, ForeignKey("%s.id" % (tb_sport)))

    sport = relationship("Sport")

    # self representation
    def __repr__(self):
        return "<Difficulty (id = '%s', code='%s', sport='%s', description='%s')>" % (
            self.id, self.code, self.sport.name, self.description)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return pd.read_sql_table(tb_difficulty, Engine, index_col="id")

    # new Difficulty
    @classmethod
    def new():
        print()
        newD = Difficulty()
        # Ask for SportID
        newD.sport_id = selectSport()
        # Ask for difficulty code
        newD.code = input("Enter Difficulty Code: ")
        # Ask for description
        newD.description = input("Enter Description: ")
        # Print what was entered
        horizontalSeperator()
        print("New Sport:\n%s" % (newD.name))
        # Ask if User wants to save new sport
        saveNewInput("sport", newD)

    # Query for all and return as panda
    @classmethod
    def select(sport, self):
        # Query from postgreSQL
        dificulties = pd.read_sql_table(tb_difficulty, Engine, index_col="id")
        # Panda comperision
        difficultyBool = difficulty["sport_id"] == sport
        difficulty = difficulty[difficultyBool]
        #print dificulties for Sport
        print(tabulate(difficulty, headers="keys", tablefmt="psql"))
        #Ask for intput
        selection = input("Select difficulty: ")
        selection = int(selection)
        return selection
Beispiel #9
0
class Sport(Base):
    __tablename__ = tb_sport

    id = Column(Integer, Sequence(sport_id), primary_key=True)
    name = Column("Sport", String(30), nullable=False)

    # self representation
    def __repr__(self):
        return "New Sport:\n%s" % (self.name)

    # new Sport
    @classmethod
    def new(self):
        print()
        newSport = Sport()
        # Ask for Name of Sport
        newSport.name = input("Enter Name of Sport: ")
        # Print what was entered
        horizontalSeperator()
        print("New Sport:\n%s" % (newSport.name))
        # Ask if User wants to save new sport
        saveNewInput("sport", newSport)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_sport)

    # selecting a Sport from the list in postgreSQL
    @classmethod
    def select(self):
        print(tabulate(sports, headers="keys", tablefmt="psql"))
        while True:
            selection = input("Select Sport: ")
            selection = int(selection)
            if selection in sports:
                break
            else:
                invalidInput()
        return selection

    # selecting a Sport from the list in postgreSQL
    @classmethod
    def selectName(self, ID):
        selection = readTableFromDB(tb_sport)
        selection = selection.iloc[ID - 1]
        selection = selection['Sport']
        return selection
Beispiel #10
0
class MountainType(Base):
    __tablename__ = tb_mtype

    id = Column(Integer, Sequence(mtype_id), primary_key=True)
    name = Column("name", String(50), nullable=False)

    # self representation
    def __repr__(self):
        return "<Mountain Type (id = '%s', name='%s')>" % (self.id, self.name)

    # new Mountain Type
    @classmethod
    def new(self):
        print()
        newType = MountainType()
        # Ask for Name of Route
        newType.name = input("Enter Type of Mountain: ")
        # Print what was entered
        horizontalSeperator()
        print("New Mountain Type:\n%s" % (newType.name))
        # Ask if User wants to save new Monutain Type
        saveNewInput("mountain type", newType)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_mtype)

    # selecting a Sport from the list in postgreSQL
    @classmethod
    def select(self):
        mtype = readTableFromDB(tb_mtype)
        print(tabulate(routes_in, headers="keys", tablefmt="psql"))
        while True:
            selection = input("Select Mountain Type: ")
            selection = int(selection)
            if selection in mtype:
                break
            else:
                invalidInput()
        return selection
from classes import String

play = String('PLAY', 'ИГРАТЬ')
settings = String('SETTINGS', 'НАСТРОЙКИ')
exit_ = String('EXIT', 'ВЫХОД')
start = String('START', 'НАЧАТЬ ИГРУ')
cancel = String('CANCEL', 'ОТМЕНА')
confirm = String('CONFIRM', 'ПОДТВЕРДИТЬ')
truth = String('TRUTH', 'ПРАВДА')
dare = String('DARE', 'ДЕЙСТВИЕ')
main_menu = String('MAIN MENU', 'ГЛАВНОЕ МЕНЮ')
continue_ = String('CONTINUE', 'ПРОДОЛЖИТЬ')
edit = String('EDIT', 'ИЗМЕНИТЬ')
delete = String('DELETE', 'УДАЛИТЬ')
lang = String('LANGUAGE', 'ЯЗЫК')
rules = String('RULES', 'ПРАВИЛА')
questions = String('QUESTIONS', 'ВОПРОСЫ')
tasks = String('TASKS', 'ЗАДАНИЯ')
back = String('BACK', 'НАЗАД')

player = String('PLAYER', 'ИГРОКА')
question = String('QUESTION', 'ВОПРОС')
task = String('TASK', 'ЗАДАНИЕ')

truth_dare = String('truth or dare?', 'правда или действие?')
title = String('TRUTH OR DARE', 'ПРАВДА ИЛИ ДЕЙСТВИЕ')
enter_player = String('Enter the name of player:', 'Введите имя игрока:')
enter_question = String('Enter the question:', 'Введите текст вопроса:')
enter_task = String('Enter the tasks:', 'Введите текст задания:')
del_confirm = String('DO YOU WANT TO DELETE',
                     'ВЫ ДЕЙСТВИТЕЛЬНО ХОТИТЕ УДАЛИТЬ')
Beispiel #12
0
 def __str__(self):
     exp = Compound([
         Identifier("error"),
         String(self.message),
     ])
     return str(exp)
Beispiel #13
0
def make_error(text):
    # (error "{text}")
    root = Compound([Identifier("error"), String(text)])

    return str(root) + '\n'
Beispiel #14
0
class User(Base):
    __tablename__ = tb_users

    id = Column(Integer, Sequence(user_id), primary_key=True)
    name = Column("name", String(50), nullable=False)
    birthday = Column("birthday", Date, nullable=False)
    male = Column("male", Boolean, nullable=False)
    height = Column("height", Integer, nullable=False)  # in cm

    weights = relationship("Weight", back_populates="user")

    # self representation
    def __repr__(self):
        return "New User:\nName: %s\nBirthday: %s\nMale: %s\nHeight: %s" % (
            self.name, self.birthday, self.male, self.height)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_users, Engine, parse_dates="birthday")

    # Add new user
    @classmethod
    def new(self):
        print()
        newU = User()
        # Ask for Name of User
        newU.name = input("Enter Name of User: "******"Birthday of user %s: " % (newU.name))
        newU.birthday = enterDate()
        # Ask for male or female
        while True:
            i = input("Is the user female or male? (f/m): ")
            if i == "f" or i == "F":
                newU.male = False
                break
            elif i == "m" or i == "M":
                newU.male = True
                break
            else:
                print("Invalid Input! Try again!")
        # Ask for heigt of user
        newU.height = int(
            input("Enter height of user %s (in cm): " % (newU.name)))
        # Print what was entered
        horizontalSeperator()
        print("New User:\nName: %s\nBirthday: %s\nMale: %s\nHeight: %s cm" %
              (newU.name, newU.birthday, newU.male, newU.height))
        # Ask to save or delete
        saveNewInput("User", newU)
        pass

    # selecting a User from the list in postgreSQL
    @classmethod
    def select(self):
        users = readTableFromDB(tb_users, Engine, parse_dates="birthday")
        print(tabulate(users, headers="keys", tablefmt="psql"))
        while True:
            selection = int(input("Select User: "******"Enter weight (in kg): "))
        # Ask for neck circumference
        newW.neck = convertStringToFloat(
            input("Enter neck circumference (in cm): "))
        # Ask for waist circumference
        newW.waist = convertStringToFloat(
            input("Enter waist circumference (in cm): "))
        # Ask for hip circumference
        ## Check if user is male or female

        if self.male == False:
            newW.hip = convertStringToFloat(
                input("Enter hip circumference (in cm): "))
        else:
            newW.hip = 0

        # Print what was entered
        horizontalSeperator()
        if self.male == True:
            print(
                "New Measurements:\nuserID: %s\nDate: %s\nWeight: %.1f kg\nneck: %.1f cm\nwaist: %.1f cm"
                %
                (newW.user_id, newW.date, newW.weight, newW.neck, newW.waist))
        else:
            print(
                "New Measurements:\nUserID: %s\nDate: %s\nWeight: %.1f kg\nNeck: %.1f cm\nWaist: %.1f cm\nHip: %.1f cm"
                % (newW.user_id, newW.date, newW.weight, newW.neck, newW.waist,
                   newW.hip))
        # Ask to save or delete
        while True:
            i = input("Do you want to save the new measurements (Y/N)? ")
            if i == "J" or i == "j" or i == "y" or i == "Y":
                self.weights.append(newW)
                moveToDatabase(self)
                break
            elif i == "n" or i == "N":
                break
            else:
                print("Invalid Input! Try again!")
            pass
        pass