Exemple #1
0
def rank():
    Database.setup()
    gamer_count = Database.get_all(document="game").count()
    sort_amount = {}
    for index in range(0, gamer_count):
        temp_name = Database.get_all(document="game")[index]["name"]
        Gamer.update_amount(temp_name)
    for index in range(0, gamer_count):
        sort_amount[Database.get_all(
            document="game")[index]["name"]] = Database.get_all(
                document="game")[index]["amount"]
    # print(sort)
    sorted_amount = sorted(sort_amount.items(),
                           key=lambda kv: kv[1],
                           reverse=True)
    print(sort_amount)
    print(sorted_amount)
    return sorted_amount
Exemple #2
0
def get_reminder():
    sources = Database.get_all(document="users")
    emails = []
    for user in sources:
        emails.append(user["email"])
    print(emails)
    currencylist, poslist = Source.get_currency()
    for email in emails:
        reminders = Database.find(document="all_alert",
                                  new_record={"email": email})
        currencies = []
        for reminder in reminders:
            #print(reminder)
            #print(reminder["price"])
            # print(pos)
            # print(pos['A'])
            #print(float(currencylist[pos[reminder["currency"]]].buy_rate))
            if currencylist[poslist[reminder["currency"]]].sell_rate != None:
                if float(currencylist[poslist[reminder["currency"]]].sell_rate
                         ) >= float(reminder["price"][0]):
                    if reminder["currency"] not in currencies:
                        currencies.append(reminder["currency"])
                    else:
                        pass
                else:
                    pass
            elif currencylist[poslist[reminder["currency"]]].buy_rate != None:
                if float(currencylist[poslist[reminder["currency"]]].buy_rate
                         ) <= float(reminder["price"][1]):
                    if reminder["currency"] not in currencies:
                        currencies.append(reminder["currency"])
                    else:
                        pass
                else:
                    pass
            else:
                pass

            #             currencies.append(user_alert["currency"])
            #         else:
            #             pass
            #             else:
            #                 pass
            #         else:
            #             pass
            #     else:
            #         pass
            #         else:
            #             pass
            #     else:
            #         pass
            # else:
            #     pass
        print(currencies)
        print(str(currencies).strip("[]"))
        print(email, ":", currencies)
        if len(currencies):
            requests.post(
                "https://api.mailgun.net/v3/sandbox1a5c1ed6074a4b759c651994f7509e55.mailgun.org/messages",
                auth=("api",
                      "1b0576f57d49e0faa17b43365cd39117-f696beb4-a9a6bd6b"),
                data={
                    "from":
                    "Mailgun Sandbox <*****@*****.**>",
                    "to":
                    "Alan Chen <*****@*****.**>",
                    # "to": user,
                    "subject":
                    "Currency Reminder",
                    "text":
                    "Dear user, your interested rate for {} has been reached!".
                    format(str(currencies).strip("[]"))
                })


# Database.initialize()
# check_alert()
Exemple #3
0
from backends.database import Database

Database.setup()

print(Database.match(document="test", new_record={"name": "dolly"}))
print(Database.find(document="test", new_record={"age": "3"}))
print(Database.get_all(document="test"))
print(Database.get_all(document="test")[0]['name'])
print(Database.get_all(document="test")[1])
Exemple #4
0
from backends.database import Database
from backends.gamer import Gamer

Database.setup()
gamer1 = Gamer.new_gamer("gamer1", "*****@*****.**")
gamer1.update_gameCurrency("AUD","200","CNY")
print(gamer1.get_message())
print(Database.get_all(document="game").count())
print(Database.get_all(document="game")[0])
print(Database.get_all(document="game")[0]["amount"])



# for gamer in Database.get_all(document="game"):
#     print(gamer.get_email())