def __init__(self, **kwargs): super(NotesScreen, self).__init__(**kwargs) self.c = Crypto(False, 0) self.n = Notes() self.latestnote() self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor()
def __init__(self, **kwargs): super(RemindersScreen, self).__init__(**kwargs) self.c = Crypto(False, 0) self.r = Reminders() self.latestreminder() self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor()
def __init__(self, **kwargs): super(TwitterScreen, self).__init__(**kwargs) self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor() self.c = Crypto(False, 0) self.t = Twitter() self.latesttweet()
def __init__(self, **kwargs): super(HomeScreen, self).__init__(**kwargs) with sqlite3.connect("resources/UserData.db") as db: cursor = db.cursor() cursor.execute("SELECT Name FROM userInfo") username = cursor.fetchone() c = Crypto(False, 0) username = c.decrypt(username[0]) self.lblName.text = "Welcome, {}!".format(username)
class csvworker: def __init__(self): self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor() self.c = Crypto(False, 0) # Method - exportcsv # Parameters - idtype: string # Return - None # Purpose - Creates a csv file from the user's selected database table (notes or reminders) def exportcsv(self, idtype): file = open("resources/output.csv", "w") writer = csv.writer(file) sql = """SELECT {}ID, Title, Content, Date FROM {}s ORDER BY Title""".format(idtype, idtype) self.cursor.execute(sql) data = self.cursor.fetchall() writer.writerow(["ID", "Title", "Content", "Date"]) for i in range(len(data)): writer.writerow([data[i][0], self.c.decrypt(data[i][1]), self.c.decrypt(data[i][2]), data[i][3]]) # Method - email # Parameters - username: string, password: string, target: string # Return - None # Purpose - Sends an email with the exported csv file attached over gmail servers using the user's email and # password, to a user defined target address def email(self, username, password, target): try: msg = MIMEMultipart() msg['From'] = username msg['To'] = target msg['Subject'] = "Assistant - Data output" body = "Attached is the output data in csv format, as created by Assistant" msg.attach(MIMEText(body, 'plain')) filename = "resources/output.csv" attachment = open("resources/output.csv", "rb") file = MIMEBase('application', 'octet-stream') file.set_payload(attachment.read()) encoders.encode_base64(file) file.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(file) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(username, password) text = msg.as_string() server.sendmail(username, target, text) server.quit() return True except: return False
def editreminder(self): reminderid = self.currentreminderid title = self.inputEditReminderTitle.text content = self.inputEditReminderContent.text if title == "" or content == "": pass else: c = Crypto(False, 0) title = c.encrypt(title) content = c.encrypt(content) n = Reminders() n.edit(reminderid, title, content) reminders = self.manager.get_screen("reminders") reminders.latestreminder() self.manager.current = "reminders"
def editnote(self): noteid = self.currentnoteid title = self.inputEditNoteTitle.text content = self.inputEditNoteContent.text if title == "" or content == "": pass else: c = Crypto(False, 0) title = c.encrypt(title) content = c.encrypt(content) n = Notes() n.edit(noteid, title, content) notes = self.manager.get_screen("notes") notes.latestnote() self.manager.current = "notes"
def createnote(self): title = self.inputNewNoteTitle.text content = self.inputNewNoteContent.text if title == "" or content == "": pass else: c = Crypto(False, 0) title = c.encrypt(title) content = c.encrypt(content) n = Notes() n.create(title, content) notes = self.manager.get_screen("notes") notes.latestnote() self.manager.current = "notes"
def getweather(self): with sqlite3.connect("resources/UserData.db") as db: cursor = db.cursor() cursor.execute("SELECT city FROM userInfo") city = cursor.fetchone() cursor.execute("SELECT country FROM userInfo") country = cursor.fetchone() c = Crypto(False, 0) city = c.decrypt(city[0]) country = c.decrypt(country[0]) w = Weather4Day(country, city) self.lblLocation.text = "The weather in {}, {} is".format( city, country) self.lblWeatherText.text = w.forecasttodaytext() self.lblWeatherHigh.text = w.forecasttodayhigh() + "C" self.lblWeatherLow.text = w.forecasttodaylow() + "C"
def completesetup(self, name, country, city): c = Crypto(True, len(name)) name = c.encrypt(name) country = c.encrypt(country) city = c.encrypt(city) un = c.encrypt("kedst") db = sqlite3.connect("resources/UserData.db") cursor = db.cursor() sql = "CREATE TABLE userInfo (Name text, Country text, City text, LastTwitterSearch text, primary key(Name))" cursor.execute(sql) sql = """INSERT INTO userInfo (Name, Country, City, LastTwitterSearch) VALUES ('{}', '{}', '{}', '{}')""".format( name, country, city, un) cursor.execute(sql) # Notes table sql = """CREATE TABLE Notes (NoteID integer, Title text, Content text, Date float, primary key(NoteID))""" cursor.execute(sql) # Reminders table sql = """CREATE TABLE Reminders (ReminderID integer, Title text, Content text, Date float, primary key(ReminderID))""" cursor.execute(sql) db.commit()
def __init__(self, password): self.crypto = Crypto(password) self.model = ManagerModel()
class ManagerService: def __init__(self, password): self.crypto = Crypto(password) self.model = ManagerModel() def add(self): App = self.crypto.EncryptString(input("App/Webpage name: ")) Username = self.crypto.EncryptString(input("Username: "******"Password: "******"Comments: ")) params = {"App": App, "Username": Username, \ "Password": Password, "Comments": Comments} return self.model.add(params) def delete(self): item_id = input("Input id to delete item: ") return self.model.delete(item_id) def listItems(self): #TODO: #Error handling if table doesnt exist response = self.model.list_items() return response def clear(self): return self.model.clear() #TODO def update(self): #TODO error handling item_id = int(input("Item id to edit: ")) column = "" value = "" flag = False while(not flag): print("Which column you want to edit?") print("1 - App/Website") print("2 - Username") print("3 - Password") print("4 - Comments") choice = input() if choice == '1': flag = True column = "App" if choice == '2': flag = True column = "Username" if choice == '3': flag = True column = "Password" if choice == '4': flag = True column = "Comments" if(not flag): print("Wrong input") value = input(f"Enter new {column} value: ") encrypted_value = self.crypto.EncryptString(value) params = [column, encrypted_value] return self.model.update(item_id, params) def printAll(self): response = self.listItems() id = "Id" App = "App/Website" Username = "******" Password = "******" Comment = "Comments" for i in range(len(response)+1): print(str(id).ljust(5) + App.ljust(25) + Username.ljust(25) + Password.ljust(25) + Comment) if i == 0: print("====================================================================================================") if i < len(response): item = response[i] id = item[0] App = self.crypto.DecryptString(item[1]) if App == False: return False Username = self.crypto.DecryptString(item[2]) Password = self.crypto.DecryptString(item[3]) Comment = self.crypto.DecryptString(item[4])
from encryption import Crypto if __name__ == "__main__": crypto = Crypto(input("Enter you password: "******"encrypted string: ") message = "secret message" print(str(crypto.token)) #encrypted = crypto.EncryptString(message) print(encrypted) print(crypto.DecryptString(encrypted))
def __init__(self): self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor() self.c = Crypto(None, 0)
class RemindersScreen(Screen): # Method - RemindersScreen init # Parameters - None # Return - None # Purpose - Initialises instances of the reminders and crypto classes, connects to the database, and runs the # latestreminder method def __init__(self, **kwargs): super(RemindersScreen, self).__init__(**kwargs) self.c = Crypto(False, 0) self.r = Reminders() self.latestreminder() self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor() # Method - latestreminder # Parameters - data: list of strings # Return - None # Purpose - If the user has any reminders, display the most recent one in labels def latestreminder(self): data = self.r.mostrecent() if data is False: self.lblLastReminderTitle.text = "No reminders found!" self.lblLastReminderContent.text = " " else: recenttitle = data[0] recentcontent = data[1] recenttitle = self.c.decrypt(recenttitle) recentcontent = self.c.decrypt(recentcontent) self.lblLastReminderTitle.text = recenttitle self.lblLastReminderContent.text = recentcontent # Method - newreminder # Parameters - None # Return - None # Purpose - Clears the content of the text inputs of the newreminder screen, then displays it def newreminder(self): newreminders = self.manager.get_screen("newreminders") newreminders.inputNewReminderTitle.text = "" newreminders.inputNewReminderContent.text = "" newreminders.inputNewReminderYear.text = "" newreminders.inputNewReminderMonth.text = "" newreminders.inputNewReminderDay.text = "" newreminders.inputNewReminderHour.text = "" newreminders.inputNewReminderMinute.text = "" newreminders.inputNewReminderSecond.text = "" self.parent.current = "newreminders" # Method - remindersbytime # Parameters - data: list of strings # Return - None # Purpose - Retrieves a list of the user's reminders sorted by time, then passes it to the setupmorereminders # function def remindersbytime(self): data = self.r.sort("Date") count = len(data) self.setupmorereminders(count, data) # Method - remindersbytime # Parameters - data: list of strings # Return - None # Purpose - Retrieves a list of the user's reminders sorted by title alphabetically, then passes it to the # setupmorereminders function def remindersbytitle(self): data = self.r.sort("Title") count = len(data) self.setupmorereminders(count, data) # Method - searchreminders # Parameters - searchterm: string, data: list of strings # Return - None # Purpose - Gets a list of the user's reminders containing a given search term, then passes it to the # setupmorereminders function def searchreminders(self): searchterm = self.inputSearchReminders.text if searchterm == "": pass else: searchterm = self.c.encrypt(searchterm) data = self.r.search(searchterm) count = len(data) self.setupmorereminders(count, data) # Method - setupmorereminders # Parameters - count: integer , data: list of strings # Return - None # Purpose - Adds widgets displaying the title and content of each reminder within the given list, as well as their # corresponding edit and delete buttons to the morereminders screen. A "back" button is then added and the screen is # displayed. def setupmorereminders(self, count, data): morereminders = self.manager.get_screen("morereminders") morereminders.layoutMoreReminders.clear_widgets( morereminders.layoutMoreReminders.children) for i in range(count): reminderid = data[i][0] title = data[i][1] title = self.c.decrypt(title) content = data[i][2] content = self.c.decrypt(content) date = data[i][3] date = datetime.datetime.fromtimestamp(date) lbltitle = Label(text=title, size_hint_y=None) lbltitle.texture_update() morereminders.layoutMoreReminders.add_widget(lbltitle) lbltext = Label(text=content, size_hint_y=None) lbltext.texture_update() morereminders.layoutMoreReminders.add_widget(lbltext) lbldate = Label(text=str(date), size_hint_y=None) lbldate.texture_update() morereminders.layoutMoreReminders.add_widget(lbldate) grid = GridLayout(cols=2, size_hint_y=None) btnedit = Button(text="Edit", size_hint_y=None, on_press=lambda a: self.edit(reminderid)) btndelete = Button(text="Delete", size_hint_y=None, on_press=lambda a: self.delete(reminderid)) btnedit.texture_update() btndelete.texture_update() grid.add_widget(btnedit) grid.add_widget(btndelete) morereminders.layoutMoreReminders.add_widget(grid) grid = GridLayout(cols=2, size_hint_y=None) btnback = (Button(text="Back", height=dp(80), on_press=lambda a: self.back())) grid.add_widget(btnback) morereminders.layoutMoreReminders.add_widget(grid) self.manager.current = "morereminders" # Method - back # Parameters - None # Return - None # Purpose - Runs the latestreminder method, then displays the reminders screen def back(self): self.latestreminder() self.manager.current = "reminders" # Method - delete # Parameters - reminderid: string # Return - None # Purpose - Deletes the reminder corresponding to the given reminderid, then calls the latestreminder method and # displays the reminders screen def delete(self, reminderid): self.r.delete(reminderid) self.latestreminder() self.manager.current = "reminders" # Method - edit # Parameters - reminderid: string # Return - None # Purpose - Displays the editreminders screen, and passes reminderid to it def edit(self, reminderid): editreminders = self.manager.get_screen("editreminders") editreminders.currentreminderid = reminderid self.manager.current = "editreminders"
class TwitterScreen(Screen): # Method - TwitterScreen init # Parameters - None # Return - None # Purpose - When kivy has built the screen, initialises instances of the Crypto and Twitter classes for this class, # then calls the latesttweet function def __init__(self, **kwargs): super(TwitterScreen, self).__init__(**kwargs) self.db = sqlite3.connect("resources/UserData.db") self.cursor = self.db.cursor() self.c = Crypto(False, 0) self.t = Twitter() self.latesttweet() # Method - latesttweet # Parameters - username # Return - None # Purpose - Retrieves the username the user last searched for, fetches their latest tweet from the API, then # displays their username latest tweet in labels def latesttweet(self): self.cursor.execute("SELECT LastTwitterSearch FROM userInfo") username = self.cursor.fetchone() username = self.c.decrypt(username[0]) self.lblRecentTweet.text = self.t.userlatest(username) self.lblRecentUsername.text = "Latest tweet from @" + username # Method - getmoretweets # Parameters - un:string # Return - None # Purpose - Obtains and displays the data on the moretweets screen using the user's chosen location def getmoretweets(self): un = self.inputTwitterUsername.text if un == "": pass else: moretwitter = self.manager.get_screen("moretwitter") moretwitter.layoutMoreTwitter.clear_widgets( moretwitter.layoutMoreTwitter.children) tweets = self.t.user10(un) lblun = Label(text=("Latest tweets from @" + un), size_hint_y=None) moretwitter.layoutMoreTwitter.add_widget(lblun) for i in range(len(tweets)): lbltweet = Label(text=tweets[i], size_hint_y=None) lbltweet.texture_update() moretwitter.layoutMoreTwitter.add_widget(lbltweet) btnback = Button(text="Back", height=dp(40), size_hint_y=None, on_press=lambda a: self.back()) moretwitter.layoutMoreTwitter.add_widget(btnback) self.manager.current = "moretwitter" # Method - back # Parameters - username: string, secureusername:s tring # Return - None # Purpose - Updates the main twitter screen with the latest tweet from the username the user last searched for, # then displays the twitter screen. def back(self): username = self.inputTwitterUsername.text secureusername = self.c.encrypt(username) sql = """UPDATE userInfo SET LastTwitterSearch='{}'""".format( secureusername) self.cursor.execute(sql) self.db.commit() self.lblRecentUsername.text = "Latest tweet from @{}".format(username) self.lblRecentTweet.text = self.t.userlatest(username) self.manager.current = "twitter"