예제 #1
0
    def update_score(self, blob_score, pos_vader_score, neg_vader_score,
                     nuetral_vader_score, compound_vader_score):
        #self._sentiment = self._sentiment + score

        # Totals are string because maximum int size would be exceeded in
        # timeframe.
        self.total_tweets = str(int(self.total_tweets) + 1)
        self.blob_score_total = str(int(self.blob_score_total) + round(blob_score))
        self.pos_vader_score_total = str(int(self.pos_vader_score_total) + round(pos_vader_score))
        self.neg_vader_score_total = str(int(self.neg_vader_score_total) + round(neg_vader_score))
        self.nuetral_vader_score_total = str(int(self.nuetral_vader_score_total) + round(nuetral_vader_score))
        self.compound_vader_score_total = str(int(self.compound_vader_score_total) + round(compound_vader_score))
        vals = (
            (blob_score, "blob_score_range_count_"),
            (pos_vader_score, "pos_vader_score_range_count_"),
            (neg_vader_score, "neg_vader_score_range_count_"),
            (nuetral_vader_score, "nuetral_vader_score_range_count_"),
            (compound_vader_score, "compound_vader_score_range_count_"),
        )
        for score, prefix in vals:
            key = prefix + self._range(score)
            count = int(getattr(self, key))
            setattr(self, key, str(count + 1))

        session.add(self)
        session.commit()
예제 #2
0
def populate():
    p1 = Person('Alice')
    p2 = Person('Anamika')
    p3 = Person('Annie')
    p4 = Person('Anson')
    p5 = Person('Bob')
    p6 = Person('Carol')
    p7 = Person('Don')
    p8 = Person('Evi')

    session.add_all([p1, p2, p3, p4, p5, p6, p7, p8])

    orders = [(p1, 'veggies', 120), (p2, 'veggies', 20), (p3, 'veggies', 120),
              (p4, 'veggies', 10), (p5, 'veggies', 280), (p1, 'ketchup', 80),
              (p1, 'spices', 220), (p1, 'tissues', 50), (p1, 'notebooks', 90),
              (p5, 'ketchup', 80)]
    for person, name, price in orders:
        order = Order(person, name, price)
        session.add(order)

    p1 = Project('BSNL billing', 'alice')
    p2 = Project('BSNL payroll', 'bob')
    p3 = Project('ABC Institute', 'bob')

    pu1 = ProjectUser(p1, 'alice')
    pu2 = ProjectUser(p1, 'carol')
    pu3 = ProjectUser(p1, 'don')
    pu4 = ProjectUser(p2, 'alice')
    pu5 = ProjectUser(p2, 'carol')
    pu6 = ProjectUser(p3, 'don')
    pu7 = ProjectUser(p3, 'carol')

    session.add_all([p1, p2, p3, pu1, pu2, pu3, pu4, pu5, pu6, pu7])

    session.commit()
예제 #3
0
def main():
    c = Coord(id="test", x=0, y=0)
    print("c: " + str(coord_schema.dump(c).data))
    session.add(c)
    session.commit()
    coords = session.query(Coord).all()
    print("all: " + str(coords_schema.dump(coords).data))
    if len(sys.argv) > 1 and sys.argv[1] == "exit":
        return
    bottle.run(server='gunicorn', host='127.0.0.1', port=5000)
예제 #4
0
def create_coord():
    data = request.json

    coord = Coord(id=data['id'], x=data['x'], y=data['y'])
    session.add(coord)
    session.commit()

    response.headers['Content-Type'] = 'application/json'
    print(coord_schema.dump(coord).data)
    return coord_schema.dump(coord).data
예제 #5
0
def create_user_currency(user_id, short_code):
    """
        Creates a currency for the user. Returns the created currency or None if not exists.
    """

    currency = UserCurrency(user_id=user_id, short_code=short_code, amount=0)
    session.add(currency)
    session.commit()

    return currency
예제 #6
0
def create_user_bet(user_id, bet_id, deposit):
    """
        Creates a currency for the user. Returns the created currency or None if not exists.
    """

    user_bet = UserBet(user_id=user_id, bet_id=bet_id, deposit=deposit)
    session.add(user_bet)
    session.commit()

    return user_bet
예제 #7
0
def create_bet(created_by, bet, rate):
    """
        Creates a currency for the user. Returns the created currency or None if not exists.
    """

    bet = Bet(created_by=created_by, bet=bet, rate=rate)
    session.add(bet)
    session.commit()

    return bet
예제 #8
0
def create_system_variable(variable, value):
    """
        Creates and returns a system variable with given arguments.
    """

    variable = System(variable=variable, value=value)
    session.add(variable)
    session.commit()

    return variable
예제 #9
0
def give_role_to_user(user_id, role_id):
    """
        Gives a role to the user in database and Discord. Returns the given role or None if failed.
    """

    role = UserRole(user_id=user_id, role_id=role_id)

    session.add(role)
    session.commit()

    return role
예제 #10
0
def create_user(discord_id):
    """
        Creates a new user in the database. Returns the created user or None if failed.
    """

    user = User(discord_id=discord_id, creation_date=get_current_date())

    session.add(user)
    session.commit()

    return user
예제 #11
0
def update_currencies():
    """
        Downloads all available currencies and prepares the database.
    """

    response = get("http://apilayer.net/api/live?access_key=%s" %
                   (Config.APILAYER_KEY)).json()

    for currency_code in response["quotes"].keys():
        currency = get_currency(short_code=currency_code[3:]).first()

        if not currency:
            currency = Currency(short_code=currency_code[3:])
            session.add(currency)
            session.commit()

        currency.value = response["quotes"][
            currency_code] / Config.CURRENCY_DIVIDER
        currency.last_update = get_current_date()
        session.commit()