From c1fbbb0bd181f719bf50c17349715ba318f9e1e1 Mon Sep 17 00:00:00 2001 From: Lacayo Date: Sat, 18 Mar 2017 14:33:20 -0600 Subject: [PATCH 1/4] Added fullscreen, login now using requests, changed GUI to use mock --- api.py | 75 ++++++++++++++++++++------------------------------------- db.json | 6 +++++ main.py | 64 ++++++++++++++++++++++++------------------------ 3 files changed, 64 insertions(+), 81 deletions(-) diff --git a/api.py b/api.py index 6dc844d..bc53084 100644 --- a/api.py +++ b/api.py @@ -1,56 +1,33 @@ -import urllib.request -import urllib.parse -import urllib.error -import ast import requests -# Important Note: -# the functions here serve to use different APIs -# to change which function is used, navigate to main.py and change the function there -# I (Lacayo) will be using login instead of mock for my GUI until mock is up and running - -api_url = "http://localhost:3000/api/" def get_credit_with_login(username, password): # function using NCAI login to get credit_student and credit_family - - api = 'http://db.nca.edu.ni/api/api_ewapp.php?' - data = { - 'mode': 'student', - 'query': 'login', - 'username': username, - 'password': password, - } - url = api + urllib.parse.urlencode(data) - # data must be encoded for url to function properly - try: - with urllib.request.urlopen(url) as response: - page_raw = response.read() # get page source; but it's encoded - page_str = page_raw.decode() # decode the source; now a string - - if 'null' in page_str: - return "Error with login, please try again." - # when there's a login error, nulls will be present - # we can check a login error by checking for nulls - else: - page_dict = ast.literal_eval(page_str) # evaluate the page str; now it's a python dictionary - credit_student = page_dict['credit_student'] # get value of key 'credit_student' - credit_family = page_dict['credit_family'] # get value of key 'credit_family' - return "Student Credit: ${} \nFamily Credit: ${}".format(credit_student, credit_family) - - except urllib.error.URLError: - return 'No internet connection.' - -# gets an id as param -# returns a dictionary with name, balance, id, and picture in base64 -def get_data(id): + if username in '' or password in '': + return "Please enter a username and password" + api = "http://db.nca.edu.ni/api/api_ewapp.php?mode=student&query=login&username={}&password={}".format(username, password) + response = requests.get(api).json() + if response['login_status'] is 0: + return "Invalid login. Please try again." + return "Your balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) + except requests.exceptions.ConnectionError: + return "Connection unable to be established.\nIs the server online?" + + +def get_credit_with_mock(user_id): try: - response = requests.get(api_url + id).json() - if len(response.keys()) != 0: - return response - else: - return {"id not found": True} - except requests.exceptions.RequestException as e: - print(e) - return {} + api = "http://localhost:3000/api/" + response = requests.get(api + user_id).json() + return "Your balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) + except requests.exceptions.ConnectionError: + return "Connection unable to be established. Is the server online?" + except KeyError: + return "Invalid id. Please try again." + except TypeError: + return "Please enter an id" + + +def get_credit_with_scanner(): + # function for use with the real API system + pass diff --git a/db.json b/db.json index b8f91d5..4afbccf 100644 --- a/db.json +++ b/db.json @@ -1,5 +1,11 @@ { "api":[ + { + "name":"John Doe", + "id":"0", + "credit_student":100.00, + "credit_family":300.00 + }, { "name":"obed miranda", "id":"017770", diff --git a/main.py b/main.py index a2a31c7..a8be546 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import sys import tkinter as tk import api @@ -8,41 +9,40 @@ def __init__(self, master=None): self.master = master self.init_window() # after initial setup; we now setup the window and its parts - def init_window(self): - def display_credit(): # use our get_student_credit function and output it to the balance Tk variable - try: - output = api.get_credit_with_login(entry_username.get(), entry_password.get()) - except SyntaxError: - # This happens when the entries are empty - output = 'Please enter username and password.' - balance.config(text=output) - - def display_data(): - json = api.get_data( entry_id.get() ) - if len(json.keys()) != 0: - try: - text = json["name"] + ": " + str(json["balance"]) - except KeyError as e: - print(e, "key not found in response") - text = "Wrong ID. Try again" - else: - text = "Network Error" + # def init_window(self): + # def display_credit(): # use our get_student_credit function and output it to the text1 Tk variable + # output = api.get_credit_with_login(entry_username.get(), entry_password.get()) + # message_box.config(text=output) + # + # entry_username = tk.Entry(self) # creating the Tk widgets + # entry_password = tk.Entry(self, show='*') + # message_box = tk.Label(self, width='200') + # button_get_credit = tk.Button(self, text="Fetch Credit", command=display_credit) + # + # self.pack(fill='both', expand=1) # displaying the Tk widgets with pack() + # entry_username.pack() + # entry_password.pack() + # button_get_credit.pack() + # message_box.pack() - balance.config(text=text) + def init_window(self): + def display_credit(): + output = api.get_credit_with_mock(entry_id.get()) + message_box.config(text=output) - # creating the Tk widgets entry_id = tk.Entry(self) - balance = tk.Message(self, width='200') - button_get_credit = tk.Button(self, text="Fetch Credit", command=display_data) + button_get = tk.Button(self, text="Get Credit", command=display_credit) + message_box = tk.Label(self) - self.master.title("Student Credit") - # displaying the Tk widgets with pack() self.pack(fill='both', expand=1) entry_id.pack() - button_get_credit.pack() - balance.pack() - -root = tk.Tk() -root.geometry("350x200") # sets window size -app = Application(root) -root.mainloop() # this kicks off tkinter window + button_get.pack() + message_box.pack() + +if __name__ == '__main__': + root = tk.Tk() + root.overrideredirect(1) # makes the window actually seem "full screen" + root.geometry("{}x{}".format(root.winfo_screenwidth(), root.winfo_screenheight())) + # gets the size of the display and sets the screen size to those values (covers the whole display) + app = Application(root) + root.mainloop() From 59f4a3a7276bc1ce71b685af9a2bfd39aed58278 Mon Sep 17 00:00:00 2001 From: Lacayo Date: Sat, 18 Mar 2017 14:47:59 -0600 Subject: [PATCH 2/4] Removed login API and login GUI --- api.py | 19 ------------------- main.py | 17 ----------------- 2 files changed, 36 deletions(-) diff --git a/api.py b/api.py index bc53084..84ec4e0 100644 --- a/api.py +++ b/api.py @@ -1,20 +1,6 @@ import requests -def get_credit_with_login(username, password): - # function using NCAI login to get credit_student and credit_family - try: - if username in '' or password in '': - return "Please enter a username and password" - api = "http://db.nca.edu.ni/api/api_ewapp.php?mode=student&query=login&username={}&password={}".format(username, password) - response = requests.get(api).json() - if response['login_status'] is 0: - return "Invalid login. Please try again." - return "Your balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) - except requests.exceptions.ConnectionError: - return "Connection unable to be established.\nIs the server online?" - - def get_credit_with_mock(user_id): try: api = "http://localhost:3000/api/" @@ -26,8 +12,3 @@ def get_credit_with_mock(user_id): return "Invalid id. Please try again." except TypeError: return "Please enter an id" - - -def get_credit_with_scanner(): - # function for use with the real API system - pass diff --git a/main.py b/main.py index a8be546..be99b1f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import sys import tkinter as tk import api @@ -9,22 +8,6 @@ def __init__(self, master=None): self.master = master self.init_window() # after initial setup; we now setup the window and its parts - # def init_window(self): - # def display_credit(): # use our get_student_credit function and output it to the text1 Tk variable - # output = api.get_credit_with_login(entry_username.get(), entry_password.get()) - # message_box.config(text=output) - # - # entry_username = tk.Entry(self) # creating the Tk widgets - # entry_password = tk.Entry(self, show='*') - # message_box = tk.Label(self, width='200') - # button_get_credit = tk.Button(self, text="Fetch Credit", command=display_credit) - # - # self.pack(fill='both', expand=1) # displaying the Tk widgets with pack() - # entry_username.pack() - # entry_password.pack() - # button_get_credit.pack() - # message_box.pack() - def init_window(self): def display_credit(): output = api.get_credit_with_mock(entry_id.get()) From 67c50a545cce0714fe5d0b831b0dddf732f6d149 Mon Sep 17 00:00:00 2001 From: Hellsing76 Date: Wed, 29 Mar 2017 10:07:39 -0600 Subject: [PATCH 3/4] I didn't really change much --- api.py | 6 ++++-- main.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api.py b/api.py index 84ec4e0..5b755a7 100644 --- a/api.py +++ b/api.py @@ -1,14 +1,16 @@ import requests -def get_credit_with_mock(user_id): +def get_balance_with_mock(user_id): try: api = "http://localhost:3000/api/" response = requests.get(api + user_id).json() - return "Your balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) + return "Balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) except requests.exceptions.ConnectionError: return "Connection unable to be established. Is the server online?" except KeyError: return "Invalid id. Please try again." except TypeError: return "Please enter an id" + except KeyboardInterrupt: + return "Goodbye" diff --git a/main.py b/main.py index be99b1f..f293b43 100644 --- a/main.py +++ b/main.py @@ -10,11 +10,11 @@ def __init__(self, master=None): def init_window(self): def display_credit(): - output = api.get_credit_with_mock(entry_id.get()) + output = api.get_balance_with_mock(entry_id.get()) message_box.config(text=output) entry_id = tk.Entry(self) - button_get = tk.Button(self, text="Get Credit", command=display_credit) + button_get = tk.Button(self, text="Get Balance", command=display_credit) message_box = tk.Label(self) self.pack(fill='both', expand=1) From 10db24309d855dbe749e5594dab219410df712ee Mon Sep 17 00:00:00 2001 From: Hellsing76 Date: Sat, 6 May 2017 22:49:49 -0600 Subject: [PATCH 4/4] some new modifications --- .idea/check-mate.iml | 11 ++ .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 287 +++++++++++++++++++++++++++++++++++++++++++ api.py | 30 ++++- main.py | 3 +- 7 files changed, 344 insertions(+), 5 deletions(-) create mode 100644 .idea/check-mate.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/check-mate.iml b/.idea/check-mate.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/check-mate.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f899e1d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..12ff05f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..b65b296 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1493845456682 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api.py b/api.py index 5b755a7..100f854 100644 --- a/api.py +++ b/api.py @@ -1,11 +1,19 @@ import requests +import json -def get_balance_with_mock(user_id): +def get_barcode(barcodeid): try: - api = "http://localhost:3000/api/" - response = requests.get(api + user_id).json() - return "Balance: ${}\nFamily balance: ${}".format(response['credit_student'], response['credit_family']) + api = "http://db.nca.edu.ni/api/api_ewapp.php?" + requirements = {'staff_username':"", + 'staff_password':"", + 'barcode':"", + "is_upc":bool + } + + + r = requests.get(api+barcodeid).json() + return "Balance: ${}\nFamily balance: ${}\nTransaction history: {}".format(r['credit_student'], r['credit_family'], r['transactions']) except requests.exceptions.ConnectionError: return "Connection unable to be established. Is the server online?" except KeyError: @@ -14,3 +22,17 @@ def get_balance_with_mock(user_id): return "Please enter an id" except KeyboardInterrupt: return "Goodbye" + + + + + + + + + + + + + + diff --git a/main.py b/main.py index f293b43..5618fb0 100644 --- a/main.py +++ b/main.py @@ -10,9 +10,10 @@ def __init__(self, master=None): def init_window(self): def display_credit(): - output = api.get_balance_with_mock(entry_id.get()) + output = api.get_barcode(entry_id.get()) message_box.config(text=output) + entry_id = tk.Entry(self) button_get = tk.Button(self, text="Get Balance", command=display_credit) message_box = tk.Label(self)