1
0
Fork 0
mirror of synced 2024-05-19 11:42:40 +12:00

Added verbose mode

This commit is contained in:
Ali Parlakci 2018-07-25 13:40:06 +03:00
parent e6b648d8b3
commit 837281c3c6
4 changed files with 50 additions and 28 deletions

View file

@ -10,13 +10,13 @@ usage: script.py [-h] [--directory DIRECTORY] [--link link] [--saved]
[--subreddit SUBREDDIT [SUBREDDIT ...]]
[--multireddit MULTIREDDIT] [--user redditor]
[--search query] [--sort SORT TYPE] [--limit Limit]
[--time TIME_LIMIT] [--NoDownload]
[--time TIME_LIMIT] [--NoDownload] [--verbose]
This program downloads media from reddit posts
optional arguments:
-h, --help show this help message and exit
--directory DIRECTORY
--directory DIRECTORY, -d DIRECTORY
Specifies the directory where posts will be downloaded
to
--link link, -l link Get posts from link
@ -40,6 +40,7 @@ optional arguments:
all
--NoDownload Just gets the posts and store them in a file for
downloading later
--verbose, -v Verbose Mode
```
# Examples

View file

@ -62,7 +62,7 @@ def parseArguments(arguments=[]):
description="This program downloads " \
"media from reddit " \
"posts")
parser.add_argument("--directory",
parser.add_argument("--directory","-d",
help="Specifies the directory where posts will be " \
"downloaded to",
metavar="DIRECTORY")
@ -144,6 +144,11 @@ def parseArguments(arguments=[]):
action="store_true",
default=False)
parser.add_argument("--verbose","-v",
help="Verbose Mode",
action="store_true",
default=False)
if arguments == []:
return parser.parse_args()

View file

@ -1,4 +1,5 @@
import os
import sys
import random
import socket
import webbrowser
@ -306,6 +307,7 @@ def redditSearcher(posts,SINGLE_POST=False):
allPosts = {}
print("GETTING POSTS")
postsFile = createLogFile("POSTS")
if SINGLE_POST:
@ -326,40 +328,53 @@ def redditSearcher(posts,SINGLE_POST=False):
if result is not None:
details = result
orderCount += 1
printSubmission(submission,subCount,orderCount)
if GLOBAL.arguments.verbose:
printSubmission(submission,subCount,orderCount)
subList.append(details)
postsFile.add({subCount:[details]})
else:
for submission in posts:
subCount += 1
try:
for submission in posts:
subCount += 1
try:
details = {'postId':submission.id,
'postTitle':submission.title,
'postSubmitter':str(submission.author),
'postType':None,
'postURL':submission.url,
'postSubreddit':submission.subreddit.display_name}
except AttributeError:
continue
if subCount % 100 == 0 and not GLOBAL.arguments.verbose:
sys.stdout.write("")
sys.stdout.flush()
result = checkIfMatching(submission)
if subCount % 1000 == 0:
sys.stdout.write("\n")
sys.stdout.flush()
if result is not None:
details = result
orderCount += 1
printSubmission(submission,subCount,orderCount)
subList.append(details)
try:
details = {'postId':submission.id,
'postTitle':submission.title,
'postSubmitter':str(submission.author),
'postType':None,
'postURL':submission.url,
'postSubreddit':submission.subreddit.display_name}
except AttributeError:
continue
allPosts[subCount] = [details]
result = checkIfMatching(submission)
if result is not None:
details = result
orderCount += 1
if GLOBAL.arguments.verbose:
printSubmission(submission,subCount,orderCount)
subList.append(details)
allPosts[subCount] = [details]
except KeyboardInterrupt:
print("\nKeyboardInterrupt",end="")
postsFile.add(allPosts)
if not len(subList) == 0:
print(
"\nTotal of {} submissions found!\n"\
"\n\nTotal of {} submissions found!\n"\
"{} GFYCATs, {} IMGURs, {} EROMEs, {} DIRECTs and {} SELF POSTS\n"
.format(
len(subList),

View file

@ -102,11 +102,12 @@ def printToFile(*args, **kwargs):
if not path.exists(folderDirectory):
makedirs(folderDirectory)
with io.open(
folderDirectory / "CONSOLE_LOG.txt","a",encoding="utf-8"
) as FILE:
print(*args, file=FILE, **kwargs)
if not "file" in kwargs:
with io.open(
folderDirectory / "CONSOLE_LOG.txt","a",encoding="utf-8"
) as FILE:
print(*args, file=FILE, **kwargs)
def nameCorrector(string):
"""Swap strange characters from given string