Skip to content

Commit

Permalink
Merge pull request #1 from jasonkhadka/filter_texts_on_title
Browse files Browse the repository at this point in the history
filter texts added
  • Loading branch information
jasonkhadka authored May 18, 2022
2 parents 4a8bc70 + 928dac6 commit 5301d84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ env/
!requirements.txt
images/*
comments/*
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -83,6 +84,7 @@ target/

# Jupyter Notebook
.ipynb_checkpoints
*.ipynb

# IPython
profile_default/
Expand Down Expand Up @@ -113,6 +115,7 @@ celerybeat.pid
# Environments
.env
.venv
.venv*
env/
venv/
ENV/
Expand Down Expand Up @@ -141,4 +144,5 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/

13 changes: 11 additions & 2 deletions grab_pictures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from utils import get_valid_filename, erase_previous_line, get_userAgent


def get_pictures_from_subreddit(data, subreddit, location, nsfw):
def get_pictures_from_subreddit(data, subreddit, location, nsfw, filter_texts):
if filter_texts is None:
filter_texts = []
for i in range(len(data)):
if data[i]['data']['over_18']:
# if nsfw post and you only want sfw
Expand All @@ -16,6 +18,11 @@ def get_pictures_from_subreddit(data, subreddit, location, nsfw):
continue

current_post = data[i]['data']
title = current_post['title'].lower()

if not any(map(lambda x: x.lower() in title, filter_texts)):
continue

image_url = current_post['url']
if '.png' in image_url:
extension = '.png'
Expand Down Expand Up @@ -55,6 +62,8 @@ def main():
help='Optionally specify the directory/location to be downloaded')
parser.add_argument('-x', '--nsfw', type=str, metavar='', default='y',
help='Optionally specify the behavior for handling NSFW content. y=yes download, n=no skip nsfw, x=only download nsfw content')
parser.add_argument('-f', '--filter-texts', nargs='+', type=str, metavar='',
required=False, help='One or more of the given filter texts need to be included in title of the images (e.g. "digital").')
args = parser.parse_args()

# initializing userAgent
Expand Down Expand Up @@ -97,7 +106,7 @@ def main():
print('downloading pictures from r/' + args.subreddit[j] + '..')

data = response.json()['data']['children']
get_pictures_from_subreddit(data, args.subreddit[j], location, args.nsfw)
get_pictures_from_subreddit(data, args.subreddit[j], location, args.nsfw, args.filter_texts)

erase_previous_line()
print('Downloaded pictures from r/' + args.subreddit[j])
Expand Down

0 comments on commit 5301d84

Please sign in to comment.