forked from ynhacler/RedKindle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronpush.py
66 lines (56 loc) · 1.44 KB
/
cronpush.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding:utf-8 -*-
from rq2 import Queue,use_connection
from worker import conn
from pushworker import pushwork,pushwork3
from datetime import datetime
import pytz
use_connection(conn)
q = Queue()
#q.enqueue(pushwork2,'asd','1q2w3e')
import web
import model
from config import *
print '----------------------'
print datetime.now()
tz = pytz.timezone('GMT')
date = datetime.now(tz)
hour = date.hour
tz2 = pytz.timezone('Asia/Shanghai')
date2 = datetime.now(tz2)
weekday = date2.isoweekday()#Mon 1: Sun 7
users = model.get_current_push_users(hour,weekday)
if len(users) == 0:
print '-=end=-'
else:
#推送
for user in users:
feeds = []
mfeeds = []
feeds_num = 0
ownfeeds = model.username2feeds(user.name)
if len(ownfeeds) != 0:
'''
books = (model.get_allbooks())
for book in books:
if book.f_id in ownfeeds:
b=[]
if cmp('http',book.url[0:4].lower()) == 0:
#自动的feeds
b.append(book.title)
b.append(book.url)
if book.isfulltext == 1:
b.append(True)
else:
b.append(False)
feeds.append(b)
else:
#手动的feeds
b.append(book.url)
mfeeds.append(b)
feeds_num += 1
if user and user.kindle_email:
q.enqueue(pushwork,args=(user.kindle_email,feeds,mfeeds,user.keep_image),timeout=feeds_num*300)
'''
if user and user.kindle_email:
q.enqueue(pushwork3,args=(user.kindle_email,ownfeeds,user.keep_image,user.ifmobi))
print '-=end=-'