Exemple #1
0
    def _save_favorite(self, n_url):
        """
        """
        # when 'kind' query empty or missing
        if not n_url.get_query('kind'):
            u = self.get_user_input('string', self.get_str(30301))
            
            # user input cancelled
            if u is None:
                return Response(Response.SUCCESS)

            n_url = self._get_album_by_invitation(Url(u))

            if n_url is None:
                return Response(Response.ERROR, message=self.get_str(30403))

        # when we're supposed to have complete input data
        favorite = Bookmark('favorite')
        favorite.add_attributes(n_url.query)

        self.log(self.__class__, "saving bookmark: %s[%s]" %
                 (favorite.name, repr(favorite.attr)))
    
        self.bookmarks.add_bookmark(favorite)
    
        return Response(Response.SUCCESS,
                        self.get_str(30404),
                        task=Response.REFRESH)
Exemple #2
0
    def scheduler_bookmark(self, limit=BOOKMARK_CYCLE):
        """
		收藏作品
		"""
        b = Bookmark()
        while True:
            b.run()
            time.sleep(BOOKMARK_CYCLE)
Exemple #3
0
    def test_save_positions():
        mock_sys = mock.MagicMock()
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.save_positions()
Exemple #4
0
    def test_save_thumbnails_none_plot():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getVideoInfoTag.return_value.getPlot.return_value = None
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.save_thumbnails()
Exemple #5
0
    def test_import_bookmark_from_plot():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getVideoInfoTag.return_value.getPlot.return_value = '[30, 10]'
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.import_bookmark_from_plot()
Exemple #6
0
    def test_add_position():
        item_path = '/path/to/video'
        thumb = '/home/kodi/.kodi/temp/A-thumb-120.jpg'
        position = 120

        with patch('bookmark.KodiDB', FakeKodiDB):
            with patch('bookmark.Bookmark.add_position',
                       return_value=None) as pmock:
                bookmark = Bookmark(item_path)
                bookmark.add_position(position, thumb)
                pmock.assert_called_once()
    def __init__(self):
        try:
            stopped_at = open('.bookmark')
            stopping_place = eval(stopped_at.readline())
            self.current_position = Bookmark(*stopping_place)
        except FileNotFoundError:
            self.current_position = Bookmark()

        self.word_counts = {}
        self.place_saved = Bookmark()
        db.create_all()
    def add_bookmark(name, path, page, data):

        try:
            q = Bookmark.insert(comic_name=name, comic_path=path,
                                comic_page=page, page_data=data)
            q.execute()
            print '[INFO] Bookmark %s inserted.' % name
        except IntegrityError:
            q = Bookmark.update(comic_page=page, page_data=data).where(
                Bookmark.comic_path == path)
            q.execute()
            print '[INFO] Bookmark updated.'
Exemple #9
0
    def test_save_positions_without_initial_folder():
        mock_sys = mock.MagicMock()
        item_path = "plugin://path/to/video"
        save_folder = '/path/to/save'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('setting.Setting.get_addon_setting',
                           return_value=None) as mock_fun:
                    bookmark = Bookmark(item_path)
                    bookmark.save_positions()
                    mock_fun.assert_called_once()
    def add_bookmark(name, path, page, data):

        try:
            q = Bookmark.insert(comic_name=name, comic_path=path,
                                comic_page=page, page_data=data)
            q.execute()
            print '[INFO] Bookmark %s inserted.' % name
        except IntegrityError:
            q = Bookmark.update(comic_page=page, page_data=data).where(
                Bookmark.comic_path == path)
            q.execute()
            print '[INFO] Bookmark updated.'
Exemple #11
0
def add():

    Bookmark.from_dict(request.vars['bookmark_obj']).add()

    # bookmark, bookmarks = get_bookmark()
    #
    # # update session and db
    # if bookmark['key'] not in bookmarks:
    #     bookmarks[bookmark['key']] = bookmark['data']
    #     db(db.auth_user.id == auth.user.id).update(bookmarks=bookmarks)

    # redirect(URL('default', 'index'))
    return
Exemple #12
0
def add():

    Bookmark.from_dict(request.vars["bookmark_obj"]).add()

    # bookmark, bookmarks = get_bookmark()
    #
    # # update session and db
    # if bookmark['key'] not in bookmarks:
    #     bookmarks[bookmark['key']] = bookmark['data']
    #     db(db.auth_user.id == auth.user.id).update(bookmarks=bookmarks)

    # redirect(URL('default', 'index'))
    return
Exemple #13
0
    def test_bookmark():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getPath.return_value = \
            'plugin://plugin.googledrive/?item_id=18cvS&driveid=10773&item_driveid=000753&action=play&content_type=video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                bookmark = Bookmark()

        mock_sys.listitem.getPath.return_value = '/path/to/video'
        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                bookmark = Bookmark()
Exemple #14
0
def run():
    """
    Main
    """
    if len(sys.argv) > 2 and sys.argv[1] == '-r':
        Bookmark.select(sys.argv[2]).delete()
    elif len(sys.argv) > 2 and Bookmark.select(sys.argv[1]) is None:
        Bookmark(sys.argv[1], sys.argv[2]).persist()
    else:
        bookmark = Bookmark.select(sys.argv[1])
        if bookmark is not None:
            call([NEW_TAB_COMMAND, bookmark.link])
        else:
            print('No bookmark ' + sys.argv[1])
Exemple #15
0
def delete():

    Bookmark.from_dict(request.vars['bookmark_obj']).delete()

    # bookmark, bookmarks = get_bookmark()
    #
    # # update session and db
    # try:
    #     del bookmarks[bookmark['key']]
    #     db(db.auth_user.id == auth.user.id).update(bookmarks=bookmarks)
    # except:
    #     pass

    # redirect(URL('default', 'index'))
    return
Exemple #16
0
def delete():

    Bookmark.from_dict(request.vars["bookmark_obj"]).delete()

    # bookmark, bookmarks = get_bookmark()
    #
    # # update session and db
    # try:
    #     del bookmarks[bookmark['key']]
    #     db(db.auth_user.id == auth.user.id).update(bookmarks=bookmarks)
    # except:
    #     pass

    # redirect(URL('default', 'index'))
    return
def extract_dt_data(dt):
    """Function to extract data from dt tag.
    
    The html is structure such that a dt tag will either contain an a tag or a h3 tag and dl tag.
    """

    for child in dt:

        if child.name == 'a':

            temp_bookmark = {
                'name': child.text,
                'url': child.get('href'),
                'icon': child.get('icon')
            }

            data = Bookmark(**temp_bookmark)

        elif child.name == 'h3':

            data = {}
            header = child.text
            data[header] = []

        elif child.name == 'dl':

            data[header] = child

    return data
 def remove_bookmark(path):
     try:
         q = Bookmark.delete().where(Bookmark.comic_path == path)
         q.execute()
         print '[INFO] Bookmark deleted.'
     except IntegrityError:
         print '[ERROR] Bookmark not find.'
Exemple #19
0
    def _delete_favorite(self, n_url):
        """Delete the favorite from the bookmark file."""
        favorite = Bookmark('favorite')
        favorite.add_attributes(n_url.query)

        self.log(self.__class__, "deleting bookmark: %s[%s]" %
                 (favorite.name, repr(favorite.attr)))
    
        try:
            self.bookmarks.delete_bookmark(favorite)
        except:
            return Response(Response.ERROR, message=self.get_str(30405))

        return Response(Response.SUCCESS,
                        message=self.get_str(30406),
                        task=Response.REFRESH)
 def remove_bookmark(path):
     try:
         q = Bookmark.delete().where(Bookmark.comic_path == path)
         q.execute()
         print '[INFO] Bookmark deleted.'
     except IntegrityError:
         print '[ERROR] Bookmark not find.'
Exemple #21
0
 def _generate_bookmarks(cursor):
     bookmarks = []
     for row in cursor:
         bookmarks.append(
             Bookmark(title=row[0],
                      url=row[1],
                      identifier=row[2],
                      date=row[3]))
     return bookmarks
Exemple #22
0
 def parseLSSharedFileListPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     try:
         for n,item in enumerate(plist["RecentDocuments"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Exemple #23
0
 def parseSFL(self, mru_file):
     plist_objects = self.load_plist_objects(mru_file)
     if plist_objects == None:
         return []
     bookmarks = []
     try:
         if plist_objects["root"]["NS.keys"][2] == "items":
             items = plist_objects["root"]["NS.objects"][2]["NS.objects"] 
             for n,item in enumerate(items):
                 if "LSSharedFileList.RecentHosts" not in mru_file:
                     bookmarks.append(Bookmark(data=item["bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Exemple #24
0
 def parseRecentItemsPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     aliases = []
     try:
         for n,item in enumerate(plist["RecentApplications"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["RecentDocuments"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["RecentServers"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Applications"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Documents"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Servers"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     return bookmarks, aliases
Exemple #25
0
 def parseMSOffice2016Plist(self, mru_file):
     bookmarks = []
     try:
         plistfile = plistlib.readPlist(mru_file)
         for n,item in enumerate(plistfile):
             try:
                 bookmarkdata = plistfile[item]["kBookmarkDataKey"]
                 for attr, blob in bookmarkdata.__dict__.iteritems():
                     try:
                         bookmarks.append(Bookmark(data=blob).parse())
                     except:
                         pass
             except:
                 pass
     except:
         pass
     return bookmarks
Exemple #26
0
 def parseSFL2(self, mru_file):
     plist_objects = self.load_plist_objects(mru_file)
     if plist_objects == None:
         return []
     bookmarks = []
     try:
         if plist_objects["root"]["NS.keys"][0] == "items":
             items = plist_objects["root"]["NS.objects"][0]["NS.objects"] 
             for n,item in enumerate(items):
                 attribute_keys = plist_objects["root"]["NS.objects"][0]["NS.objects"][n]["NS.keys"]
                 attribute_values = plist_objects["root"]["NS.objects"][0]["NS.objects"][n]["NS.objects"]
                 attributes = dict(zip(attribute_keys,attribute_values))
                 if "LSSharedFileList.RecentHosts" not in mru_file:
                     bookmarks.append(Bookmark(data=attributes["Bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Exemple #27
0
 def parseFinderPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     aliases = []
     try:
         for n,item in enumerate(plist["FXRecentFolders"]):
             try:
                 bookmarks.append(Bookmark(data=item["file-bookmark"]).parse())
             except:
                 pass
             try:
                 pass
                 aliases.append(Alias(data=item["file-data"]["_CFURLAliasData"]).parse())
             except:
                 pass
     except:
         pass
     return bookmarks, aliases
 def get_bookmarks(rows_number):
     query = Bookmark.select().order_by(Bookmark.comic_id.desc()).limit(
         rows_number)
     return list(query)
Exemple #29
0
def validate_url(bc, url):
    b = Bookmark(url)
    if b.verify():
        print_bookmark(b)
    else:
        print('not able to validate')
def main():
    bookmark = Bookmark()
    bookmark.save_positions()
    bookmark.save_thumbnails()
Exemple #31
0
from bookmark import Bookmark
from webpage import Webpage

bm = Bookmark('https://en.wikipedia.org/wiki/Futurama')
words = bm.get_words()
links = bm.get_links()

for link in links:
    bm = Bookmark(link)
    more_links = bm.get_links()
    if more_links:
        links.extend(more_links)
        print('__________________________________')
        print('  new links: ' + str(len(more_links)))
        print('total links: ' + str(len(links)))
        print('  avg links: ' + str(bm.link_avg()))
        print('  std links: ' + str(bm.link_std()))
    if len(links) > 1000: break

for link in links:
    bm = Bookmark(link)
    more_words = bm.get_words()
    if more_words:
        words.extend(more_words)
        print('__________________________________')
        print('  new words: ' + str(len(more_words)))
        print('total words: ' + str(len(words)))
        print('  avg words: ' + str(bm.word_avg()))
        print('  std words: ' + str(bm.word_std()))

bm.get_bow(words)
Exemple #32
0
def import_gdrive_image(file_name, item_path):
    position = utils.retrieve_position_from_thumb(file_name)
    if position != 0:
        file = xbmc.translatePath('special://temp') + file_name
        bookmark = Bookmark(item_path)
        add_thumb(bookmark, file, position)
Exemple #33
0
def main():
    hatena_id = os.environ['HATENAID']
    bookmark = Bookmark(hatena_id)
    titles = bookmark.get_title()

    create_wordcloud(titles)
class Parser:

    def __init__(self):
        try:
            stopped_at = open('.bookmark')
            stopping_place = eval(stopped_at.readline())
            self.current_position = Bookmark(*stopping_place)
        except FileNotFoundError:
            self.current_position = Bookmark()

        self.word_counts = {}
        self.place_saved = Bookmark()
        db.create_all()

    def save_place(self):
        with open('.bookmark', 'w') as stopped_at:
            stopped_at.write('{}'.format(self.place_saved))

    def get_comment_data_blobs(self, directory='data'):
        for zipped_file in os.walk(directory):
            for file_name in zipped_file[2]:
                if file_name[-17:] != 'comments.json.zip' \
                        or not self.current_position.right_file(file_name):
                    print('Skipped parsing {}'.format(file_name))
                    continue
                try:
                    prepped_zip_file = ZipFile('data/' + file_name)
                    print(file_name)
                except BadZipFile as e:
                    continue

                for raw_file in prepped_zip_file.namelist():
                    for line in prepped_zip_file.open(raw_file, 'r'):
                        yield json.loads(line.decode()), file_name

    def run(self):
        try:
            for blob, current_file in self.get_comment_data_blobs():
                comment = build_comment(blob)
                if not self.current_position.back_where_we_need_to_be(current_file, comment.id):
                    continue

                db.session.add(comment)

                if len(self.word_counts) > 100000:
                    self.dump_into_db(db)

                for unigram in tokenize(blob['body']):
                    if unigram in self.word_counts:
                        self.word_counts[unigram]['count'] += 1
                    else:
                        self.word_counts[unigram] = {}
                        self.word_counts[unigram]['count'] = 1

                    if not self.word_counts[unigram].get('occurences'):
                        self.word_counts[unigram]['occurences'] = deque()

                    self.word_counts[unigram]['occurences'].append(comment)
                self.current_position.commit = True

        except (KeyboardInterrupt) as e:
            print(e)
            self.dump_into_db(db)

        finally:
            final_count = sorted(Unigram.query.all(), reverse=True)
            for unigram in final_count:
                print('{}'.format(unigram))

    def dump_into_db(self, db):
        start = datetime.now()
        length = len(self.word_counts)
        alert = '\nMoving from memory into database. ({})'
        db.session.commit()

        print(alert.format(length))

        for current in Unigram.query.filter(Unigram.id in self.word_counts).all():
            current.times_occurred += self.word_counts[current.id]['count']
            current.occurs_in.extend(
                self.word_counts[current.id]['occurences'])
            del(self.word_counts[current.id])

        for ngram in self.word_counts:
            current = Unigram(ngram, self.word_counts[ngram]['count'],
                              self.word_counts[ngram]['occurences'])
            db.session.add(current)

        db.session.commit()
        print('Leaving dump after {}.'.format(datetime.now() - start))
        self.place_saved = deepcopy(self.current_position)
        self.save_place()
def main():
    bookmark = Bookmark()

    bookmark.import_bookmark_from_plot()
 def get_bookmarks(rows_number):
     query = Bookmark.select().order_by(
         Bookmark.comic_id.desc()).limit(rows_number)
     return list(query)
 def get_bookmark_by_path(path):
     bk_list = Bookmark.select().where(Bookmark.comic_path == path)
     return bk_list[0] if bk_list else None
 def is_bookmark(path):
     bk_list = Bookmark.select().where(Bookmark.comic_path == path)
     return True if bk_list else False
Exemple #39
0
logger = log.get_logger('bkm-org', log_path=log_path)
collection_home = Path(config['bkm-org']['plain_home'])
default_collection_fpath = Path(config['bkm-org']['collection_fpath'])

ignore_categories = ['Bookmarks Menu', 'Bookmarks Toolbar', 'Mobile Bookmarks']

current_collection = BookmarkCollection(default_collection_fpath)

while True:
    receivedMessage = nm.getMessage()
    if receivedMessage:
        command = receivedMessage['command']
        if command == 'add-bookmark':
            created = utils.get_date_from_unix_timestamp(
                str(receivedMessage['created']))
            bookmark = Bookmark(receivedMessage['url'],
                                receivedMessage['title'], created)
            if 'categories' in receivedMessage:
                bookmark.categories = utils.get_category_hierarchy_str(
                    receivedMessage['categories'])
                bookmark.tags = [
                    utils.get_tag_from_category(c)
                    for c in receivedMessage['categories']
                    if c not in ignore_categories
                ]
            if 'tags' in receivedMessage and receivedMessage['tags']:
                bookmark.add_tags(receivedMessage['tags'].split(','))
            success = current_collection.add(bookmark)
            if success:
                nm.send("user-message",
                        f"added bookmark: {receivedMessage['url']}")
            continue
 def get_bookmark_by_path(path):
     bk_list = Bookmark.select().where(Bookmark.comic_path == path)
     return bk_list[0] if bk_list else None
 def is_bookmark(path):
     bk_list = Bookmark.select().where(Bookmark.comic_path == path)
     return True if bk_list else False
Exemple #42
0
 def __init__(self, title, url, rss):
     # インスタンス初期化用のメソッド
     self.rss = rss                  # RSSのURLをアトリビュートに代入
     Bookmark.__init__(self, title, url)