-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
127 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5060 | ||
2999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from recommendation.models import Book | ||
from contacts.models import Contact | ||
try: | ||
from douban.service import DoubanService | ||
from douban.client import OAuthClient | ||
except ImportError, e: | ||
print e | ||
print 'please install douban-python' | ||
sys.exit(0) | ||
|
||
class DoubanBooks(object): | ||
|
||
def __init__(self): | ||
self.HOST = 'http://www.douban.com' | ||
self.API_KEY = "0ff1b8ce70b305ab2fd52a6b52191101" | ||
self.SECRET = "47c2cb706c4ec51d" | ||
self.reco_books = [] | ||
self.subjects = [] | ||
self.reco = [] | ||
self.href = [] | ||
self.service = DoubanService(self.API_KEY, self.SECRET) | ||
|
||
def get_reco(self): | ||
member = Contact.objects.all() | ||
book_states = ['read', 'reading', 'wish'] | ||
for tmp_member in member: | ||
for tmp_states in book_states: | ||
feed_read = self.service.GetMyCollection('/people/%s/collection' % tmp_member.douban_id, 'book', 'IST', tmp_states) | ||
self.get_book(feed_read, tmp_member.fullname) | ||
|
||
def get_book(self, feed, fullname): | ||
for entry in feed.entry: | ||
book_href = entry.link[1].href | ||
self.href.append(book_href[21:]) | ||
subject_id = book_href[35:] | ||
if subject_id not in self.subjects: | ||
book_href = book_href[21:] | ||
bookfeed = self.service.GetBook(book_href) | ||
self.subjects.append(subject_id) | ||
self.reco.append((bookfeed, [fullname], subject_id)) | ||
continue | ||
else: | ||
for tmp in self.reco: | ||
if tmp[2] == subject_id: | ||
if fullname not in tmp[1]: | ||
tmp[1].append(fullname) | ||
continue | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class DoubanBooks(object): | ||
|
||
def __init__(self): | ||
self.HOST = 'http://www.douban.com' | ||
self.API_KEY = "0ff1b8ce70b305ab2fd52a6b52191101" | ||
self.SECRET = "47c2cb706c4ec51d" | ||
self.reco_books = [] | ||
self.subjects = [] | ||
self.reco = [] | ||
self.href = [] | ||
self.service = DoubanService(self.API_KEY, self.SECRET) | ||
|
||
def get_reco(self): | ||
member = Contact.objects.all() | ||
for tmp in member: | ||
feed_read = self.service.GetMyCollection('/people/%s/collection' % tmp.douban_id, 'book', 'IST','read') | ||
self.get_book(feed_read, tmp.fullname) | ||
feed_reading = self.service.GetMyCollection('/people/%s/collection' % tmp.douban_id, 'book', 'IST','reading') | ||
self.get_book(feed_reading, tmp.fullname) | ||
feed_wish = self.service.GetMyCollection('/people/%s/collection' % tmp.douban_id, 'book', 'IST','wish') | ||
self.get_book(feed_wish, tmp.fullname) | ||
|
||
def get_book(self, feed, fullname): | ||
for entry in feed.entry: | ||
book_href = entry.link[1].href | ||
self.href.append(book_href[21:]) | ||
subject_id = book_href[35:] | ||
if subject_id not in self.subjects: | ||
book_href = book_href[21:] | ||
bookfeed = self.service.GetBook(book_href) | ||
self.subjects.append(subject_id) | ||
self.reco.append((bookfeed, [fullname], subject_id)) | ||
continue | ||
else: | ||
for tmp in self.reco: | ||
if tmp[2] == subject_id: | ||
if fullname not in tmp[1]: | ||
tmp[1].append(fullname) | ||
continue | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters