def update_user_by_password(old, new): Database.update_record( document="users", new_record={"password": old}, new_query={"$set": { "password": User.encode_password(new) }})
def setup(): session["email"] = session.get("email") session["name"] = session.get("name") session["password"] = session.get("password") db.setup() # work = BackgroundScheduler(check_alert, "cron", day_of_week="0-4", hour="16", miniute="30") work = BackgroundScheduler() # work.add_job(check_alert, "interval", seconds=10) work.add_job(get_reminder, "interval", seconds=10000000) # work.add_job(check_alert, "cron", day_of_week="0-4", hour="18",minute="1") work.start()
def update_amount(name): currencylist, pos = Source.get_currency() gamer = Gamer.get_gamer_by_name(name) ans = 0 for currency in gamer["gameCurrency"]: temp = convert(currency, "AUD", gamer["gameCurrency"][currency], currencylist, pos) ans += temp ans = float(round(ans, 2)) Database.update_record(document="game", new_record={"name": name}, new_query={"$set": {"amount": ans}}) return ans
def update_gameCurrency(name, from_currency, to_currency, from_amount): currencylist, pos = Source.get_currency() to_amount = convert(from_currency, to_currency, from_amount, currencylist, pos) temp_gameCurrency = Gamer.get_gamer_by_name(name)["gameCurrency"] temp_gameCurrency[from_currency] = float(temp_gameCurrency[from_currency]) - float(from_amount) temp_gameCurrency[to_currency] = float(temp_gameCurrency[to_currency]) + float(to_amount) temp_gameCurrency[from_currency] = float(round(temp_gameCurrency[from_currency], 2)) temp_gameCurrency[to_currency] = float(round(temp_gameCurrency[to_currency], 2)) if temp_gameCurrency[from_currency] < 0: return 0 Database.update_record(document="game", new_record={"name": name}, new_query={"$set": {"gameCurrency": temp_gameCurrency}}) print(Gamer.get_gamer_by_name(name)["gameCurrency"]) Gamer.update_amount(name) return 1
def new_user(name, email, password): match = Database.match(document="users", new_record={"email": email}) if match is not None: return False else: User(name, email, User.encode_password(password)).add_to_database() return True
def validation(email, password): user = Database.match(document="users", new_record={"email": email}) if user is None: return False if User.validation_password(password, user["password"]) is False: return False return True
def new_reminder(email, currency, price): match = Database.match(document="all_alert", new_record={"email": email, "currency": currency}) if match is not None: return False else: Reminder(email, currency, price).add_to_database() return True
def new_watchList(email, currency, code, sell_rate, buy_rate): match = Database.match(document="preference", new_record={ "email": email, "code": code }) if match is not None: return False else: WatchList(email, currency, code, sell_rate, buy_rate).add_to_database() return True
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
def getPassword(email): user = Database.match(document="users", new_record={"email": email}) return user["password"]
def add_to_database(self): Database.add_new(document="all_alert", new=self.to_json())
def get_reminder_by_email(email): return Database.find(document="all_alert", new_record={"email": email})
def update_user_by_email(old, new): Database.update_record(document="users", new_record={"email": old}, new_query={"$set": { "email": new }})
def get_user_by_email(email): return Database.match(document="users", new_record={"email": email})
def update_reminder(email, currency, price): Database.update_record(document="all_alert", new_record={"email":email, "currency": currency}, new_query={"$set": {"price": price}})
def delete_reminder(email, currency): Database.delete_record(document="all_alert", old={"email": email, "currency": currency})
from backends.database import Database from backends.user import User Database.setup() User.update_user_email("*****@*****.**", "*****@*****.**") # User.update_user_email("*****@*****.**", "*****@*****.**") # User.update_user_email("*****@*****.**", "*****@*****.**") # User.update_user_email("*****@*****.**", "*****@*****.**") # User.update_user_email("*****@*****.**", "*****@*****.**")
def add_to_database(self): Database.add_new(document="game", new=self.to_json())
def add_to_database(self): Database.add_new(document="preference", new=self.to_json())
def get_gamer_by_name(name): gamer = Database.match(document="game", new_record={"name": name}) return gamer
def get_watch_list(email): return Database.find(document="preference", new_record={"email": email})
def delete_watchList(email, code): Database.delete_record(document="preference", old={ "email": email, "code": code })
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])
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()
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())