From cc8570d02f019dd57d197d317669d58f080d8ebb Mon Sep 17 00:00:00 2001 From: pierre geeraert Date: Sun, 7 Dec 2025 23:22:46 +0000 Subject: [PATCH] adding reddit downloader --- django_code/django_code/urls.py | 2 + django_code/stash_management/apps.py | 26 +- .../templates/simple_form.html | 275 ++++++++++++++++++ 3 files changed, 300 insertions(+), 3 deletions(-) create mode 100644 django_code/stash_management/templates/simple_form.html diff --git a/django_code/django_code/urls.py b/django_code/django_code/urls.py index 02335f6..27761d8 100644 --- a/django_code/django_code/urls.py +++ b/django_code/django_code/urls.py @@ -66,6 +66,8 @@ urlpatterns = [ path('stash/incremental/', stashapp.incremental), path('stash/album/', stashapp.album), path('stash/album-form/', stashapp.album_form, name='submit_form'), + path('stash/album/', stashapp.simple), + path('stash/album-form/', stashapp.simple_form, name='submit_form'), path('stash/submit-form/', stashapp.handle_survey_form, name='submit_form'), path('stash/incremental-form/', stashapp.incremental_form, name='submit_form'), diff --git a/django_code/stash_management/apps.py b/django_code/stash_management/apps.py index 270cfad..2eed8bf 100644 --- a/django_code/stash_management/apps.py +++ b/django_code/stash_management/apps.py @@ -41,7 +41,8 @@ def form(request): return render(request, 'stash_form.html',{}) def album(request): return render(request, 'album_form.html',{}) - +def simple(request): + return render(request, 'simple_form.html',{}) def check_and_create_destination_folder(name): #check if the output directory exist and create if not if not os.path.isdir(destination_folder): @@ -137,7 +138,20 @@ def individual_image_downloader(image_url, filename ): print("Still Can't download "+filename+" -- "+image_url+" == Cancelling") return 0 +def simple_form(request): + name = request.GET.get('name') + reddit_downloader(username=name) + + text_generated = "successfully sent to the reddit downloader" + return HttpResponse(text_generated, content_type="text/plain") + def reddit_downloader(username): + + #create the prerequisites folder + destination_named_folder = check_and_create_destination_folder(name=username) + + + url = "https://www.reddit.com/user/"+username+"/submitted/.json?limit=1000" opener = urlrequest.build_opener(proxy) urlrequest.install_opener(opener) @@ -145,8 +159,14 @@ def reddit_downloader(username): req = urlrequest.Request(url) urlcurl = urlrequest.urlopen(req).read() data = json.loads(urlcurl) - print(data['data']['children'][0]['data']['url']) - print(data['data']['children'][3]['data']['url']) + + picture_list=[] + for children in data['data']['children']: + print("adding to the list : "+children['data']['url']) + picture_list.append(children['data']['url']) + + images_downloader.delay(name=username,images_url_list=picture_list,destination_named_folder=destination_named_folder) + return 0 def incremental(request): diff --git a/django_code/stash_management/templates/simple_form.html b/django_code/stash_management/templates/simple_form.html new file mode 100644 index 0000000..27ce4e8 --- /dev/null +++ b/django_code/stash_management/templates/simple_form.html @@ -0,0 +1,275 @@ + + + + + + Simple form + + + + + + + +
+
+
+
+

Stash Form

+

Download form

+
+
+ +
+ +
+ +
+
+
+
+