Exemplo n.º 1
0
    def __selection_change(self, view):
        '''
        this method is called when a new
        row in the tree view is selected
        '''

        rows = view.get_selection().get_selected()
        message = rows[0].get_value(rows[1], 6).replace('&', '&').replace(
					     '<', '&lt;').replace('>', '&gt;')
        receiver = rows[0].get_value(rows[1], 7).split(',')
        database = DataBase()
        receiver = database.get_contact_name(receiver)
        sender = rows[0].get_value(rows[1], 8)
        database.close()
        self.message_store.clear()
        self.message_scroll.show_all()
        name = ''
        number = ''
        for receipient in receiver:
            name += receipient[0] + '\n'
            number += receipient[1] + '\n'
        name = name[:-1]
        number = number[:-1]
        self.message_store.append(['<span font_desc="belgrano 12"><b>'
                                   + message + '</b></span>', number, name,
                                   sender, '#3890FF'])
        return
Exemplo n.º 2
0
def editEmp():
    id = request.args.get('id', '')
    print(request.json)
    if not request.json:
        abort(400)
    DataBase.editEmp(id,Employee(0,request.json['Login'],request.json['Name'],Employee.hashPassword(request.json['Password']),request.json['Salary']))
    return jsonify({'status':'good'})
Exemplo n.º 3
0
 def __check_send_status(self, button, status, receiver, message):
     flag = True
     for key in status.keys():
         if not status[key][1]:
             flag = False
             break
     if flag:
         button.set_sensitive(True)
         self.__spnnier.stop()
         failure = []
         for key in status.keys():
             if not status[key][0]:
                 failure.append(key)
         self.__generalize_status_bar()
         if not failure:
             self.__custom_status(True)
         else:
             self.__custom_status(False, failure)
         for failed in failure:
             receiver.remove(failed)
         if receiver:
             database = DataBase()
             database.save_message(message, receiver, time_stamp())
             database.close()
         return False
     return True
Exemplo n.º 4
0
 def _day_selected_cb(self, widget, data=None):
     '''Select new day'''
     date_formated = date_format(self.calendar.get_date())
     db = DataBase(self.path)
     data = db.get(date_formated)
     db.close()
     tasks_model = TasksModel(data)
     self.tasks_list.set_model(tasks_model.get_model())
Exemplo n.º 5
0
class CategoryParam(QDialog):
	def __init__(self, parent=None):
		QDialog.__init__(self)

		self.categoryParam = Ui_CatParam()
		self.categoryParam.setupUi(self)

		self.showParam()

		self.connect(self.categoryParam.btnSet,SIGNAL('clicked()'),self.setParam)
		self.connect(self.categoryParam.btnDefault,SIGNAL('clicked()'),self.setDefault)
	def setDefault(self):
		conn = sqlite3.connect('dakar.sqlite')
		cursor = conn.cursor()

		query = "UPDATE category set minRange ='0' ,maxRange ='50' where id = 1"
		cursor.execute(query)
		query = "UPDATE category set minRange ='51' ,maxRange ='99' where id = 2"
		cursor.execute(query)
		query = "UPDATE category set minRange ='100' ,maxRange ='200' where id = 3"
		cursor.execute(query)
		conn.commit()

		self.showParam()

	def setParam(self):
		conn = sqlite3.connect('dakar.sqlite')
		cursor = conn.cursor()

		minMoto = self.categoryParam.lnMinMoto.text()
		maxMoto = self.categoryParam.lnMaxMoto.text()
		minQuad = self.categoryParam.lnMinQuad.text()
		maxQuad = self.categoryParam.lnMaxQuad.text()
		minCar = self.categoryParam.lnMinCar.text()
		maxCar = self.categoryParam.lnMaxCar.text()

		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 1"%(int(minMoto),int(maxMoto))
		cursor.execute(query)
		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 2"%(int(minQuad),int(maxQuad))
		cursor.execute(query)
		query = "UPDATE category set minRange ='%i' ,maxRange ='%i' where id = 3"%(int(minCar),int(maxCar))
		cursor.execute(query)
		conn.commit()

		self.showParam()
	def showParam(self):
		self.db = DataBase()
		self.db.open('dakar.sqlite')
		rows = self.db.get_category()

		self.categoryParam.lnMinMoto.setText(str(rows[0][2]))
		self.categoryParam.lnMaxMoto.setText(str(rows[0][3]))
		self.categoryParam.lnMinQuad.setText(str(rows[1][2]))
		self.categoryParam.lnMaxQuad.setText(str(rows[1][3]))
		self.categoryParam.lnMinCar.setText(str(rows[2][2]))
		self.categoryParam.lnMaxCar.setText(str(rows[2][3]))
Exemplo n.º 6
0
 def mark_day(self):
     '''Mark the days of the month with tasks'''
     date = date_format(self.calendar.get_date())
     #just the month
     data = (date[3:],) 
     db = DataBase(self.path)
     day_list = db.get_days(data)
     db.close()
     for i in day_list:
         self.calendar.mark_day(int(i))
Exemplo n.º 7
0
            def confirm_exit(unused):
                'confirms whether to remove the only user'

                from database import DataBase
                import sys
                database = DataBase()
                database.drop_default()
                database.close()
                message.destroy()
                sys.exit(0)
Exemplo n.º 8
0
 def _delete_row_cb(self, widget, data=None):
     '''Delete a row'''
     selection = self.tasks_list.get_selection()
     model, row_iter = selection.get_selected()
     row = model[row_iter]
     data = (row[0],)
     db = DataBase(self.path)
     db.delete(data)
     db.close()
     self.get_tasks()
Exemplo n.º 9
0
 def get_tasks(self):
     '''Get the rows'''
     date_formated = date_format(self.calendar.get_date())
     db = DataBase(self.path)
     data = db.get(date_formated)
     reminder = db.get_reminder()
     db.close()
     tasks_model = TasksModel(data)
     reminder_model = TasksModel(reminder)
     self.tasks_list.set_model(tasks_model.get_model())
     self.reminder_list.set_model(reminder_model.get_model())
Exemplo n.º 10
0
    def __update_database(self, star, word):
        "updates database when a word is starred/unstarred"

        from database import DataBase
        import pickle

        database = DataBase()
        table = (len(word.query) > 1 and word.query[1] != " ") and word.query[:2] or word.query[:1]
        data = star.state == True and pickle.dumps(word) or None
        database.update(table.lower(), (word.query.lower(), data, "bengali"))
        database.close()
Exemplo n.º 11
0
 def re_log_in(unused_widget, unused_event):
     from way2sms import login
     import time
     database = DataBase()
     user = database.get_default()
     thread.start_new_thread(login, (str(user[0]), user[1], True))
     database.close()
     time.sleep(3.4)
     self.__generalize_status_bar()
     self.__push_status_message('<span font_desc="belgrano 10"><b>  Try to <span foreground="#0000FF">re send</span> once more</b></span>')
     return
Exemplo n.º 12
0
 def __send_message(self, number, message, status):
     from way2sms import send
     import time
     database = DataBase()
     customer_id = database.get_default()[2]
     for text in message:
         text = text.strip()
         status[number][0] = status[number][0] and send(customer_id, number, text)
         time.sleep(1.4)
     status[number][1] = True
     return
Exemplo n.º 13
0
    def __update_database(self, star, word):
        'updates the  database when a word is starred/unstarred'

        from database import DataBase
        import pickle
        database = DataBase()
        table = (len(word.query) > 1 and word.query[1] != ' ') and \
                                    word.query[:2] or word.query[:1]
        data = star.state == True and pickle.dumps(word) or None
        database.update(table.lower(), (word.query.lower(), data, 'english'))
        database.close()
Exemplo n.º 14
0
 def marker(selected):
     database = DataBase()
     for index in range(32):
         calendar.unmark_day(index)
     for item in database.get_dates(selected):
         calendar.mark_day(item[0])
     database.close()
     if selected[0] != self.__cur[2] or selected[1] + 1 != self.__cur[1]:
         calendar.unmark_day(self.__cur[0])
     else:
         calendar.mark_day(self.__cur[0])
     return
Exemplo n.º 15
0
    def __save(self, receiver, radio):
        'saves the user informations'

        for radio in radio.get_group():
            if radio.get_active():
                from database import DataBase
                database = DataBase()
                database.default_user(radio.get_label())
        if type(receiver) != type(self):
            self.hide_on_delete()
        gtk.main_quit()
        return False
Exemplo n.º 16
0
    def __init__(self, pifacecontrol):
        """! @brief Initialize the instance and get the two collections of the database.
        @param self the Action instance
        """
        QObject.__init__(self)
        ## contains a link to the database collection *user*
        self.users = DataBase().user
        ## contains a link to the database collection *transaction*
        self.transactions = DataBase().transaction

        self.piFace = pifacecontrol
        self.piFace.activateButtonListener()
Exemplo n.º 17
0
 def add_contacts(self):
     database = DataBase()
     for contacts in self.__contact_box.get_children():
         contacts.hide_all()
         self.__contact_box.remove(contacts)
         contacts.destroy()
     for contacts in database.select_rows('contacts'):
         from contacts import Contact
         contact = Contact(contacts)
         contact.connect('toggle', self._append_number_to_receivers)
         self.__contact_box.pack_start(contact, False, False)
     self.__contact_box.show_all()
Exemplo n.º 18
0
 def _filter_query_cb(self, widget, data=None):
     '''Query for filter the tasks'''
     category = self.combobox_q_category.get_active()
     priority = self.combobox_q_priority.get_active()
     self.combobox_q_category.set_active(-1)
     self.combobox_q_priority.set_active(-1)
     date_formated = date_format(self.calendar.get_date())
     data = (date_formated, category, priority)
     db = DataBase(self.path)
     tasks = db.filter_tasks(data)
     db.close()
     tasks_model = TasksModel(tasks)
     self.tasks_list.set_model(tasks_model.get_model())
Exemplo n.º 19
0
    def __date_change(self, calendar):
        'this method is called when a new date is selected'

        selected = calendar.get_date()

        def marker(selected):
            database = DataBase()
            for index in range(32):
                calendar.unmark_day(index)
            for item in database.get_dates(selected):
                calendar.mark_day(item[0])
            database.close()
            if selected[0] != self.__cur[2] or selected[1] + 1 != self.__cur[1]:
                calendar.unmark_day(self.__cur[0])
            else:
                calendar.mark_day(self.__cur[0])
            return

        if not selected[2]:
            return False
        thread.start_new_thread(marker, (selected,))
        calendar.select_day(0)
        database = DataBase()
        messages = database.get_message(selected)
        database.close()
        self.time_store.clear()
        self.message_scroll.hide_all()
        if messages[0] or messages[1]:
            suffix = {1:'st', 2:'nd', 3:'rd'}
            month = {0:'JAN', 1:'FEB', 2:'MAR', 3:'APR', 4:'MAY', 5:'JUN',
                     6:'JUL', 7:'AUG', 8:'SEP', 9:'OCT', 10:'NOV', 11:'DEC'}
            suffix = (suffix.has_key(selected[2] % 10) and (selected[2] < 10 \
                     or selected[2] > 20)) and suffix[selected[2] % 10] or 'th'
            month = month[selected[1]]
            date_tag = "<span font_desc='CrashNumberingGothic  12'><b>%s</b><sup>%s</sup>\
</span>  <span font_desc='CrashNumberingGothic  12'><b>%s</b></span>  <span font_desc='ca\
rbontype  12'><sup>'</sup><b>%s</b></span>" % (selected[2], suffix, month,
                                               selected[0] % 100)
            self.__date_tag.set_markup(date_tag)
            self.time_scroll.show_all()
        else:
            self.time_scroll.hide_all()
        if messages[0]:
            for message in messages[0]:
                self.time_store.append([message[0], message[1], message[2],
                    'AM', 'black', 'white', message[3], message[4], message[5]])
        if messages[1]:
            for message in messages[1]:
                self.time_store.append([message[0], message[1], message[2],
                    'PM', 'white', 'black', message[3], message[4], message[5]])
        return True
Exemplo n.º 20
0
 def __delete_user(self, unused):
     self.__generalize_status_bar()
     database = DataBase()
     edit_list = [contacts for contacts in self.__contact_box if
                  contacts.get_child().get_children()[0].get_active()]
     if not edit_list:
         self.__push_status_message('<span font_desc="belgrano 10">  Select at least <b><span foreground="#FF0000">one</span></b> contact</span>')
         return False
     contacts = [contact.get_contact_info()[1] for contact in edit_list]
     for number in contacts:
         database.delete('contacts', number)
     database.close()
     self.add_contacts()
     return False
Exemplo n.º 21
0
 def _toggle_row_cb(self, widget, path):
     '''Toggle button row'''
     model = self.tasks_list.get_model()
     row_iter = model.get_iter(path)
     #row is a gtk.TreeModelRow()
     row = model[row_iter]
     row[4] = not row[4]
     #task, completed, id for the moment category and 
     #priority are excluded
     data = (row[4], row[0])
     db = DataBase(self.path)
     db.update(data)
     db.close()
     self.get_tasks()
Exemplo n.º 22
0
 def __activate(self, unused, entry, user, password, id):            
     if entry.get_text() == str(self.__status['code']):
         from database import DataBase
         database = DataBase()
         database.add_user(user, password, id)
         if self.__set_default:
             database.default_user(user)
         self.destroy()
         return False
     entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FF8092'))
     if not self.__status['status']:
         entry.set_text('Re Send Code')
     elif entry.get_text() != str(self.__status['code']):
         entry.set_text('Incorrect Code')
     return False
Exemplo n.º 23
0
def getEmp():
    data = DataBase.getAllEmp()
    print(data)
    if not data:
        return jsonify({'status':'bad'})
    else:
        return jsonify({'status':'good','data':data})
Exemplo n.º 24
0
 def setUp(self):
     self.db = DataBase()
     self.db._change_file_name('TestDatabase.db')
     self.friends_data = \
         [{'name': 'Vasya', 'bdate': '01.03.1998', 'skype': 'blabla'},
          {'name': 'Bob', 'bdate': '03.06.1876',
           'country': 'USA', 'city': 'Boston'}]
     self.db.create(data=(self.friends_data, None))
Exemplo n.º 25
0
	def __init__( self, outFunc = None ):
		watchdog.events.FileSystemEventHandler.__init__( self )
		if not outFunc:
			outFunc = lambda x: True
		self.outFunc = outFunc
		self.ignoreFiles = []
		self.db = DataBase()
		self.queue = queue.Queue()
		self.worker = threading.Thread( target = self.worker )
Exemplo n.º 26
0
def login():
    print(request.json)
    if not request.json:
        abort(400)
    data = DataBase.isUser(request.json['Login'],Employee.hashPassword(request.json['Password']))
    if not data:
        return jsonify({'status':"Invalide user name or password"})
    else:
        return jsonify({'status':'good','data':data})
Exemplo n.º 27
0
def spinner_thread(theme_index, data_dict):
    'spinner object is activated in this thread'

    def strip_space(data):
        '''
        replaces any white space
        from a string with a '+'
        '''

        count = 0
        while count < len(data) and data[count] == ' ':
            count += 1
        if count == len(data) :
            return ''
        data = data[count:]
        word = ''
        for i in range(len(data)):
            if data[i] != ' ':
                word += data[i]
                count = 0
            else:
                count += 1
                if count == 1:
                    word += '+'
        if word[len(word) - 1] == '+':
            word = word[0:len(word) - 1]
        return word

    if InputBox.query != '':
        data_dict['text'] = InputBox.query
        data_dict['language'] = {'en': 0, 'bn': 1}[InputBox.target]
        table = (len(InputBox.query) > 1 and InputBox.query[1] != ' ') and \
                                  InputBox.query[:2] or InputBox.query[:1]
        database = DataBase()
        row = database.select_row(table, InputBox.query)
        if not row or not row[{'en': 1, 'bn': 2}[InputBox.target]]:
            data_dict['widget'] = fetch_from_web(strip_space(InputBox.query),
                                                 InputBox.target, theme_index)
        else:
            data_dict['widget'] = fetch_from_database(row, InputBox.target,
                                                      theme_index)
    gtk.main_quit()
Exemplo n.º 28
0
    def __remove_user(self, unused, radio, vbox):
        "removes a user from the users' list"

        if len(radio.get_group()) == 1:
            message = gtk.MessageDialog(type = gtk.MESSAGE_QUESTION,
                      message_format = 'WARNING', buttons = gtk.BUTTONS_YES_NO)
            text = '<span font_desc="belgrano">Do you want to actually remove\
\n  the only user <span foreground="#ff0000"><b>%s</b></span> ?</span>\n<small>\
<span font_desc="belgrano">[<i><b>The application will be closed</b> </i>]\
</span></small>' % radio.get_label()
            message.format_secondary_markup(text)
            message.set_icon_from_file(ICON_PATH + '/admin.png')
            def confirm_exit(unused):
                'confirms whether to remove the only user'

                from database import DataBase
                import sys
                database = DataBase()
                database.drop_default()
                database.close()
                message.destroy()
                sys.exit(0)
            message.get_child().get_children()[-1].get_children()[0].connect(
                                                       'clicked', confirm_exit)
            message.run()
            message.destroy()
            return
        for radio in radio.get_group():
            if radio.get_active():
                from database import DataBase
                database = DataBase()
                database.remove_user(radio.get_label())
                database.close()
                vbox = vbox.get_children()[0].get_child().get_child().\
                       get_child()
                radio.set_group(None)
                vbox.remove(radio)
                radio = vbox.get_children()[0]
                radio.set_active(True)
                radio.get_child().set_markup('<b>' + radio.get_label() + '</b>')
                break
        return
Exemplo n.º 29
0
	def showParam(self):
		self.db = DataBase()
		self.db.open('dakar.sqlite')
		rows = self.db.get_category()

		self.categoryParam.lnMinMoto.setText(str(rows[0][2]))
		self.categoryParam.lnMaxMoto.setText(str(rows[0][3]))
		self.categoryParam.lnMinQuad.setText(str(rows[1][2]))
		self.categoryParam.lnMaxQuad.setText(str(rows[1][3]))
		self.categoryParam.lnMinCar.setText(str(rows[2][2]))
		self.categoryParam.lnMaxCar.setText(str(rows[2][3]))
Exemplo n.º 30
0
    def __add_user(self, unused, radio, vbox):
        'adds a new user to the list'

        from auth import Auth
        Auth()
        gtk.main()
        from database import DataBase
        database = DataBase()
        users = database.get_username_and_password()
        current_users = [user.get_label() for user in vbox.get_children()[0].\
                         get_child().get_child().get_child().get_children()]
        for user in users:
            if str(user[0]) not in current_users:
                vbox.get_children()[0].get_child().get_child().get_child().\
                pack_start(gtk.RadioButton(radio, str(user[0])))
                from way2sms import login
                import thread
                thread.start_new_thread(login, (user[0], user[1], True))
        vbox.get_children()[0].get_child().get_child().get_child().show_all()
        return False
Exemplo n.º 31
0
def add():
	data = request.get_json()
	db = DataBase()
	user_name = data['link'].split('/')[-1]
	db.add(user_name)
	return jsonify({'success': True})
Exemplo n.º 32
0
 def previous(self):
     self.data_raw = DataBase.previous(self.data_raw['_id'])
     Thread(target=self.changePic, args=(self.data_raw['urls']['large'],)).start()
     self.copy()
Exemplo n.º 33
0
class App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.db = DataBase()
        self._db_manip = DataBase_Manipulator( self.db )
        self._db_manip_add = Database_Manipulator_Add( self.db )
        self._db_manip_del = DataBase_Manipulator_Delete( self.db )
        self._init_UI()


    def _init_UI(self):
        self.left = 300
        self.top = 180
        self.width = 853
        self.height = 310
        self._up_margin = 30
        self._left_margin = 10


        # add Menu Bar
        self._menu_bar = Menu_Bar(["File", "Edit", "About"], self)
        # File
        self._menu_bar.add_separator_to_menu("File")
        self._menu_bar.add_menu_button("File", "Create DataBase Content", "Create the content of the DataBase", self._action_create_database_content)
        self._menu_bar.add_separator_to_menu("File")
        self._menu_bar.add_menu_button("File", "Exit", "Close Window", self.close)
        # Edit
        self._menu_bar.add_separator_to_menu("Edit")
        self._menu_bar.add_menu_button("Edit", "Load Persons", "Load persons to the table.", self._action_table_update_data_persons)
        self._menu_bar.add_menu_button("Edit", "Load Events", "Load events to the table.", self._action_table_update_data_events)
        self._menu_bar.add_separator_to_menu("Edit")
        self._menu_bar.add_menu_button("Edit", "Delete Persons", "Delete selected persons from the table.", self._action_delete_persons)
        self._menu_bar.add_menu_button("Edit", "Delete Events", "Delete selected events from the table.", self._action_delete_events)
        # About
        self._menu_bar.add_separator_to_menu("About")
        #self._menu_bar.add_menu_button("About", "Program", "Informations about the program.", self._show_info_program)
        #self._menu_bar.add_menu_button("About", "Author", "Informations about the program author.", self._show_info_author)
        

        # PERSONS
        # add buttons
        self._button_load_persons = Button(
            x=self._left_margin,
            y=self._up_margin,
            text="Load Persons",
            tooltip="Load persons to the table.",
            on_click=self._action_table_update_data_persons,
            parent=self
        )
        self._button_add_person = Button(
            x=self._button_load_persons.x() + self._button_load_persons.width(), 
            y=self._up_margin, 
            width=30,
            text='+', 
            tooltip='You can add a new Person to the DataBase!', 
            on_click=self._action_add_person, 
            parent=self
        )
        # add table
        table_x = self._left_margin
        table_y = self._up_margin + self._button_load_persons.height()
        self._table_persons = Table(x=table_x, y=table_y, width=330, parent=self)
        self._delete_persons = Button(
            x=self._table_persons.x() + self._table_persons.width() - 119,
            y=self._table_persons.y() + self._table_persons.height() + 10,
            text="Delete Persons",
            tooltip="Delete persons selected on the table.",
            on_click=self._action_delete_persons,
            parent=self
        )


        # EVENTS
        # add buttons
        self._button_load_events = Button(
            x=self._table_persons.x() + self._table_persons.width() + 170,
            y=self._up_margin,
            text="Load Events",
            tooltip="Load persons to the table.",
            on_click=self._action_table_update_data_events,
            parent=self
        )
        self._button_add_event = Button(
            x=self._button_load_events.x() + self._button_load_events.width(),
            y=self._up_margin,
            width=30,
            text="+",
            tooltip="You can add a new Event to the Database!",
            on_click=self._action_add_event,
            parent=self
        )
        # add table
        table_x = self._button_load_events.x() 
        table_y = self._up_margin + self._button_load_persons.height()
        self._table_events = Table(x=table_x, y=table_y, width=330, parent=self)

        self._delete_events = Button(
            x=self._table_events.x() + self._table_events.width() - 119,
            y=self._table_events.y() + self._table_events.height() + 10,
            text="Delete Events",
            tooltip="Delete events selected on the table.",
            on_click=self._action_delete_events,
            parent=self
        )


        # OTHER
        # add buttons
        #self._button_init_db = Button(
        #    x=10,
        #    y=self._table_persons.y() + self._table_persons.height() + 10,
        #    text="Create DataBase",
        #    tooltip="You can create the DataBase content if it doesn't exists!",
        #    on_click=self._action_create_database_content,
        #    parent=self
        #)
        self._button_add_person_at_event = Button(
            x=self._left_margin + self._table_persons.x() + self._table_persons.width(),
            y=100,
            width=150,
            text="Add For Events",
            tooltip="Sign up the Persons for the Event.",
            on_click=self._action_add_person_at_event,
            parent=self
        )
        self._button_remove_person_at_event = Button(
            x=self._button_add_person_at_event.x(),
            y=self._button_add_person_at_event.y() + 85,
            width=150,
            text="Remove From Events",
            tooltip="Remove Persons from Events.",
            on_click=self._action_remove_persons_from_events,
            parent=self
        )
       
        # set window appearance
        self.setWindowTitle('Calendar Manager')
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.show()


    def _action_table_update_data_persons(self):
        self._table_persons.update_data(["id", "name", "email"], self.db.get_persons())


    def _action_table_update_data_events(self):
        self._table_events.update_data(["id", "title", "start time", "end time"], self.db.get_events())


    def _action_add_person(self):
        self._person_data_widget = Input_Person_Data_Widget(self._db_manip_add)
        self._action_table_update_data_persons()
        

    def _action_add_event(self):
        self._event_data_widget = Input_Event_Data_Widget(self._db_manip_add)
        self._action_table_update_data_events()

    def _action_add_person_at_event(self):
        persons_ids = self._table_persons.get_ids_of_selected()
        events_ids = self._table_events.get_ids_of_selected()
        if len(persons_ids) == 0 : 
                QMessageBox.about(self, "Create DataBase Content", "Select at least one person.")
        if len(events_ids) == 0 : 
                QMessageBox.about(self, "Create DataBase Content", "Select at least one event.")
        for person_id in persons_ids:
            for event_id in events_ids:
                message = self._db_manip_add.add_person_at_event({"person_id":person_id, "event_id":event_id})
                QMessageBox.about(self, "Create DataBase Content", message)


    def _action_create_database_content(self):
        message = self._db_manip.create_database_content()
        QMessageBox.about(self, "Create DataBase Content", message)


    def _action_delete_persons(self):
        for person_id in self._table_persons.get_ids_of_selected():
            message = self._db_manip_del.delete_person({"id":person_id})
            QMessageBox.about( self, "Delete Person", message )
        self._table_persons.remove_selected()


    def _action_delete_events(self):
        for event_id in self._table_events.get_ids_of_selected():
            message = self._db_manip_del.delete_event({"id":event_id})
            QMessageBox.about( self, "Delete Event", message )
        self._table_persons.remove_selected()

    def _action_remove_persons_from_events(self):
        self._output_data_widget = Output_Data_Widget(self.db)
Exemplo n.º 34
0
                }).text,
                'url':
                urljoin(
                    self.start_url,
                    soup.find('div', attrs={
                        'itemprop': 'author'
                    }).parent.get('href'))
            },
            'tags': [],
        }
        for tag in soup.find_all('a', attrs={'class': "small"}):
            tag_data = {
                'url': urljoin(self.start_url, tag.get('href')),
                'name': tag.text
            }
            data['tags'].append(tag_data)
        return data

    def get_comments(self, comments_soup):
        if comments_soup:
            print(1)

    def save(self, page_data: dict):
        self.db.create_post(page_data)


if __name__ == '__main__':
    db = DataBase('sqlite:///gb_blog.db')
    parser = GbBlogParse('https://geekbrains.ru/posts', db)

    parser.run()
Exemplo n.º 35
0
def add_trigger(message):
    try:
        if message.reply_to_message:
            if len(
                    message.text.lower()[13:]
            ) >= 3:  # and is_good_name_for_trigger(message.text.lower()):
                db = DataBase()

                if not db.is_trigger(message.text.lower()[13:],
                                     message.chat.id):
                    # добавить в бд
                    if message.reply_to_message.sticker:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.sticker.file_id,
                            "sticker", message.from_user.id,
                            message.from_user.username, message.chat.id,
                            message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.photo:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.photo[0].file_id, "photo",
                            message.from_user.id, message.from_user.username,
                            message.chat.id, message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.video:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.video.file_id, "video",
                            message.from_user.id, message.from_user.username,
                            message.chat.id, message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.voice:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.voice.file_id, "voice",
                            message.from_user.id, message.from_user.username,
                            message.chat.id, message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.audio:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.audio.file_id, "audio",
                            message.from_user.id, message.from_user.username,
                            message.chat.id, message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.document:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.document.file_id,
                            "document", message.from_user.id,
                            message.from_user.username, message.chat.id,
                            message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.video_note:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.video_note.file_id,
                            "video_note", message.from_user.id,
                            message.from_user.username, message.chat.id,
                            message.date
                        ]
                        db.add_trigger(data)
                    elif message.reply_to_message.text:
                        data = [
                            message.text.lower()[13:],
                            message.reply_to_message.text, "text",
                            message.from_user.id, message.from_user.username,
                            message.chat.id, message.date
                        ]
                        db.add_trigger(data)
                    bot.send_message(
                        message.chat.id,
                        "Триггер '" + message.text[13:] + "' добавлен.")

                else:
                    bot.send_message(
                        message.chat.id, "Триггер '" + message.text[13:] +
                        "' уже занесен в базу.")

                db.close()
            else:
                bot.send_message(message.chat.id,
                                 "Неккоректное имя триггера менее 3 символов")
        else:
            bot.send_message(message.chat.id, "Нет реплейнутого сообщения.")
    except:
        db.close()
        print("don't add_trigger.  ~~~" +
              str(time.strftime("%d.%m.%y %H:%M:%S", time.localtime())) +
              "\n\n" + traceback.format_exc() + "\n\n")
Exemplo n.º 36
0
def transfer_new_record(source_db_info,
                        destination_db_info,
                        source_table_name,
                        destination_table_name,
                        select_max_thread,
                        insert_max_thread,
                        select_max_offset,
                        insert_max_offset,
                        lock,
                        where_str=None):
    start = get_now_time_second()
    transfer_record = dict()
    transfer_record['result'] = list()
    transfer_record['select_query_status'] = list()
    transfer_record['command_query_status'] = list()
    transfer_record['sum_select_record'] = list()
    transfer_record['sum_insert_record'] = list()

    transfer_record_count = 0

    print('get source record count')

    db = DataBase(db_info=source_db_info)
    if where_str is None:
        query = 'select count(*) from {0}'.format(source_table_name)
    else:
        query = 'select count(*) from {0} where {1}'.format(
            source_table_name, where_str)

    res, err = db.select_query(query=query, args=(), mod=1)
    if err is None:
        transfer_record_count = res[0][0]

    transfer_record['transfer_record_count'] = [transfer_record_count]

    print('transfer_record_count: {}'.format(transfer_record_count))
    # ----------
    # select_query = 'select * from {}'.format(source_table_name)
    if where_str is None:
        select_query = 'select * from {0}'.format(source_table_name)
    else:
        select_query = 'select * from {0} where {1}'.format(
            source_table_name, where_str)

    args = ()

    select_thread = threading.Thread(
        name='select_thread',
        target=select_process,
        args=(transfer_record, source_db_info, select_max_thread,
              transfer_record_count, select_max_offset, lock, select_query,
              args))

    print('start select thread')
    select_thread.start()
    while not select_thread.is_alive():
        sleep(0.1)

    select_thread_name = select_thread.getName()
    #print(select_thread_name)

    insert_status_flag = [True]
    # ----------
    while len(
            transfer_record['result']
    ) < 1 and transfer_record['select_query_status'][0] != 'stopping':
        sleep(0.1)
    if len(transfer_record['result']) < 1:

        return 0, 0, transfer_record['error'], get_now_time_second() - start

    v = '%s, ' * len(transfer_record['result'][0])
    v = v.strip(', ')
    insert_query = 'insert ignore into {} values({}) '.format(
        destination_table_name, v)
    args = transfer_record['result']

    insert_thread = threading.Thread(
        name='insert_thread',
        target=command_process,
        args=(transfer_record, destination_db_info, insert_max_thread,
              insert_max_offset, lock, insert_query, args, insert_status_flag))

    print('start insert thread')
    insert_thread.start()
    while not insert_thread.is_alive():
        sleep(0.1)

    # ----------
    while transfer_record['select_query_status'][0] != 'stopping':
        #print('{}: {}/{}'.format(transfer_record_count, transfer_record['sum_select_record'][0], transfer_record['sum_insert_record'][0]))
        sleep(0.1)
    insert_status_flag[0] = False
    #print('-----------insert_status_flag: {}'.format(insert_status_flag[0]))

    for t in threading.enumerate():
        if t != threading.main_thread():
            #print('--------{}----------'.format(t.getName()))
            t.join()

    # sleep(1)
    new_record_count = transfer_record_count
    total_transfer_record = transfer_record['sum_insert_record'][0]
    error = transfer_record['error']
    run_time = get_now_time_second() - start

    return new_record_count, total_transfer_record, error, run_time
Exemplo n.º 37
0
# local import
from database import (DataBase, add_color_from_JMOL, add_f0_from_intertab,
                      add_f1f2_from_kissel, add_mass_from_NIST,
                      add_radius_from_WIKI, init_material_db)

verbose = False

if len(sys.argv) > 1:
    fname = sys.argv[1]
if len(sys.argv) > 2:
    dataroot = sys.argv[2]
else:
    dataroot = os.path.join(os.path.dirname(__file__), 'data')

dbf = DataBase(fname)
dbf.Create('elementdata',
           'Database with elemental data from XOP and Kissel databases')

init_material_db(dbf)

# add a dummy element, this is useful not only for testing and should be
# kept in future! It can be used for structure factor calculation tests, and
# shows how the a database entry can be generated manually
dbf.SetMaterial('dummy')
dbf.SetF0([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])  # atomic structure factors
dbf.SetF1F2((0, 1e5), (0, 0), (0, 0))  # zero dispersion correction

add_mass_from_NIST(dbf, os.path.join(dataroot, 'nist_atom.dat'), verbose)
add_color_from_JMOL(dbf, os.path.join(dataroot, 'colors.dat'), verbose)
add_radius_from_WIKI(dbf, os.path.join(dataroot, 'atomic_radius.dat'), verbose)
Exemplo n.º 38
0
import os
import re
import time

import telebot

from availablecommands import commands
from botstate import BotState
from database import DataBase
from yandexdisk import YandexDisk
from mthreading import mult_threading
import schedule
from commands.publish import send_photos

database = DataBase()
ydisk = YandexDisk(token=os.environ["YADISKTOKEN"])
bot = telebot.TeleBot(os.environ['TOKEN'])
bot_state = BotState(saved_commands=commands.get_na_commands())


@mult_threading
def time_publish():
    # schedule.every().day.at("20:00").do(send_photos, bot, database, ydisk, 10)
    schedule.every(2).hours.do(send_photos, bot, database, ydisk, 1)
    while True:
        schedule.run_pending()
        time.sleep(1)


@bot.message_handler(content_types=["text"])
def answer_commands(message):
Exemplo n.º 39
0
                  size_hint=(None, None), size=(400, 400))
    pop.open()


def invalidForm():
    pop = Popup(title='Invalid Form',
                  content=Label(text='Please fill in all inputs with valid information.'),
                  size_hint=(None, None), size=(400, 400))

    pop.open()


kv = Builder.load_file("my.kv")

sm = WindowManager()
db = DataBase("users.txt")

screens = [LoginWindow(name="login"), CreateAccountWindow(name="create"),MainWindow(name="main")]
for screen in screens:
    sm.add_widget(screen)

sm.current = "login"


class MyMainApp(App):
    def build(self):
        return sm


if __name__ == "__main__":
    MyMainApp().run()
Exemplo n.º 40
0
	insertsql1 = """
	INSERT
	INTO Student(snao,Sname,Ssex,Sdept,Sage)
	VALUES('20151218','CHENDONG',"MAN","IS",18)
	"""
	insertsql2 = """
	INSERT
	INTO Student
	VALUES('20151218','CHENDONG',"MAN","IS",18)
	"""
	insertsql3 = """
	INSERT
	INTO Student(Sdept,Sage)
	VALUES("IS",18)
	"""
    ctx.db = DataBase()
    ctx.db.insert_record()





if __name__ == '__main__':
	# try:
	# 	TestInsert()
	# except Exception, e:
	# 	print e

	# print "============"
	# try:
	# 	TestDele()
Exemplo n.º 41
0
from database import DataBase

fileName = input('Введите путь к файлу с IDs:\n')

ids = []
with open(fileName, 'r') as f:
    ids = f.read().split()
    db = DataBase()
    for i in range(len(ids)):
        print('{} / {}'.format(i, len(ids)), end='\r')
        db.add(ids[i])
Exemplo n.º 42
0
class Application(tornado.web.Application):
    def __init__(self):
        settings = {
            "static_path": os.path.join(os.path.dirname(__file__), "static"),
        }
        handlers = [
            (r'/', IndexHandler),
            (r'/admin', AdminHandler),
            (r'/admin/connections', AdminConnectionsHandler),
            (r'/admin/logs', AdminLogHandler),
            (r'/admin/history', AdminHistoryHandler),
            (r'/admin/search', AdminSearchHandler),
            (r'/restart', RestartHandler),
            (r'/ws/speech', WavWebSocketHandler),
            (r'/ws/decode', DecodeWebSocketHandler),
            (r'/static/', tornado.web.StaticFileHandler,
             dict(path=settings['static_path'])),
        ]
        tornado.web.Application.__init__(self, handlers, **settings)
        self.counter = 0
        self.num_connection = 0
        self.connections = set()
        self.decoders = {}
        self.decoders_info = {}
        self.decoders_list_lock = threading.Lock()
        self.load_config('main.cfg')

    def load_config(self, config_file):
        #TODO, add other config item
        config = ConfigParser.ConfigParser()
        config.read(config_file)
        # config server port
        self.port = config.getint('master', 'port')
        # config log
        self.log_file = config.get('master', 'log_file')
        logging.basicConfig(
            level=logging.DEBUG,
            format=
            '%(levelname)s %(asctime)s (%(filename)s:%(funcName)s():%(lineno)d) %(message)s',
            filename=self.log_file,
            filemode='a')
        # config decoder cluster
        for item in config.items('decoders'):
            #check ip and port
            arr = item[1].split(':')
            assert (len(arr) == 3)
            ip, port, max_thread = arr[0], int(arr[1]), int(arr[2])
            assert (port > 0 and port < 65535)
            logging.debug("add decoder " + item[1])
            self.decoders[(ip, port)] = max_thread
            self.decoders_info[(ip, port)] = max_thread
        assert (len(self.decoders) > 0)
        # config database
        db_file = config.get('master', 'database')
        self.db = DataBase(db_file)
        # config user-data
        self.user_data_dir = config.get('master', 'user_data_dir')
        if not os.path.exists(self.user_data_dir):
            os.makedirs(self.user_data_dir)

    def start(self):
        logging.info('server start, port: %d...' % self.port)
        try:
            self.listen(self.port)
            tornado.ioloop.IOLoop.current().start()
        except:
            self.db.close()
Exemplo n.º 43
0
from puzzle_generator import get_puzzle
from database import DataBase as DB

db = DB()
get_puzzle(db.getMatrix())
Exemplo n.º 44
0
def get_github_repos():
    repos = []
    for repo in github.get_user().get_repos(visibility="public"):
        try:
            contents = repo.get_contents("README.md")
            repos.append(dict({"repo_name": repo.name, "readme": contents.decoded_content.decode("utf-8"),
                               "repo_url": repo.url}))
        except UnknownObjectException as e:
            print(e)
    return repos

github = Github(os.environ["GITHUB_TOKEN"])
app = Flask(__name__)
github_projects = get_github_repos()
db_client = DataBase(database="projects", projects=github_projects)


@app.route('/')
def index():
    print("print projects")
    for i in range(len(github_projects)):
        github_projects[i]['readme'] = markdown2.markdown(github_projects[i]['readme'])
    return render_template('index.html', github_projects=github_projects)

@app.route("/project/<repo_name>")
def project(repo_name):
    project_info = db_client.get_project(repo_name)
    readme = markdown2.markdown(project_info['readme'])

    return render_template("project.html", repo_name=project_info['repo_name'],
Exemplo n.º 45
0
#-*- coding: utf-8 -*-
import sys
import json
import random
import string
from flask import Flask, request, jsonify, abort

from database import DataBase

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
app.config["JSON_SORT_KEYS"] = False

db = DataBase()
FIRST_TOKEN = ""
SESSION_KEY = ""


# ランダムキー生成用関数
def randomkey():
    randlst = [
        random.choice(string.ascii_letters + string.digits) for i in range(32)
    ]
    return ''.join(randlst)


# AES decoder関数
def decode(string, passwd):
    pass

Exemplo n.º 46
0
def main(urls_file_name):
    db = DataBase()
    db.init_database()

    web_scraper = WebScraper()
    web_scraper.start(urls_file_name)
Exemplo n.º 47
0
def get_topchik(week=True):
    db = DataBase()
    try:
        result = ''
        response = db.select_top_count_battle(1, week)
        if response:
            result = '<u><b>Самый впрягающийся</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))

        response = db.select_top_last_hit(1, week)
        if response:
            result += '<u><b>Убийца</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))

        response = db.select_top_exp(1, week)
        if response:
            result += '<u><b>Самый опытный</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))

        response = db.select_top_gold(1, week)
        if response:
            result += '<u><b>Самый богатый</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))

        response = db.select_top_stock(1, week)
        if response:
            result += '<u><b>Самый запасливый</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))

        response = db.select_top_hp(1, week)
        if response:
            result += '<u><b>Человек-месиво</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))
            # result = '\n'.join('.'.join(map(str, s)) for s in query)

        response = db.select_top_knockout(1, week)
        if response:
            result += '<u><b>Человек-зомби</b></u>\n{0}\t{1}\n\n'.format(
                str(response[0][1]), str(response[0][0]))
            # result = '\n'.join('.'.join(map(str, s)) for s in query)

        db.close()
        if result != '':
            bot.send_message(ADEPT_ID, result, parse_mode='HTML')
        else:
            bot.send_message(ADEPT_ID, 'Нет еще топчика в этом чатике)')
    except:
        print("don't get_topchik.  ~~~" +
              str(time.strftime("%d.%m.%y %H:%M:%S", time.localtime())) +
              "\n\n" + traceback.format_exc() + "\n\n")
        db.close()
Exemplo n.º 48
0
 def setUp(self):
     self.db = DataBase(self.full_db_path)
Exemplo n.º 49
0
# pylint: disable=invalid-name
# %%
# Imports
import datetime as dt
import os
import pandas as pd
from database import DataBase as db

# %%
# Get all the values
PATH = os.environ['PATH_APR']
sql = """SELECT v.PO, v.family, v.area, v.parameter, v.value,
         o.batch, o.material, o.description, o.launch_date
         FROM cpv.params_values v, cpv.process_orders o
         where v.po = o.process_order"""
df_params = db.select(sql)
df_params["value"] = pd.to_numeric(df_params["value"], errors='coerce')
df_params.head()


#%%
# Save Files
def save_files(path_base):
    """Saves  csv files to disk"""
    products = df_params.loc[:, "family"].unique()
    for product in products:
        df = df_params.loc[df_params['family'] == product]
        df = pd.pivot_table(df,
                            values='value',
                            index=[
                                'PO', 'batch', 'material', 'description',
Exemplo n.º 50
0
    def test_basics(self):
        """Tests creating, opening, closing and deleting a database."""
        # test the creation for a database
        db_path = 'tests'
        db_name = 'basic_tests'
        full_path = db_path + '\\' + db_name
        db = DataBase(full_path)

        self.assertEqual(db.name, db_name)
        self.assertEqual(db.path, db_path)
        self.assertEqual(db.full_path, full_path)
        self.assertTrue(os.path.exists(full_path + '.fs'))
        self.assertTrue(os.path.exists(full_path + '.fs.index'))
        self.assertTrue(os.path.exists(full_path + '.fs.lock'))
        self.assertTrue(os.path.exists(full_path + '.fs.tmp'))

        # test closing the DataBase object
        ret = db.close()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_closed(db)

        # test recloseing the DataBase object
        ret = db.close()
        self.assertEqual(ret, 1)
        self.assert_db_is_proper_closed(db)

        # test opening a DataBase object
        ret = db.open()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_opened(db)

        # test reopeing a DataBase object
        ret = db.open()
        self.assertEqual(ret, 1)
        self.assert_db_is_proper_opened(db)

        # test _total_extinction of the database
        db._total_extinction()

        self.assertFalse(os.path.exists(full_path + '.fs'))
        self.assertFalse(os.path.exists(full_path + '.fs.index'))
        self.assertFalse(os.path.exists(full_path + '.fs.lock'))
        self.assertFalse(os.path.exists(full_path + '.fs.tmp'))

        # test recreating database
        ret = db.open()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_opened(db)

        db._total_extinction()
Exemplo n.º 51
0
class Producer(multiprocessing.Process):

    def __init__(self, nodes_ip, cluster_list, num_consumers, db_path, result_path="./.roce_result", target_path="/root/.roce"):
        multiprocessing.Process.__init__(self)
        self.nodes_ip = nodes_ip
        self.cluster_list = cluster_list
        self.result_path = result_path
        self.target_path = target_path
        self.num_consumers = num_consumers

        self.db = DataBase(db_path)

    def same_cluster(self, ip1, ip2):
        # do not test for ip in the same cluster

        # TODO: more efficient way!

        if self.cluster_list == None: return False
        for cluster in cluster_list:
            if ip1 in cluster and ip2 in cluster:
                return True
        return False
    
    def run(self):
        # Store pid, date into DataBase
        self.db.update_info(self.pid, start=now())

        # Init node info
        nodes_info = {}
        for ip in self.nodes_ip:
            nodes_info[ip] = NodeInfo(ip)

        # Establish communication queues
        tasks = multiprocessing.JoinableQueue()
        results = multiprocessing.Queue()

        # Create result path
        remove_dir(self.result_path)
        make_dir(self.result_path)
        for kind in TaskKind:
            make_dir(os.path.join(self.result_path, kind.value))

        # Start consumers
        print('Creating {} consumers'.format(self.num_consumers))
        consumers = [
            Consumer(tasks, results, self.result_path, self.target_path)
            for _ in range(self.num_consumers)
        ]

        for w in consumers:
            w.daemon = True
            w.start()
        

        db = self.db
        def signal_handler(*args):
            for c in consumers:
                os.kill(c.pid, signal.SIGTERM)
            db.update_info(-1, end=now())
            sys.exit()
        signal.signal(signal.SIGTERM, signal_handler)

        # Start Time
        print("Test Start at {}".format(now()))

        # Number of Task have enqueue
        ntasks = 0

        # Enqueue task first - "no password check"
        for ip in self.nodes_ip:
            tasks.put(Task(kind=TaskKind.NOPWCHECK, ip=ip))
            nodes_info[ip].status = TaskKind.NOPWCHECK
            # +2 because there is ACCEPT and SUCC -> two result
            ntasks += 2
            self.db.update_top(ip, TaskKind.NOPWCHECK, Result.WAIT, now())
        
        conn_check_waiting_list = []
        
        # Generate port List for ucx test
        # [2001, 2002, ..., 2000+len(nodes_ip)]
        port_list = [2001+i for i in range(0, len(self.nodes_ip))]
        

        while ntasks > 0:
            result = results.get()
            ntasks -= 1

            print('Result: {}'.format(result))

            if result.code == Result.SUCC:
                # enqueue more task
                if result.kind == TaskKind.NOPWCHECK:
                    tasks.put(Task(kind=TaskKind.ENVCHECK, ip=result.ip))
                    nodes_info[result.ip].status = TaskKind.ENVCHECK
                    ntasks += 2
                    self.db.update_top(result.ip, TaskKind.ENVCHECK, Result.WAIT, now())

                elif result.kind == TaskKind.ENVCHECK:
                    tasks.put(Task(kind=TaskKind.SETUP, ip=result.ip))
                    nodes_info[result.ip].status = TaskKind.SETUP
                    ntasks += 2
                    self.db.update_top(result.ip, TaskKind.SETUP, Result.WAIT, now())

                elif result.kind == TaskKind.SETUP:
                    self.db.delete_top(result.ip)
                    for ip in conn_check_waiting_list:
                        ip1, ip2 = (result.ip, ip) if IPAddress(result.ip) < IPAddress(ip) else (ip, result.ip)
                        tasks.put(Task(kind=TaskKind.CONNCHECK, ip=[ip1, ip2]))
                        ntasks += 2
                        self.db.update_top([ip1, ip2], TaskKind.CONNCHECK, Result.WAIT, now())
                    conn_check_waiting_list.append(result.ip)
                    nodes_info[result.ip].status = TaskKind.CONNCHECK
                
                elif result.kind == TaskKind.CONNCHECK:
                    self.db.delete_top(result.ip)
                    ip1 = result.ip[0]
                    ip2 = result.ip[1]

                    if self.same_cluster(ip1, ip2):
                        continue

                    if nodes_info[ip1].occupied is False and \
                        nodes_info[ip2].occupied is False:
                        # both ip is available
                        self.do_ucx_test(tasks, ip1, ip2, port_list)
                        ntasks += 2
                        
                        # Occupied
                        nodes_info[ip1].occupied = True
                        nodes_info[ip2].occupied = True
                    else:
                        # at lease have one ip is not available
                        nodes_info[ip1].dep_list.append(ip2)
                        nodes_info[ip2].dep_list.append(ip1)

                elif result.kind == TaskKind.UCXTEST:
                    self.db.delete_top(result.ip)

                    ip1 = result.ip[0]
                    ip2 = result.ip[1]
                    self.handle_ucx_test_result(result)
                    
                    # Just go ahead and do next two-IPs test
                    assert nodes_info[ip1].occupied == True
                    assert nodes_info[ip2].occupied == True

                    # Do perf_v2_test
                    self.do_perf_v2_test(tasks, ip1, ip2, port_list)
                    ntasks += 2

                    # Maybe have to enqueue more task
                elif result.kind == TaskKind.PERFV2TEST:
                    self.db.delete_top(result.ip)
                    self.handle_perf_v2_test_result(result)

                    nodes_info[result.ip[0]].occupied = False
                    nodes_info[result.ip[1]].occupied = False

                    # Find dependence, and Enqueue new UCX task
                    for ipx in result.ip:
                        if nodes_info[ipx].occupied is True: continue
                        for ipy in nodes_info[ipx].dep_list :
                            if nodes_info[ipy].occupied is False:
                                ip1, ip2 = (ipx, ipy) if IPAddress(ipx) < IPAddress(ipy) else (ipy, ipx)
                                self.do_ucx_test(tasks, ip1, ip2, port_list)
                                ntasks += 2
                                
                                # Occupied
                                nodes_info[ip1].occupied = True
                                nodes_info[ip2].occupied = True

                                # Remove from List
                                nodes_info[ip1].dep_list.remove(ip2)
                                nodes_info[ip2].dep_list.remove(ip1)

                                break


            elif result.code == Result.FAILED:
                if type(result.ip) == str:
                    nodes_info[result.ip].status = Result.FAILED
                    self.db.update_top(result.ip, result.kind, Result.FAILED, now())
                else:
                    assert type(result.ip) == list
                    assert len(result.ip) == 2
                    nodes_info[result.ip[0]].status = Result.FAILED
                    nodes_info[result.ip[1]].status = Result.FAILED
                    self.db.update_top(result.ip, result.kind, Result.FAILED, now())

                    # release
                    nodes_info[result.ip[0]].ocupied = False
                    nodes_info[result.ip[1]].ocupied = False

            elif result.code == Result.ACCEPT:
                # Update database
                self.db.update_top(result.ip, result.kind, Result.ACCEPT, now())
            

        # CleanUp for every remote machine
        for ip in self.nodes_ip:
            tasks.put(Task(kind=TaskKind.CLEAN, ip=ip))
            ntasks += 2
            # Do not show CLEAN phase (it will overwrite previous failure information)
            #self.db.update_top(ip, TaskKind.CLEAN, Result.WAIT, now())

        while ntasks > 0:
            result = results.get()
            ntasks -= 1

            print('Result: {}'.format(result))
            if result.kind == TaskKind.CLEAN:
                #self.db.delete_top(result.ip)
                if result.code == Result.FAILED:
                    assert type(result.ip) == str, "CLEAN IP: {}".format(result.ip)
                    #self.db.update_top(result.ip, result.kind, Result.FAILED, now())
                    print("{} CLEAN FAILED".format(result.ip))
                #elif result.code == Result.ACCEPT:
                    #self.db.update_top(result.ip, result.kind, Result.ACCEPT, now())
            else:
                raise Exception("Clean must be after all tasks finished")
        
        # Wait for all of the tasks to finish
        tasks.join()

        # Add a poison pill for each consumer
        for _ in range(self.num_consumers):
            tasks.put(None)

        self.db.update_info(-1, end=now())

    def do_ucx_test(self, tasks, ip_to, ip_from, port_list):
        '''
        args:
            tasks     : multiprocessing.JoinableQueue, the task queue to consumers
            ip_to     : str, the ip address of test node
            ip_from   : str, the ip address of test node
            port_list : list(int), the port list genreate by Producer
        '''
        idx = sum([self.nodes_ip.index(ip) for ip in [ip_to, ip_from]]) % len(self.nodes_ip)
        port = port_list[idx]
        tasks.put(Task(kind=TaskKind.UCXTEST, ip=[ip_to, ip_from], port=port))
        self.db.update_top([ip_to, ip_from], TaskKind.UCXTEST, Result.WAIT, now())


    def do_perf_v2_test(self, tasks, ip_to, ip_from, port_list):
        '''
        args:
            tasks     : multiprocessing.JoinableQueue, the task queue to consumers
            ip_to     : str, the ip address of test node
            ip_from   : str, the ip address of test node
            port_list : list(int), the port list genreate by Producer
        '''
        idx = sum([self.nodes_ip.index(ip) for ip in [ip_to, ip_from]]) % len(self.nodes_ip)
        port = port_list[idx]
        tasks.put(Task(kind=TaskKind.PERFV2TEST, ip=[ip_to, ip_from], port=port))
        self.db.update_top([ip_to, ip_from], TaskKind.PERFV2TEST, Result.WAIT, now())


    def handle_ucx_test_result(self, result):
        ip1 = result.ip[0]
        ip2 = result.ip[1]
        stdout = result.stdout.decode().strip()

        for line in stdout.split('\n'):
            line = line.strip()
            words = line.split(",")
            assert len(words) == 9, "ucx IP1: {}, IP2: {}, words: {}".format(ip1, ip2, words)
            data = [ip1, ip2] + words
            self.db.update_ucx_test(data)


    def handle_perf_v2_test_result(self, result):
        ip1 = result.ip[0]
        ip2 = result.ip[1]
        stdout = result.stdout.decode().strip()

        for line in stdout.split('\n'):
            line = line.strip()
            words = line.split(",")
            assert len(words) == 4, "perf IP1: {}, IP2: {}, words: {}".format(ip1, ip2, words)
            data = [ip1, ip2] + words
            self.db.update_perf_test(data)
Exemplo n.º 52
0
class DataBaseTest0(TestCase):
    db_path = 'tests'
    db_name = 'general_test_base'

    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)
        self.immutables = [
            True, False, None, 7357, 42, (True, 69), (1337, ()), '\n +  \t',
            'test',
            frozenset([1, "a", "\n"]),
            frozenset([1, ('r', 2), "a", "\n"])
        ]
        self.db_path = 'tests'
        self.db_name = 'general_test_base'
        self.full_db_path = self.db_path + '\\' + self.db_name

    def setUp(self):
        self.db = DataBase(self.full_db_path)

    def tearDown(self):
        self.db._total_extinction()

    def assert_db_is_proper_closed(self, db):
        self.assertIsNone(db._db)
        self.assertIsNone(db._root)
        self.assertIsNone(db._storage)
        self.assertIsNone(db._connection)
        self.assertTrue(db.is_closed)
        self.assertFalse(db.is_opened)

    def assert_db_is_proper_opened(self, db):
        self.assertIsNotNone(db._db)
        self.assertIsNotNone(db._root)
        self.assertIsNotNone(db._storage)
        self.assertIsNotNone(db._connection)
        self.assertFalse(db.is_closed)
        self.assertTrue(db.is_opened)

    def test_basics(self):
        """Tests creating, opening, closing and deleting a database."""
        # test the creation for a database
        db_path = 'tests'
        db_name = 'basic_tests'
        full_path = db_path + '\\' + db_name
        db = DataBase(full_path)

        self.assertEqual(db.name, db_name)
        self.assertEqual(db.path, db_path)
        self.assertEqual(db.full_path, full_path)
        self.assertTrue(os.path.exists(full_path + '.fs'))
        self.assertTrue(os.path.exists(full_path + '.fs.index'))
        self.assertTrue(os.path.exists(full_path + '.fs.lock'))
        self.assertTrue(os.path.exists(full_path + '.fs.tmp'))

        # test closing the DataBase object
        ret = db.close()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_closed(db)

        # test recloseing the DataBase object
        ret = db.close()
        self.assertEqual(ret, 1)
        self.assert_db_is_proper_closed(db)

        # test opening a DataBase object
        ret = db.open()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_opened(db)

        # test reopeing a DataBase object
        ret = db.open()
        self.assertEqual(ret, 1)
        self.assert_db_is_proper_opened(db)

        # test _total_extinction of the database
        db._total_extinction()

        self.assertFalse(os.path.exists(full_path + '.fs'))
        self.assertFalse(os.path.exists(full_path + '.fs.index'))
        self.assertFalse(os.path.exists(full_path + '.fs.lock'))
        self.assertFalse(os.path.exists(full_path + '.fs.tmp'))

        # test recreating database
        ret = db.open()
        self.assertEqual(ret, 0)
        self.assert_db_is_proper_opened(db)

        db._total_extinction()

    def test_context_manager(self):
        """"""  # todo docstrings schreiben
        db_path = 'tests'
        db_name = 'context_manager_test'
        full_path = db_path + '\\' + db_name
        immutables_rev = list(reversed(self.immutables))
        test_root = zip(immutables_rev, self.immutables)

        # writing data into database
        with DataBase(full_path) as db:
            self.assert_db_is_proper_opened(db)
            for key, value in test_root:
                db[key] = value

        # ensure that the database was closed by checking if accessing is possible
        db = DataBase(full_path)

        # checking correctness and completeness of stored data
        for key, value in test_root:
            self.assertIn(key, db.keys())
            self.assertIn(value, db.values())
            self.assertEqual(db[key], value)

        # manual teardown
        db._total_extinction()

    def test_auto_open(self):
        """Testing the constructor on the functionality of the parameter auto_open."""
        # todo implement

    def test_simple_immutable_storage(self):
        """Tests persistence of little amount of immutable objects when stored in a DataBase object."""
        immutables_rev = list(reversed(self.immutables))
        test_root = zip(immutables_rev, self.immutables)
        for key, value in test_root:
            self.db[key] = value

        self.db.close()
        self.db.open()

        for key, value in test_root:
            self.assertIn(key, self.db.keys())
            self.assertIn(value, self.db.values())
            self.assertEqual(self.db[key], value)
Exemplo n.º 53
0
#!/usr/local/bin/python2.7
#python search.py -i dataset/image.jpg

import cv2
import traceback
import urllib
import numpy as np
from scipy.cluster.vq import *
from sklearn import preprocessing

from database import DataBase
from config import Config
from descriptors.feature import Descriptor

# Load the classifier, class names, scaler, number of clusters and vocabulary (voc)
db = DataBase()
descriptorHandler = Descriptor(Config)
settings = Config.Settings
Datasets = {}

for key, value in Config.Features.iteritems():
    filename = "{}/{}_{}_kmeans{}_{}".format(settings["ROOT_DATASET_FOLDER"],
                                             settings["TRAIN_DATASET"], value,
                                             Config.KMeans["TYPE"],
                                             settings["FEATURE_FILE"])
    if db.checkFile(filename):
        (image_paths, im_features, idf, numWords, voc) = db.read(filename)
        Datasets[value] = (image_paths, im_features, idf, numWords, voc)


def getQueryImage(image_path, cx=0, cy=0, cw=0, ch=0):
Exemplo n.º 54
0
    pop = Popup(title='Invalid Form',
                content=Label(
                    text='Please fill in all inputs with valid information.'),
                size_hint=(None, None),
                size=(400, 400))

    pop.open()


with open("wallets.txt", "r") as f:
    wallets = f.readlines()
    wallets = [x.strip("\n") for x in wallets]

kv = Builder.load_file("my.kv")
sm = WindowManager()
db = DataBase("./monero/", wallets)

screens = [
    LoginWindow(name="login"),
    CreateAccountWindow(name="create"),
    MainWindow(name="main")
]
for screen in screens:
    sm.add_widget(screen)

sm.current = "login"


class MyMainApp(App):
    def build(self):
        #if doesnt work switch sm to kv
Exemplo n.º 55
0
 def next_R18(self):
     self.data_raw = DataBase.next_r18(self.data_raw['_id'])
     Thread(target=self.changePic, args=(self.data_raw['urls']['large'],)).start()
     self.copy()
Exemplo n.º 56
0
import base64
import hashlib
import os

from flask import *
from database import DataBase

app = Flask(__name__)
db = DataBase()


def get_if_in(key: str, form: dict, default=None):
    if key in form:
        return form[key]
    return default


@app.route('/', methods=['GET'])
def index():
    return '<a href="https://github.com/LanceLiang2018/Go-Online">https://github.com/LanceLiang2018/Go-Online</a>'


@app.route('/play/<string:code>/', methods=['POST', 'GET'])
def play(code: str):
    if request.method == 'GET':
        return jsonify(db.read(code))
    # POST 部分
    form = request.form
    if 'action' not in form:
        return db.make_result(1, message='No action selected')
    action = form['action']
Exemplo n.º 57
0
class WebScraper:
    def __init__(self):
        self.db = DataBase()

    def start(self, urls_file_name):
        '''
		gets urls' file name, read the urls to list,
		execute thread pool of 4 workers for scraping amazon and ebay products
		'''
        urls = self.get_urls_list(urls_file_name)
        with ThreadPoolExecutor(max_workers=4) as executor:
            for url in urls:
                if self.check_website_type_by_url(url) == AMAZON:
                    executor.submit(self.extract_amazon_product, url)
                else:
                    executor.submit(self.extract_ebay_product, url)

    def get_urls_list(self, file_name):
        urls_list = []
        f = open(file_name, 'r')
        my_file_data = f.read()
        f.close()
        urls_list = my_file_data.split('\n')
        return urls_list

    def check_website_type_by_url(self, url):
        if url.find(AMAZON, 12) != NA:
            return AMAZON
        else:
            return EBAY

    def extract_amazon_product(self, url):
        url_content_res = self.download_url_content(url)
        if url_content_res != NA:
            soup = BeautifulSoup(url_content_res.text, "lxml")
            price = soup.find(id="priceblock_ourprice").get_text()
            str_name = soup.find(id="productTitle").get_text()
            name = str_name.strip()
            amazon_product = Product(name, price)
            self.insert_product(amazon_product)
        else:
            print("URL content is NOT avaliable")

    def extract_ebay_product(self, url):
        url_content_res = self.download_url_content(url)
        if url_content_res != NA:
            soup = BeautifulSoup(url_content_res.text, "lxml")
            str_price = soup.find(id="prcIsum").get_text()
            price = str_price[4:]
            str_name = soup.find(id="itemTitle").get_text()
            name = str_name[16:]
            ebay_product = Product(name, price)
            self.insert_product(ebay_product)
        else:
            print("URL content is NOT avaliable")

    def download_url_content(self, url):
        ua = {"User-Agent": "Mozilla/5.0"}
        res = requests.get(url, headers=ua)
        if res.status_code == OK:
            return res
        else:
            print("requests NOT OK!")
            return NA

    def insert_product(self, product):
        self.db.insert_product(product)
Exemplo n.º 58
0
    pop.open()


def existing_user():
    pop = Popup(title='Existing user',
                content=Label(text='Email already registered'),
                size_hint=(None, None),
                size=(400, 400))

    pop.open()


kv = Builder.load_file("cred.kv")

sm = WindowManager()
db = DataBase("login_app/users.txt")

screens = [
    LoginWindow(name="login"),
    CreateAccountWindow(name="create"),
    MainWindow(name="main")
]
for screen in screens:
    sm.add_widget(screen)

sm.current = "login"


class MyApp(App):
    def build(self):
        return sm
class AnomalyDomain (Process):
    # initilize data 
    def __init__(self, name, host) :
        super(AnomalyDomain, self).__init__()
        self.name = name
        self.db = DataBase(host=host, database="anomaly", collection="data")
        self.last_update = ""
        self.last_value = 0
        
        self.timeline = []
        for i in range(24) :
            hour_detection = Amean()
            self.timeline.append(hour_detection)
        
        self.timeline_weekend = []
        for i in range(24) :
            hour_detection = Amean()
            self.timeline_weekend.append(hour_detection)        
        return 

    def __predict (self, hour=0, current=0, angle=0, date="") :
        """predict and return value for new data point"""
        date = datetime.strptime(date, "%Y-%m-%d")
        code = self.timeline[hour].predict(current=current, angle=angle)
        if code == '' :
            return 10
        else :
            return code
            

    def __log (self, msg) :
        with open("log.txt","a") as f :
            f.write(msg + '\n')
        return 

    def __check_new_data (self, name) :
        """check if there is new data in repo
            if yes, return all new data"""
        # check if repo is null (start-date = null)
        if self.last_update == "" :
            start_date = self.db.get_start_date(name=name)
            if start_date != '' :
                self.last_update = start_date

        # check last update
        # go to database and get last_update, then update data in anomaly class (this class)
        db_last_update = self.db.get_last_update(name=name)
        print("db_last_update: ",db_last_update)
        if db_last_update == '' or not db_last_update:
            return []
        else :
            db_last_update = datetime.strptime(db_last_update, "%Y-%m-%d %H")  
        last_update = datetime.strptime(self.last_update,  "%Y-%m-%d %H")
        result = []
        while last_update < db_last_update :
            print("db_last_update: ", name," ", db_last_update)
            last_update += timedelta(seconds=3600)
            print("check last update :", last_update)
            date = last_update.strftime("%Y-%m-%d")
            hour = last_update.hour
            data_value = self.db.get_data_by_hour(name=name, date=date, hour=hour) 
            self.__log(date + ' ' + str(hour) + ' ' + str(data_value))
            data = {'angle':float(data_value)-float(self.last_value),
                    'current':data_value,
                    'date':date,
                    'hour':hour}
            result.append(data)
            self.last_value = data_value  
            
        self.last_update = datetime.strftime(last_update, '%Y-%m-%d %H')
        return result
        

    def __save_result (self, name, date, result) :
        self.db.insert_result(name=name, date=date, value=result)
        return 
        
    
    #=========================  RUN   ==============================    
    # Run process method
    # start per process by calling run()
    def run(self) :
        name = self.name     
        try :
            while True :
                time.sleep(10) 

                data = self.__check_new_data (name)
                # data :
                # [] : no new data
                # [ {date:, hour:, current:, angle:)]
                print("--------------AnomalyDomain is running1--------------")
                if data != [] :
                    print("--------------AnomalyDomain is running2--------------")
                    # predict new data
                    for hour_data in data :                
                        result_prediction = self.__predict(hour=hour_data['hour'], 
                                                           current=hour_data['current'], 
                                                           angle=hour_data['angle'],
                                                           date=hour_data["date"])
                        # save result to db
                        self.__save_result(name=name,
                                           date=hour_data['date']+' '+str(hour_data['hour']),
                                           result=result_prediction)
                
                #continue waiting 
        except Exception as e: 
            with open("log.txt","a") as f :
                f.write(str(e) + '\n')
                traceback.print_exc()
Exemplo n.º 60
0
 def __init__(self):
     self.db = DataBase()