Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update user import #487

Merged
merged 1 commit into from Jul 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions bookie/lib/importer.py
Expand Up @@ -81,7 +81,7 @@ def process(self, fulltext=None):
"""Meant to be implemented in subclasses"""
raise NotImplementedError("Please implement this in your importer")

def save_bookmark(self, url, desc, ext, tags, dt=None):
def save_bookmark(self, url, desc, ext, tags, dt=None, is_private=False):
"""Save the bookmark to the db

:param url: bookmark url
Expand All @@ -108,7 +108,8 @@ def save_bookmark(self, url, desc, ext, tags, dt=None):
ext,
tags,
dt=dt,
inserted_by=IMPORTED
inserted_by=IMPORTED,
is_private=is_private,
)

# Add this hash to the list so that we can skip dupes in the
Expand Down Expand Up @@ -181,9 +182,9 @@ def process(self):

link = tag.a

# Skip any bookmarks with an attribute of PRIVATE.
if link.has_key('PRIVATE'): # noqa
continue
is_private = False
if link.has_key('private'): # noqa
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should do a search in the keys to cover "private", "is_private" or any other version of this.

That said, maybe that's more trouble than its worth.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For DelImporter, the private bookmarks are marked with a 'PRIVATE="1"', so we are searching here with key 'private'.

is_private = True

import_add_date = float(link['add_date'])

Expand All @@ -198,7 +199,8 @@ def process(self):
unicode(link.text),
unicode(extended),
u" ".join(unicode(link.get('tags', '')).split(u',')),
dt=add_date)
dt=add_date,
is_private=is_private)
count = count + 1
DBSession.flush()
except InvalidBookmark:
Expand Down Expand Up @@ -279,13 +281,19 @@ def process(self):

add_date = dateparser.parse(post.get('time'))

if post.get('private') == "no":
is_private = False
elif post.get('private') == "yes":
is_private = True

try:
bmark = self.save_bookmark(
unicode(post.get('href')),
unicode(post.get('description')),
unicode(post.get('extended')),
unicode(post.get('tag')),
dt=add_date)
dt=add_date,
is_private=is_private)
count = count + 1
if bmark:
bmark.stored = bmark.stored.replace(tzinfo=None)
Expand Down
14 changes: 14 additions & 0 deletions bookie/tests/test_utils/test_imports.py
Expand Up @@ -40,6 +40,13 @@ def _delicious_data_test(self):
19,
"We should have 19 results, we got: " + str(len(res)))

# Check for the private bookmarks.
private_res = Bmark.query.filter(Bmark.is_private == True).all() # noqa
self.assertEqual(
len(private_res),
1,
"We should have 1 private bookmark: " + str(len(private_res)))

# verify we can find a bookmark by url and check tags, etc
check_url = u'http://www.ndftz.com/nickelanddime.png'
check_url_hashed = generate_hash(check_url)
Expand Down Expand Up @@ -74,6 +81,13 @@ def _delicious_xml_data_test(self):
25,
"We should have 25 results, we got: " + str(len(res)))

# Check for the private bookmarks.
private_res = Bmark.query.filter(Bmark.is_private == True).all() # noqa
self.assertEqual(
len(private_res),
20,
"We should have 20 private bookmarks: " + str(len(private_res)))

# verify we can find a bookmark by url and check tags, etc
check_url = 'http://jekyllrb.com/'
check_url_hashed = generate_hash(check_url)
Expand Down