コード例 #1
0
    def new_book(self, title, author, publisher, year, edition, genre, url,
                 bestseller, reference, cop_count):
        if self.get_priv() >= 2:
            print("these are the fields " + title + ", " + author + ", " +
                  publisher + ", " + year + "," + edition + ", " + genre +
                  ", " + url)
            new = dc.Book(title,
                          author,
                          publisher,
                          year,
                          edition,
                          genre,
                          url,
                          bestseller,
                          reference,
                          copies=cop_count)
            print("this is book summary " + str(new.summary()))
            db.insert(new.summary())

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(title)
            db.insert_log(date + " | Librarian(" + id_str + ") added book: " +
                          title_str)
        else:
            return
コード例 #2
0
 def add_librarian(self, id, alias, name, mail, number, address, priv):
     new = Librarian(id, alias, name, mail, number, address, priv)
     db.insert(new.summary())
     print("SZD;LK;LDSZHVFJ;LKDSAJF;")
     id_str = str(id)
     date = get_date()
     db.insert_log(date + " | Admin added Librarian with ID: " + id_str)
コード例 #3
0
    def set_lib_priv(self, alias, new):
        Lib = db.get(alias=alias)[0]
        Lib.set_priv(new)

        lib_id = str(Lib.get_id())
        priv_str = str(new)
        date = get_date()
        db.insert_log(date + " |  " + "Admin set to Librarian(" + lib_id +
                      ") priveleg: " + priv_str)
コード例 #4
0
    def set_lib_address(self, alias, new):
        Lib = db.get(alias=alias)[0]
        Lib.set_address(new)

        librarian_id = Lib.get_id()
        lib_id = str(librarian_id)
        priv_str = str(new)
        date = get_date()
        db.insert_log(date + " |  " + "Admin set to Librarian(" + lib_id +
                      ") address: " + priv_str)
コード例 #5
0
    def remove_document(self, title):
        if self.get_priv() == 3:
            db.delete(title)

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(title)
            db.insert_log(date + " | Librarian(" + id_str +
                          ") removed Document with title: " + title_str)
        else:
            return
コード例 #6
0
    def remove(self, id):
        if self.get_priv() == 3:

            db.delete(id=id)

            id_str = str(self.get_id())
            date = get_date()
            us_id_str = str(id)
            db.insert_log(date + " | Librarian(" + id_str +
                          ") removed user with id: " + us_id_str)
        else:
            return
コード例 #7
0
    def set_outstanding(self, title):
        if self.get_priv() >= 2:
            book = db.get(title=title)[0]
            book.set_outstanding()

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(title)
            db.insert_log(date + " | Librarian(" + id_str +
                          ") marked Document " + title_str + " as outstanding")
        else:
            return
コード例 #8
0
    def new_vp(self, id, alias, name, mail, number, address):
        if self.get_priv() >= 2:
            new = VP(id, alias, name, mail, number, address)
            db.insert(new.summary())

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(id)
            db.insert_log(date + " | Librarian(" + id_str +
                          ") added Visiting Prof. with ID: " + title_str)
        else:
            return
コード例 #9
0
    def new_AV_material(self, title, author, value, url, copies):
        if self.get_priv() >= 2:
            new = dc.AV_Materials(title, author, value, url, copies=copies)
            print("avmaterial " + str(new.summary()))
            db.insert(new.summary())

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(title)
            db.insert_log(date + " | Librarian(" + id_str + ") added AV: " +
                          title_str)
        else:
            return
コード例 #10
0
    def add_copy_for_doc(self, original: dc.Document, copy_count):
        if self.get_priv() == 3:
            original.add_copy(copy_count)
            db.update(title=original.get_title(),
                      copies=original.get_count_of_copies())

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(original.get_title())
            db.insert_log(date + " | Librarian(" + id_str +
                          ") added copy for book: " + title_str)
        else:
            return
コード例 #11
0
def crawler():
    # Definição do número de páginas que serão percorridas para obtenção dos dados. 
    # Como a página lista os filmes de 50 em 50, o número total de filmes
    # será a soma do número total de páginas visitadas multiplicado por 50, no caso 5000.
    pages = [str(i) for i in range(1, 101)]
    count = 1
    result = True
    for page in pages:
        url = 'https://www.imdb.com/search/title?title_type=feature&user_rating=1.0,10.0&has=business-info,x-ray&start=' + page
        try:
            response = requests.get(url)
        except requests.exceptions.RequestException as e:
            insert_log({'step': 'get request', 'success': False, 'exception': str(e)})
            return 'Error: ' + str(e)
        html_soup = BeautifulSoup(response.text, 'html.parser')
        if(html_soup == ''):
            insert_log({'step': 'html_soup', 'success': False, 'exception': 'Page not found'})
            return 'Error: A página solicitada não foi encontrada'

        movie_containers = html_soup.find_all('div', class_ = 'lister-item-content')
        if(not movie_containers):
            insert_log({'step': 'movie_containers', 'success': False, 'exception': 'The page requested does not match the IMDB page'})
            return 'Error: A URL solicitada não corresponde com a página do IMDB'

        #Função que extrai as informações da página
        # Após a obtenção dos dados de cada filme, os mesmos são padronizados no formato json e salvo em banco de dados mongodb
        for container in movie_containers:
            #Obtenção dos dados contidos no bloco principal:
            #Título do filme, ano de lançamento, tempo de duração
            header  = container.find('h3', class_ = 'lister-item-header')
            title   = header.find('a', href=True).text
            year    = header.find('span', class_ = 'lister-item-year text-muted unbold').text
            runtime = container.find('span', class_='runtime').text.strip(' min')
            # Afim de manter a consistência dos dados, ignora-se os filmes que não possuem informação de tempo de duração
            if runtime == '':
                continue
            # Obtenção dos demais dados que se encontram no corpo do bloco analisado
            genre           = list(filter(None, container.find('span', class_='genre').text.strip().split(', ')))
            info            = container.find_all('p')
            director        = list(filter(None, info[2].text.split('\n')[2].split(', ')))
            dir_nacionality = get_director_nacionality(info[2].text.split('\n')[2])
            director_gender = get_director_gender(info[2].text.split('\n')[2])
            match           = re.search('([0-9]+)', year)
            year            = year[match.start() : match.end()]
            rating          = container.strong.text.strip()
            other_infos     = container.find('p', class_='sort-num_votes-visible')
            num_votes       = other_infos.find_all('span', {'data-value': True})[0]['data-value']
            gain            = other_infos.find_all('span', {'data-value': True})[1]['data-value']

            try:
                insert_fields({'id': count, 'title': title, 'year': year, 'runtime': runtime,
                                'genre': genre, 'director': director, 'is_american': dir_nacionality,
                                'dir_gender': director_gender, 'votes': num_votes, 'gain': gain, 'imdb_rating': rating})
            except Exception as e:
                insert_log({'url': 'insert_field', 'success': False,
                            'exception': str(e)})
                result = False
                break
            count += 1
    return result
コード例 #12
0
def log_string(input_string, msg_type="SYSTEM INFO"):
    print(f"Logging {msg_type}: {input_string}")
    new_log = {"type": msg_type, "msg": input_string}
    try:
        success = insert_log(new_log)
    except:
        success = False
    with open(LOG_FILE, 'a') as file:
        timestamp = time.asctime()
        file.write(f'{timestamp} {msg_dict[success]}: {input_string}\n')
コード例 #13
0
    def new_article(self, title, author, journal, publication_date, editor,
                    url, copies):
        if self.get_priv() >= 2:
            new = dc.Article(title,
                             author,
                             journal,
                             publication_date,
                             editor,
                             url,
                             copies=copies)
            db.insert(new.summary())

            id_str = str(self.get_id())
            date = get_date()
            title_str = str(title)
            db.insert_log(date + " | Librarian(" + id_str +
                          ") added article: " + title_str)
        else:
            return
コード例 #14
0
def address(call):
    print(call.text)
    u.current.auth_val_arr.append(call.text)
    temp = dict()
    for i in range(3):
        temp[u.current.auth_arr[i]] = u.current.auth_val_arr[i]
    temp["id"] = str(call.chat.id)
    temp["alias"] = call.from_user.username
    temp["mail"] = u.current.email

    id = temp["id"]
    name = temp["name"]
    mail = temp["mail"]
    number = temp["number"]
    alias = temp["alias"]
    address = temp["address"]
    if facbase.is_instructor(mail):
        usr = Instructor(id, alias, name, mail, number, address)
        temp_type = "Instructor"
    elif facbase.is_ta(mail):
        usr = TA(id, alias, name, mail, number, address)
        temp_type = "TA"
    elif facbase.is_professor(mail):
        usr = Professor(id, alias, name, mail, number, address)
        temp_type = "Professor"
    elif facbase.is_vp(mail):
        usr = VP(id, alias, name, mail, number, address)
        temp_type = "VP"
    else:
        usr = Student(id, alias, name, mail, number, address)
        temp_type = "Student"
    date = get_date()
    db.insert(usr.summary())
    db.insert_log(date + " | " + temp_type + " with ID: " + str(id) + " added")
    print(temp)
    user[str(id)].me = usr
    bot.send_message(
        call.chat.id,
        "Congratulations, registration is finished. Now choose, what do you want to do",
        reply_markup=bot_features.get_inline_markup(
            u.keyboard_patron_buttons_home))
コード例 #15
0
ファイル: telegram_bot.py プロジェクト: homycdev/PyBot
def edited(message):
    getattr(users[message.chat.id].object,
            "set_" + str(users[message.chat.id].attr).lower())(message.text)

    date = get_date()
    id_str = str(message.chat.id)
    us_id = str(users[message.chat.id].object.get_id())
    attrib = str(users[message.chat.id].attr)
    cur_type = type(users[message.chat.id].user)
    new_attr = message.text
    if cur_type == Librarian:
        db.insert_log(date + " | " + cur_type + " with ID(" + id_str +
                      ") changed user's " + attrib + " with ID: " + us_id +
                      " to " + new_attr)
    else:
        db.insert_log(date + " | Admin changed Librarian's " + attrib +
                      " with ID: " + us_id + " to " + new_attr)

    bot.send_message(
        message.chat.id,
        text="This field is now equals to {}".format(message.text),
        reply_markup=bot_features.get_inline_markup(u.keyboard_button_back))
コード例 #16
0
    def remove(self, librarian_id):
        db.delete(id=librarian_id)

        id_str = str(librarian_id)
        date = get_date()
        db.insert_log(date + " | Admin deleted Librarian with ID: " + id_str)
コード例 #17
0
def new_entry(index,entry,gate):
    entered_indexes.append(index)
    db.insert_log(index,entry,gate)
    return index