This commit is contained in:
2018-10-21 02:04:02 +02:00
parent d738976f6d
commit e63ae46724
3 changed files with 15 additions and 11 deletions

0
infomentor.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

26
login.py Normal file → Executable file
View File

@@ -87,17 +87,21 @@ class NewsInformer(object):
def make_site(self, text): def make_site(self, text):
filename = str(uuid.uuid4()) filename = str(uuid.uuid4())
fpath = os.path.join('files', filename+'.html') fpath = os.path.join('files', filename+'.html')
urlfinder = re.compile("(https?://[^ \n\t]*)")
text = urlfinder.sub(r'<a href="\1">\1</a>', text)
text = '<html> <head> <meta charset="utf-8" /> </head> <body>{}</body></html>'.format(text)
with open(fpath, 'w+') as f: with open(fpath, 'w+') as f:
f.write(text) f.write(text)
return 'https://files.hyttioaoa.de/{}'.format(fpath) return 'https://files.hyttioaoa.de/{}.html'.format(filename)
def send_notification( def send_notification(
self, news_id, text, title, attachment=None, timestamp=True): self, news_id, text, title, attachment=None, timestamp=True):
self.logger.info('sending notification: %s', title) self.logger.info('sending notification: %s', title)
text = text.replace('<br>', '\n') if len(text) > 900:
if len(text) > 1000:
url = self.make_site(text) url = self.make_site(text)
text = 'saved at: {}'.format(url) shorttext = text[:900]
text = '{}...\n\nfulltext saved at: {}'.format(shorttext, url)
text = text.replace('<br>', '\n')
try: try:
self.logger.info(text) self.logger.info(text)
self.logger.info(title) self.logger.info(title)
@@ -155,8 +159,8 @@ class NewsInformer(object):
att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0] att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0]
f = self.im.download(attachment['url'], directory='files', skip=True) f = self.im.download(attachment['url'], directory='files', skip=True)
try: try:
_path, urlname = os.path.split(f) fid, fname = f.split('/')
storehw['homeworkText'] += '''\nAttachment {0}: https://files.hyttioaoa.de/{0}\n'''.format(urlname) storehw['homeworkText'] += '''<br>Attachment {0}: https://files.hyttioaoa.de/{1}<br>'''.format(fname, f)
if self.db_attachments.find_one(id=int(att_id)): if self.db_attachments.find_one(id=int(att_id)):
continue continue
self.db_attachments.insert( self.db_attachments.insert(
@@ -197,8 +201,7 @@ class NewsInformer(object):
att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0] att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0]
f = self.im.download(attachment['url'], directory='files', skip=True) f = self.im.download(attachment['url'], directory='files', skip=True)
try: try:
_path, urlname = os.path.split(f) storenewsdata['content'] += '''<br>Attachment {0}: https://files.hyttioaoa.de/{0}<br>'''.format(f)
storenewsdata['content'] += '''\nAttachment {0}: https://files.hyttioaoa.de/{0}\n'''.format(urlname)
if self.db_attachments.find_one(id=int(att_id)): if self.db_attachments.find_one(id=int(att_id)):
continue continue
self.db_attachments.insert( self.db_attachments.insert(
@@ -333,10 +336,11 @@ class Infomentor(object):
self.logger.info('determine filename from headers') self.logger.info('determine filename from headers')
filename = get_filename_from_cd(r.headers.get('content-disposition')) filename = get_filename_from_cd(r.headers.get('content-disposition'))
self.logger.info('determined filename: %s', filename) self.logger.info('determined filename: %s', filename)
filename = os.path.join(directory, subid, filename) filename = os.path.join(subid, filename)
self.logger.info('saveas: %s', filename) filepath = os.path.join(directory, filename)
self.logger.info('saveas: %s', filepath)
with open(filename, 'wb+') as f: with open(filepath, 'wb+') as f:
f.write(r.content) f.write(r.content)
return filename return filename

0
requirements.txt Normal file → Executable file
View File