From e63ae467241473c23b84f6d3ab6a32ee2a82779f Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Sun, 21 Oct 2018 02:04:02 +0200 Subject: [PATCH] updated --- infomentor.png | Bin login.py | 26 +++++++++++++++----------- requirements.txt | 0 3 files changed, 15 insertions(+), 11 deletions(-) mode change 100644 => 100755 infomentor.png mode change 100644 => 100755 login.py mode change 100644 => 100755 requirements.txt diff --git a/infomentor.png b/infomentor.png old mode 100644 new mode 100755 diff --git a/login.py b/login.py old mode 100644 new mode 100755 index 365e9fe..bf3c669 --- a/login.py +++ b/login.py @@ -87,17 +87,21 @@ class NewsInformer(object): def make_site(self, text): filename = str(uuid.uuid4()) fpath = os.path.join('files', filename+'.html') + urlfinder = re.compile("(https?://[^ \n\t]*)") + text = urlfinder.sub(r'\1', text) + text = ' {}'.format(text) with open(fpath, 'w+') as f: f.write(text) - return 'https://files.hyttioaoa.de/{}'.format(fpath) + return 'https://files.hyttioaoa.de/{}.html'.format(filename) def send_notification( self, news_id, text, title, attachment=None, timestamp=True): self.logger.info('sending notification: %s', title) - text = text.replace('
', '\n') - if len(text) > 1000: + if len(text) > 900: url = self.make_site(text) - text = 'saved at: {}'.format(url) + shorttext = text[:900] + text = '{}...\n\nfulltext saved at: {}'.format(shorttext, url) + text = text.replace('
', '\n') try: self.logger.info(text) self.logger.info(title) @@ -155,8 +159,8 @@ class NewsInformer(object): att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0] f = self.im.download(attachment['url'], directory='files', skip=True) try: - _path, urlname = os.path.split(f) - storehw['homeworkText'] += '''\nAttachment {0}: https://files.hyttioaoa.de/{0}\n'''.format(urlname) + fid, fname = f.split('/') + storehw['homeworkText'] += '''
Attachment {0}: https://files.hyttioaoa.de/{1}
'''.format(fname, f) if self.db_attachments.find_one(id=int(att_id)): continue self.db_attachments.insert( @@ -197,8 +201,7 @@ class NewsInformer(object): att_id = re.findall('Download/([0-9]+)?', attachment['url'])[0] f = self.im.download(attachment['url'], directory='files', skip=True) try: - _path, urlname = os.path.split(f) - storenewsdata['content'] += '''\nAttachment {0}: https://files.hyttioaoa.de/{0}\n'''.format(urlname) + storenewsdata['content'] += '''
Attachment {0}: https://files.hyttioaoa.de/{0}
'''.format(f) if self.db_attachments.find_one(id=int(att_id)): continue self.db_attachments.insert( @@ -333,10 +336,11 @@ class Infomentor(object): self.logger.info('determine filename from headers') filename = get_filename_from_cd(r.headers.get('content-disposition')) self.logger.info('determined filename: %s', filename) - filename = os.path.join(directory, subid, filename) - self.logger.info('saveas: %s', filename) + filename = os.path.join(subid, 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) return filename diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755