forked from KMhook/istweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py~
40 lines (35 loc) · 1.19 KB
/
tasks.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from celery.decorators import task, periodic_task
from celery.task.schedules import crontab
import sys
# Create your views here.
from doubanbooks import DoubanBooks
@periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*"))
def test():
douban_books = DoubanBooks()
douban_books.get_reco()
for reco in douban_books.reco:
bid = reco[0].link[1].href
title = reco[0].title.text
#author = reco[0].author
img_url = reco[0].link[2].href
recommender = ''
author = ''
for person in reco[0].author:
author += person.name.text + ', '
author = author[0:-2]
for person in reco[1]:
recommender += ' ' + person
print recommender
books = Book.objects.filter(book_id = bid)
if not books:
book = Book(book_title = title,
book_author = author,
book_img_url = img_url,
book_id = bid,
book_recommender = recommender)
book.save()
else:
book = books[0]
book.book_recommender = recommender
book.book_author = author
book.save()