示例#1
0
 def test_find_with_changed_order(self):
     """Find the given token regardless of order"""
     string_list = ['asd', 'asdd', 'fre', 'glk', 'lkm']
     finder = Finder(string_list)
     find = finder.find('sad')
     expected = ['asd', 'asdd']
     assert find == expected
示例#2
0
 def test_find_with_none_param(self):
     """Find the empty given token"""
     string_list = ['asd', 'asdd', 'fre', 'glk', 'lkm']
     finder = Finder(string_list)
     find = finder.find(None)
     expected = []
     assert find == expected
def query(query_string, max_distance):
    model = ProjectionModel()
    model.load(configs['model_path'])
    ontobiotope = OntoBiotope(configs['ontobiotope_raw'])
    ontobiotope.load_graph(configs['ontobiotope_nx'])

    ontobiotope_enriched = OntoBiotope(configs['ontobiotope_raw'])
    ontobiotope_enriched.load_graph(configs['ontobiotope_enriched'])
    node_embeddings = OntoBiotope.load_embeddings(configs['node_embeddings'])

    finder = Finder()
    finder.construct_inverted_index(configs['train'])

    query_embedding = MentionSet.mention_to_embedding(
        query_string, pretrained_word_embeddings)
    predicted_node_id = model.predict(
        np.array(query_embedding).reshape((1, 100)), node_embeddings)[0]

    taxonomy_results = finder.find_related_docs(ontobiotope.graph,
                                                predicted_node_id,
                                                max_distance)
    finder.display_search_results(taxonomy_results, configs['train'],
                                  './data/taxonomy_results.txt')

    cooccurrence_results = finder.find_related_docs(ontobiotope_enriched.graph,
                                                    predicted_node_id,
                                                    max_distance)
    finder.display_search_results(cooccurrence_results, configs['train'],
                                  './data/cooccurrence_results.txt')
示例#4
0
 def test_find_with_big_initialization(self):
     """Find the given token regardless of order"""
     string_list = [
         'North America', 'South America', 'Asia', 'Africa', 'Europe',
         'Antartica', 'Australia'
     ]
     finder = Finder(string_list)
     find = finder.find('ac')
     expected_result = [
         'North America', 'South America', 'Africa', 'Antartica'
     ]
     assert find == expected_result
示例#5
0
 def test_find_with_large_initialization(self):
     """Find the given token regardless of order with a big input"""
     string_list = [
         'Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola',
         'Antigua & Deps', 'Argentina', 'Armenia', 'Australia', 'Austria',
         'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados',
         'Belarus', 'Belgium', 'Belize', 'Benin', 'Bhutan', 'Bolivia',
         'Bosnia Herzegovina', 'Botswana', 'Brazil', 'Brunei', 'Bulgaria',
         'Burkina', 'Burundi', 'Cambodia', 'Cameroon', 'Canada',
         'Cape Verde', 'Central African Rep', 'Chad', 'Chile', 'China',
         'Colombia', 'Comoros', 'Congo', 'Congo', 'Costa Rica', 'Croatia',
         'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti',
         'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt',
         'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia',
         'Ethiopia', 'Fiji', 'Finland', 'France', 'Gabon', 'Gambia',
         'Georgia', 'Germany', 'Ghana', 'Greece', 'Grenada', 'Guatemala',
         'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras',
         'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq',
         'Ireland', 'Israel', 'Italy', 'Ivory Coast', 'Jamaica', 'Japan',
         'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Korea North',
         'Korea South', 'Kosovo', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia',
         'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein',
         'Lithuania', 'Luxembourg', 'Macedonia', 'Madagascar', 'Malawi',
         'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands',
         'Mauritania', 'Mauritius', 'Mexico', 'Micronesia', 'Moldova',
         'Monaco', 'Mongolia', 'Montenegro', 'Morocco', 'Mozambique',
         'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands',
         'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman',
         'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay',
         'Peru', 'Philippines', 'Poland', 'Portugal', 'Qatar', 'Romania',
         'Russian Federation', 'Rwanda', 'St Kitts & Nevis', 'St Lucia',
         'Saint Vincent & the Grenadines', 'Samoa', 'San Marino',
         'Sao Tome & Principe', 'Saudi Arabia', 'Senegal', 'Serbia',
         'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia',
         'Solomon Islands', 'Somalia', 'South Africa', 'South Sudan',
         'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Swaziland', 'Sweden',
         'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania',
         'Thailand', 'Togo', 'Tonga', 'Trinidad & Tobago', 'Tunisia',
         'Turkey', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine',
         'United Arab Emirates', 'United Kingdom', 'United States',
         'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Venezuela',
         'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'
     ]
     finder = Finder(string_list)
     find = finder.find('tan')
     expected_result = [
         'Afghanistan', 'Bhutan', 'Kazakhstan', 'Kyrgyzstan', 'Mauritania',
         'Pakistan', 'Tajikistan', 'Turkmenistan', 'Uzbekistan', 'Vietnam'
     ]
     assert find == expected_result
 def __init__(self, username):
     self.bdAPI = bdAPI()  #экземпяр БД класса
     self.user_id = self.bdAPI.getUserIdFromName(username)
     self.f = Finder(self.user_id)  #экземпяр инстаграм класса
class scrapper():
    def __init__(self, username):
        self.bdAPI = bdAPI()  #экземпяр БД класса
        self.user_id = self.bdAPI.getUserIdFromName(username)
        self.f = Finder(self.user_id)  #экземпяр инстаграм класса

    #добавление всех записей
    def asyncLoadAllMediaInfo(self, username):
        max_id = -1
        errors = 0
        while max_id != -2:
            feed, max_id = self.f.findFeed(max_id)
            #сохранение записей из feed
            for item in feed:
                try:
                    self.bdAPI.addMediaItem(item)
                except:
                    errors += 1
                    continue

    #загрузка комментариев
    def loadComments(self):  #все комментарии здесь попадают в базу
        rows = self.bdAPI.getMediaIds()
        for row in rows:
            max_id = -1
            errors = 0
            try:
                comments = self.f.takeCommentsWithoutCircle(row[0],
                                                            60)  #было 20
                for item in comments:
                    try:
                        self.bdAPI.addComment(item, row[0])
                    except:
                        errors += 1
                        continue
            except Exception as e:
                self.writeReport(str(e))
                QMessageBox.about(self, "Ошибка получения комментариев",
                                  str(e))

    #поиск комментариев их запись и выдача подходящих
    def findAbcAllCommentsAndSendIt(self):
        self.bdAPI.commentsUnNew()  #комментарии прочитаны
        rows = self.bdAPI.getMediaIds()
        for row in rows:
            commentsOld = self.bdAPI.takeOldCommentsIds(
                row['media_id'])  #старые 50
            commentsOldN = list(
                map(lambda x: int(x['comment_id']), commentsOld))
            commentsNew = self.f.takeCommentsWithoutCircle(
                row['media_id'], 50)  #новые 50
            for comment in commentsNew:
                if comment['pk'] in commentsOldN:
                    break
                else:
                    self.bdAPI.addComment(
                        comment,
                        row['media_id'])  #добавляем в базу новые комментарии
        self.bdAPI.checkNewComments()  #отмечает все новые комменты по словарю
        rows = self.bdAPI.showGoodNewComments(
        )  #получает новые и отмеченные для единовременного их вывода на экран
        self.bdAPI.commentsUnNew()  #комментарии прочитаны

    #перезагрузка базы
    def LoadAll(self, name):
        self.asyncLoadAllMediaInfo(name)
        self.loadComments()
        self.bdAPI.checkComments()

    def writeReport(self, text):
        now = datetime.now()
        with open('report.info', 'a') as file:
            file.write(
                '\n%s\t%s' %
                (now.strftime("%d-%m-%Y %H:%M"), text))  #дозапись в файл

    #проверка на наличие новой записи стены
    def searchAndAddNewMediaItems(self):
        oldMediaIds = self.bdAPI.getMediaIds()
        newMediaIds = self.f.findNewFeed()
        oldMediaIds = list(map(lambda x: int(x["media_id"]), oldMediaIds))
        for media in newMediaIds:
            if media['pk'] in oldMediaIds:
                break
            else:
                self.bdAPI.addMediaItem(media)
示例#8
0
def finder():
    return Finder()
示例#9
0
 def setup(self):
     self.finder = Finder()
示例#10
0
        # Formats the selected proxy.
        proxy = Proxy(args)

        if args.proxy is not None:
            args.proxy = proxy.format_proxy()
        else:
            if args.random_proxy:
                args.proxy = proxy.random_proxy()

        # Instance the "Check" class.
        request = Request(args)

        # Checks whether the target is online.
        if request.check_status() == 200:
            Color.println("{+} Target On: {G}%s{W}" % args.url)
        else:
            Color.println("{!} Error: Please verify your target.")
            exit()

        # Stores the selected word list in the variable.
        wordlist = Wordlist(args)
        args.wordlist = wordlist.run()

        ExploitFinder = Finder(args)  # Instance the "Finder" class.

        # Heimdall, find!
        ExploitFinder.dashboard()

        Color.println("\n{+} {G}Heimdall, find the dashboard!{W}\n")
        ExploitFinder.run()
示例#11
0
        Formats the selected proxy.
        """
        if args.proxy is not None:
            args.proxy = Set.proxy()
        """
        Instance the "Check" class.
        Checks whether the target is online.
        """
        Checkup = Check(args)
        try:
            Checkup.target()
            Color.println("{+} Target On: {G}%s{W}" % args.url)
        except Exception as ex:
            Color.println("{!} Error: %s" % ex)
            Color.println("{!} Please verify your target.")
            exit()
        """
        Stores the selected word list in the variable.
        """
        args.wordlist = Set.wordlist()
        """
        Instance the "Finder" class.
        Heimdall, find!
        """
        ExploitFinder = Finder(args)
        try:
            ExploitFinder.dashboard()
        except KeyboardInterrupt as ex:
            Color.println("\n{!} CTRL + C has pressed. %s" % ex)
    Color.println("{+} Finished!    :)")