Example #1
0
 def __init__(self, account, clientServer):
     Tk.__init__(self)
     self.title("Inbox")
     self.config(bg="#3a4860")
     self.clientServer = clientServer
     self.account = account
     self.database = DataBase()
     exit_button = Button(self, text="Exit",
                          command=self.quit,
                          bg="black", fg="red")
     exit_button.grid(row=8, column=1, columnspan=2, rowspan=2,
                      padx=5, pady=5)
     self.transaction_phase()
     print("Transaction finished")
     message_content = self.database.fetch_mail_from_account(
         self.account.split("@")[0])
     print("Messages")
     print(message_content)
     for i, mail in enumerate(message_content):
         Label(self, text=mail['Data'], fg="#ffffff", bg="#576884").grid(
             row=20 + i*2, column=1, columnspan=2, rowspan=2,
             padx=5, pady=5, sticky=W+E+N+S)
     if(len(message_content) == 0):
         Label(self, "No messages", fg="#ffffff", bg="#576884").grid(
             row=20 + 2, column=1, columnspan=2, rowspan=2,
             padx=5, pady=5, sticky=W+E+N+S)
Example #2
0
 def handle_mail(self, socket, mail_from, mail_to, message):
     print("Handling mail")
     domain = mail_to.split("@")[1].replace(">", "")
     if (domain == self.domain):
         database = DataBase()
         database.save_Mail(mail_from, mail_to, message)
     else:
         print("sending to..." + domain)
         self.send_mail(domain, mail_from, mail_to, message)
Example #3
0
 def __init__(self, selected_date, status):
     #data hardcode for now, should come from database
     self.database = DataBase()
     self.date = selected_date
     self.photo = []
     self.tag = []
     self.text = None
     if status == 'old':
         loaded_values = self.database.getData(self.date)
         self.text = loaded_values[0]
         self.tag.extend(loaded_values[1].split(','))
         self.photo.extend(loaded_values[2].split(','))
Example #4
0
class Entry:
    def __init__(self, selected_date, status):
        #data hardcode for now, should come from database
        self.database = DataBase()
        self.date = selected_date
        self.photo = []
        self.tag = []
        self.text = None
        if status == 'old':
            loaded_values = self.database.getData(self.date)
            self.text = loaded_values[0]
            self.tag.extend(loaded_values[1].split(','))
            self.photo.extend(loaded_values[2].split(','))

    def addPhoto(self, loc, isEdit):
        if loc == None:
            self.photo = []
        elif loc != self.photo and isEdit == True:
            self.photo = loc[0]
        elif loc != self.photo and isEdit == False:
            self.photo.extend(loc[0])

    def addTag(self, tags, isEdit):
        if tags != self.tag and isEdit == False:
            self.tag.extend(tags)
        elif tags != self.tag and isEdit == True:
            self.tag = tags

    def addText(self, texts):
        self.text = texts

    def editText(self, getWhat):
        if getWhat == 'getTexts':
            return self.text
        elif getWhat == 'getTags':
            return self.tag
        elif getWhat == 'getPhotos':
            return self.photo

    def storeValues(self, status):
        if status == 'new':
            joined_tag = ' '.join(self.tag)
            joined_photos = ','.join(self.photo)
            self.database.addDataEntry(self.date, self.text, joined_tag,
                                       joined_photos)
        elif status == 'old':
            self.database.updateEntryText(self.date, self.text)
            joined = ' '.join(self.tag)
            self.database.updateEntryTags(self.date, joined)
            joined = ','.join(self.photo)
            self.database.updateEntryPhotos(self.date, joined)
Example #5
0
    def list_image_tags(self):
        """Called by show image. Adds current tags to ListTags listbox"""

        tags = DataBase.get_image_tags(pth=self.queue[self.curr_img])
        lt = self.ui.builder.get_object("ListTags")
        self.clear_tags()
        for tag in tags:
            lt.insert(END, tag)
Example #6
0
def try_connecting():
    i = 0
    db = DataBase("budget", "192.168.1.100", "Budget", "matix0508", "G@d#ryp0luk!")
    while not (db.connected or i == 10):
        try:
            db.db_connect()
        except:
            i+=1
            db = DataBase("budget", "192.168.1.10{i}", "Budget", "matix0508", "G@d#ryp0luk!")
    if db.connected:
        db.close()
        return db
Example #7
0
class User:
    def __init__(self):
        self.database = DataBase()

    def changePin(self, oldPin, newPin, confirmPin):
        if self.database.getPIN('Hannah Tan') == oldPin:
            if newPin == confirmPin:
                self.database.updatePIN('Hannah Tan', newPin)
                return 0
            else:
                return 1
        else:
            return 2

    def verifyLogin(self, inputPin):

        if self.database.getPIN('Hannah Tan') == inputPin:
            return True
        else:
            return False
Example #8
0
    def confirmed(self, event):

        #Listbox items
        tags = self.ui.builder.get_object("ListSelected").get(0, END)
        #       Unique images' ids
        res = set()
        for tg in tags:
            ids = DataBase.get_tagged_items(tg)
            #TODO maybe sth better if nth found
            if len(ids) < 1:
                return
#           Add else intersection
            if self.any:
                res |= set(ids)
            else:
                res &= set(ids)

        lt = list()
        for r in res:
            lt.append(DataBase.get_path(r))
        self.queue_images(lt)
Example #9
0
class Date:
    def __init__(self, selected_date):
        self.day = selected_date
        self.database = DataBase()
        self.slot = True

    def createEntry(self, txt, tgs, phts):
        entry = Entry(self.day, 'new')
        entry.addText(txt)
        word = tgs.split()
        entry.addTag(word, False)
        entry.addPhoto(phts, False)
        entry.storeValues('new')

    def dateAvailability(self):
        if self.day in self.database.getDates():
            return True
        else:
            return False

    def deleteEntry(self):
        self.database.delDataDate(self.day)

    def sendData(self, getWhat):
        entry = Entry(self.day, 'old')
        if getWhat == 'getTexts':
            return entry.editText('getTexts')
        elif getWhat == 'getTags':
            return entry.editText('getTags')
        elif getWhat == 'getPhotos':
            return entry.editText('getPhotos')

    def editEntry(self, txt, tgs, phts):
        entry = Entry(self.day, 'old')
        entry.addText(txt)
        word = tgs.split()
        entry.addTag(word, True)
        entry.addPhoto(phts, True)
        entry.storeValues('old')
Example #10
0
File: ABC.py Project: AlyAhmad1/IMS
from flask import Flask, render_template, url_for, redirect, request, session, make_response
from flask_wtf import FlaskForm, RecaptchaField, file
from wtforms import StringField, PasswordField
from wtforms.validators import InputRequired, AnyOf
from functools import wraps
from DB import DataBase
from datetime import timedelta
import os
import sys
DB_obj = DataBase()

Application = Flask(__name__)
Application.config['SECRET_KEY'] = '!2#4%6&8(0Ali'


# making login_required decorator
def login_required(f):
    @wraps(f)
    def wrap(*args, **kwargs):
        if 'user' in session:
            session.permanent = True
            Application.permanent_session_lifetime = timedelta(minutes=5)
            return f(*args, **kwargs)
        else:
            return redirect(url_for('login'))

    return wrap
Example #11
0
class inbox(Tk):
    def __init__(self, account, clientServer):
        Tk.__init__(self)
        self.title("Inbox")
        self.config(bg="#3a4860")
        self.clientServer = clientServer
        self.account = account
        self.database = DataBase()
        exit_button = Button(self, text="Exit",
                             command=self.quit,
                             bg="black", fg="red")
        exit_button.grid(row=8, column=1, columnspan=2, rowspan=2,
                         padx=5, pady=5)
        self.transaction_phase()
        print("Transaction finished")
        message_content = self.database.fetch_mail_from_account(
            self.account.split("@")[0])
        print("Messages")
        print(message_content)
        for i, mail in enumerate(message_content):
            Label(self, text=mail['Data'], fg="#ffffff", bg="#576884").grid(
                row=20 + i*2, column=1, columnspan=2, rowspan=2,
                padx=5, pady=5, sticky=W+E+N+S)
        if(len(message_content) == 0):
            Label(self, "No messages", fg="#ffffff", bg="#576884").grid(
                row=20 + 2, column=1, columnspan=2, rowspan=2,
                padx=5, pady=5, sticky=W+E+N+S)

    def recive_command(self):
        recive_data = ""
        while True:
            data = self.clientServer.recv(1024).decode()
            recive_data = recive_data + data
            if("\r\n" in recive_data):
                break
        return recive_data

    def retr_message(self, received_data):
        print("S: " + received_data)
        message = []
        string_message = ""
        message.append(received_data)
        string_message += received_data
        while(".\r\n" not in string_message):
            received_data = self.recive_command()
            string_message += received_data
            if(received_data != "./r/n"):
                message.append(received_data)
            else:
                break
        return message

    def transaction_phase(self):
        self.clientServer.send("LIST\r\n".encode())
        print("C: " + "LIST")
        # Recive +OK len(messages) messages size_of_messages
        recive_data = self.recive_command()
        # Star
        recive_data = self.recive_command()
        # No message to retrive
        if (recive_data == ".\r\n"):
            print("S :" + recive_data)
        # Receive at least one
        else:
            messages = self.retr_message(recive_data)
            # Remove .\r\n
            for i in range(len(messages)):
                if(messages[i] == ".\r\n"):
                    continue
                # SEND RETR #message
                retr = "RETR "
                retr_message = retr + str(i+1) + "\r\n"
                self.clientServer.send(retr_message.encode())
                print("C: " + retr_message)
                # RECIVE DATA

                received_data = self.recive_command()
                message = ""
                message += received_data
                while(".\r\n" not in message):
                    received_data = self.recive_command()
                    print(received_data)
                    message += received_data
                print(message)

                dele = "DELE "
                dele_message = dele + str(i+1) + "\r\n"
                self.clientServer.send(dele_message.encode())
                print("C: " + dele_message)
                self.database.insert_user_mail(
                    self.account.split("@")[0], message)
def Get():
    print(get_env().RABBITMQCONNECTSTRING)
    data = DataBase.ListCollection(get_env().CONNECTSTRING)
    return Response(dumps(data), mimetype='application/json')
Example #13
0
 def __init__(self, selected_date):
     self.day = selected_date
     self.database = DataBase()
     self.slot = True
Example #14
0
 def __init__(self):
     self.smtp_port = 8080
     self.domain = "grupo01.com"
     self.host = gethostbyname(gethostname())
     self.database = DataBase()
Example #15
0
 def __init__(self):
     self.currtable = str(INVALIDTABLE)
     self.datb = DataBase("fuller.db")
Example #16
0
class ViewModel:

    #Pre: nothing
    #Post: An instance of the ViewModel is created. The DataBase
    #is created with the name fuller.db
    #Narrative: Constructor
    def __init__(self):
        self.currtable = str(INVALIDTABLE)
        self.datb = DataBase("fuller.db")

    #Pre: No pre-conditions required
    #Post: All of the table names are returned in the form of a python list of strings
    #Narrative: This returns a list contianing all the names of the tables existing in the database
    def GetTableNames(self):
        tablenames = self.datb.GetTables()
        return tablenames

    #Pre: A valid string is passed in
    #Post: A boolean value is returned: true for table exists, false for non existant.
    #Narrative: This calls the CheckTable from the DataBase Module
    def CheckTable(self, name):
        return self.datb.CheckTable(name)

    #Pre: Database Exists
    #Post: A count of how many tables exist in the databas is returned
    #Narrative: This method returns an integer of how many tables are in the database
    def TableCount(self):
        num = self.datb.TableCount()
        return num

    #Pre: Other Tables exist to change to
    #Post: If a valid table name was given, it's changed to. If the name is invalid then the table is not changed.
    #Narrative: Changes the current table to a new table based on the name given.
    #Returns true on success False on failure
    def ChangeTable(self, name):
        names = self.GetTableNames()

        if name in names:
            self.currtable = name
            self.datb.ChangeTable(name)
            return True
        else:
            return False

    #Pre: Space exists on the machine for more Tables
    #Post: The table is created with the given name, given that the name provided was valid
    # see the README for what table names are invalid
    #Narrative: Adds a table with the given name to the database.
    def AddTable(self, name):
        #Make sure the name isn't already in the database
        if not (self.datb.CheckTable(name)) and name != "table":
            self.datb.NewTable(name)
            self.datb.ChangeTable(name)
            self.currtable = name
            return True
        return False

    #Pre: Name of an existing table is given
    #Post: The table with the given name is dropped
    #Narrative: Drops the table with the given name
    #Returns false if the table doesn't exist in the database.
    #If the current table is dropped, it is set to invalid
    def DropTable(self, name):
        names = self.GetTableNames()
        if name in names:
            if name == self.currtable:
                self.currtable = INVALIDTABLE
            self.datb.DropTable(name)
            return True
        return False

    #Pre: Records exist in the current table
    #Post: Records from the database are returned in the form of a python list
    #Narrative: returns a list of the records from the current table in the databse
    def GetRecords(self):
        if self.currtable != INVALIDTABLE:
            return self.datb.GetRecords()
        else:
            return []

    #This function acts similarly to the previos GetRecords but it instead Returns
    #The datbase cursor object from SQLite. This is in here to allow certain interfaces used
    #For creating a GUI to have access to a database object for extraction of records.
    def GetRawRecords(self):
        return self.datb.GetRawRecords()

    #Pre: Iso and Pentaconnect are within range. Iso is the Isomner given by the user
    # and pentaconnect is whether or not they want to allow touching pentagons
    #Post: the records are added to the database.
    #Narrative: Using subprocess sprial.exe is called to obtain the topological info and
    #the output from sprial.exe is thrown into a python list. This is added into the DataBase
    #using the database AddRecord() method
    def AddIso(self, iso, pentaconnect):
        #start setting up the input for the database
        records = []
        if not iso.isnumeric() or int(iso) > 200 or int(iso) < 0:
            return records

        dbInput = str(iso)

        #add on a space then the pentagon rule to format the input for spiral.f
        dbInput += " "
        if not pentaconnect.isnumeric() or int(pentaconnect) > 1 or int(
                pentaconnect) < 0:
            return records
        dbInput += pentaconnect

        #call spiral.f and have a pipe set up to get the input
        p = subprocess.Popen("./spiral.exe",
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             universal_newlines=True)
        if not p:
            print("Error with opening")

        #read spiral.f output into x
        x = p.communicate(input=dbInput)[0]

        #create a list of all of the lines of output
        lines = x.split("\n")

        #get rid of the extra lines describing what the table is showing
        if len(lines) > 1:
            lines.pop(0)
            lines.pop(0)
            lines.pop(len(lines) - 1)
            lines.pop(len(lines) - 1)

            for line in lines:
                #strip off unnecessary pieces of string
                line = line.strip()
                #format the line for database input
                line = list(line)
                line[0] = " "
                line = "".join(line)
                line = line.strip()
                line = (iso, line)
                #add to list of records to be added to database
                records.append(line)
            self.datb.AddRecord(records, iso)

        return self.datb.GetRecords()

    #Method that calls AddIso multiple times for a given range
    def AddIsos(self, lowerBound, upperBound, pentaconnect):
        upperBound += 1
        for iso in range(lowerBound, upperBound):
            self.AddIso(str(iso), pentaconnect)
        return self.datb.GetRecords()

    #Pre: none
    #Post: the current table is returned as a string value
    #Narrative: Simple method to retrieve the name of the current table
    def GetCurrTable(self):
        return self.currtable
Example #17
0
    def path_input(self, pth):
        """Handle request for new input file. If new tag and display else display"""

        self.clear_results()
        tfiles = None

        #       Single image path
        if not isdir(pth):
            new = True
            #           SQL exception if path is not unique
            try:
                DataBase.add_image(pth)
            except IntegrityError:
                new = False

#          Tag new
            if new:
                tags = Tagger.tag_file(pth)
                for tag in tags:
                    DataBase.tag_image(tag, pth=pth)
#       Directory path
        else:
            tags, tfiles = Tagger.tag_dir(pth)
            for i in range(len(tfiles)):
                f = tfiles[i]
                #               Full path to image
                fpth = join(pth, f)
                tfiles[i] = fpth
                #               Continue if already present
                if DataBase.exists(pth=fpth):
                    continue
                else:
                    DataBase.add_image(fpth)
                    #                   Tuple results
                    if not isinstance(tags[i], str):
                        for t in tags[i]:
                            DataBase.tag_image(t, pth=fpth)
#                   String result
                    else:
                        DataBase.tag_image(tags[i], pth=fpth)

        L = 1
        #       Display
        if tfiles is None:
            self.queue_images(pth)
        else:
            #Number of listbox for results length
            L = len(tfiles)
            nlb = max(3, L)
            nlb = min(nlb, 12)
            self.ui.builder.get_object("ListResults").config(height=nlb)

            self.queue_images(tfiles)

        self.update_info("Processed " + str(L) + " images")
Example #18
0
 def __init__(self):
     self.database = DataBase()