added homework
This commit is contained in:
27
login.py
27
login.py
@@ -7,6 +7,7 @@ import http.cookiejar
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import dateparser
|
import dateparser
|
||||||
|
import datetime
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@ class NewsInformer(object):
|
|||||||
primary_id=False,
|
primary_id=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_notification(self, news_id, text, title, attachment=None, timestamp=True):
|
def send_notification(
|
||||||
|
self, news_id, text, title, attachment=None, timestamp=True):
|
||||||
logger.info('sending notification: %s', title)
|
logger.info('sending notification: %s', title)
|
||||||
text = text.replace('<br>', '\n')
|
text = text.replace('<br>', '\n')
|
||||||
try:
|
try:
|
||||||
@@ -61,7 +63,8 @@ class NewsInformer(object):
|
|||||||
self.logger.error('Sending notification failed', exc_info=e)
|
self.logger.error('Sending notification failed', exc_info=e)
|
||||||
|
|
||||||
def _notification_sent(self, news_id):
|
def _notification_sent(self, news_id):
|
||||||
entry = self.db_notification.find_one(id=news_id, username=self.username)
|
entry = self.db_notification.find_one(
|
||||||
|
id=news_id, username=self.username)
|
||||||
return entry is not None
|
return entry is not None
|
||||||
|
|
||||||
def notify_news(self):
|
def notify_news(self):
|
||||||
@@ -79,7 +82,8 @@ class NewsInformer(object):
|
|||||||
}
|
}
|
||||||
self.db_news.insert(storenewsdata)
|
self.db_news.insert(storenewsdata)
|
||||||
if not self._notification_sent(news_item['id']):
|
if not self._notification_sent(news_item['id']):
|
||||||
logger.info('Notify %s about %s', self.username, news_item['title'])
|
logger.info('Notify %s about %s',
|
||||||
|
self.username, news_item['title'])
|
||||||
image = None
|
image = None
|
||||||
image_filename = im.get_newsimage(news_item['id'])
|
image_filename = im.get_newsimage(news_item['id'])
|
||||||
if image_filename:
|
if image_filename:
|
||||||
@@ -272,6 +276,21 @@ class Infomentor(object):
|
|||||||
)
|
)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
def get_homework(self):
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
dayofweek = now.weekday
|
||||||
|
startofweek = now - datetime.timedelta(days=-dayofweek)
|
||||||
|
timestamp = startofweek.strftime('%Y-%m-%dT00:00:00.000Z')
|
||||||
|
data = {
|
||||||
|
'date': timestamp,
|
||||||
|
'isWeek': True,
|
||||||
|
}
|
||||||
|
r = self._do_post(
|
||||||
|
self._mim_url('Homework/homework/GetHomework'),
|
||||||
|
data=data
|
||||||
|
)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
db_users = db.create_table(
|
db_users = db.create_table(
|
||||||
@@ -282,7 +301,7 @@ def main():
|
|||||||
for user in db_users:
|
for user in db_users:
|
||||||
if user['password'] == '':
|
if user['password'] == '':
|
||||||
logger.warning('User %s not enabled', user['username'])
|
logger.warning('User %s not enabled', user['username'])
|
||||||
continue;
|
continue
|
||||||
ni = NewsInformer(**user)
|
ni = NewsInformer(**user)
|
||||||
ni.notify_news()
|
ni.notify_news()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user