-
Notifications
You must be signed in to change notification settings - Fork 1
/
clock.py
35 lines (24 loc) · 811 Bytes
/
clock.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
# -*- coding: utf-8 -*-
import os
from datetime import datetime
from pytz import timezone
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "schedule_twitter.settings")
import django
from django.conf import settings
from apscheduler.schedulers.background import BlockingScheduler
from tweet.models import Tweet
django.setup()
def tweet():
tz = timezone(settings.TIME_ZONE)
now = datetime.now(tz)
tweets = Tweet.objects.filter(agendado_para__lte=now, publicado=False)
for tweet in tweets:
tweet.send()
def start_scheduler():
scheduler = BlockingScheduler()
scheduler.add_job(tweet,
settings.SCHEDULE['type'],
minutes=settings.SCHEDULE['interval'],
id='tweet_jobs')
scheduler.start()
start_scheduler()