Skip to content

Commit

Permalink
remove created from filename #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Vogt committed Oct 27, 2020
1 parent 1f9c00f commit 0270828
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion moodle_dl/download_service/download_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def gen_path(storage_path: str, course: Course, file: File):
# If the file is located in a folder or in an assignment,
# it should be saved in a sub-folder
# (with the name of the module).
if file.module_modname in ['assign', 'folder', 'data']:
if file.module_modname.endswith(('assign', 'folder', 'data', 'forum')):
file_path = file.content_filepath
if file.content_type == 'submission_file':
file_path = os.path.join('/submissions/', file_path.strip('/'))
Expand Down
2 changes: 1 addition & 1 deletion moodle_dl/download_service/path_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def to_valid_name(name: str) -> str:
while ' ' in name:
name = name.replace(' ', ' ')
name = sanitize_filename(name, PathTools.restricted_filenames)
name = name.strip('.')
name = name.strip('. ')
name = name.strip()

return name
Expand Down
1 change: 1 addition & 0 deletions moodle_dl/download_service/url_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def create_description(self):

self.success = True
else:
self.set_utime()
self.file.time_stamp = int(time.time())

self.success = True
Expand Down
17 changes: 4 additions & 13 deletions moodle_dl/moodle_connector/forums_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

from moodle_dl.moodle_connector.request_helper import RequestHelper
from moodle_dl.state_recorder.course import Course
from moodle_dl.download_service.path_tools import PathTools
Expand Down Expand Up @@ -154,8 +152,8 @@ def _get_files_of_discussions(self, latest_discussions: []) -> []:
result = []

for i, discussion in enumerate(latest_discussions):

shorted_discussion_name = discussion.get('subject', '')
valid_subject = PathTools.to_valid_name(discussion.get('subject', ''))
shorted_discussion_name = valid_subject
if len(shorted_discussion_name) > 17:
shorted_discussion_name = shorted_discussion_name[:15] + '..'
discussion_id = discussion.get('discussion_id', 0)
Expand All @@ -178,23 +176,16 @@ def _get_files_of_discussions(self, latest_discussions: []) -> []:

for post in posts:
post_message = post.get('message', '')
post_created = post.get('created', 0)
post_modified = post.get('modified', 0)

post_id = post.get('id', 0)
post_parent = post.get('parent', 0)
post_userfullname = post.get('userfullname', '')
post_filename = PathTools.to_valid_name(
datetime.utcfromtimestamp(post_created).strftime('%Y-%m-%d %H:%M:%S')
+ ' ['
+ str(post_id)
+ '] '
+ post_userfullname
)
post_filename = PathTools.to_valid_name('[' + str(post_id) + '] ' + post_userfullname)
if post_parent != 0:
post_filename = PathTools.to_valid_name(post_filename + ' response to [' + str(post_parent) + ']')

post_path = PathTools.to_valid_name(discussion.get('subject', ''))
post_path = valid_subject

post_files = post.get('messageinlinefiles', [])
post_files += post.get('attachments', [])
Expand Down
10 changes: 7 additions & 3 deletions moodle_dl/moodle_connector/results_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,22 @@ def _find_all_urls_in_description(
urls += list(set(re.findall(r'src=[\'"]?([^\'" >]+)', description)))

result = []
original_module_modname = module_modname
if original_module_modname != "forum" and len(urls) > 0:
print(original_module_modname)

for url in urls:
if url == '':
continue

module_modname = 'url-description'
module_modname = 'url-description-' + original_module_modname

url_parts = urlparse.urlparse(url)
if url_parts.hostname == self.moodle_domain and url_parts.path.find('/webservice/') >= 0:
module_modname = 'index_mod-description'
module_modname = 'index_mod-description-' + original_module_modname

elif url_parts.hostname == self.moodle_domain:
module_modname = 'cookie_mod-description'
module_modname = 'cookie_mod-description-' + original_module_modname

new_file = File(
module_id=module_id,
Expand Down
12 changes: 12 additions & 0 deletions moodle_dl/state_recorder/state_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ def __files_have_same_type(self, file1: File, file2: File) -> bool:

if file1.content_type == file2.content_type and file1.module_modname == file2.module_modname:
return True

elif (
file1.content_type == 'description-url'
and file1.content_type == file2.content_type
and (
file1.module_modname.startswith(file2.module_modname)
or file2.module_modname.startswith(file1.module_modname)
)
):
# stop redownloading old description urls. Sorry the module_modname structure has changed
return True

return False

def __files_have_same_path(self, file1: File, file2: File) -> bool:
Expand Down

0 comments on commit 0270828

Please sign in to comment.