Skip to content

Commit

Permalink
Update 0.5
Browse files Browse the repository at this point in the history
- scraped pastes now are automatically sorted into subdirectories unless the noSorting flag is set
  • Loading branch information
InitialPosition committed Feb 13, 2020
1 parent 437aa09 commit 6a9cbf5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ keywords.txt

# pycharm stuff
.idea/

# vscode
.vscode/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Parameters are back baby
| Parameter | Optional? | Default | Effect |
| --------- | --------- | ------- | ------ |
| -k / --keywords | Yes | None | A file containing keywords to scrape for. One keyword per line. |
| -i / --infinite | Yes | No | Whether to run in infinite mode or in keyfile mode |
| -i / --infinite | Yes | False | Whether to run in infinite mode or in keyfile mode |
| -nS / --noSorting | Yes | False | Whether to sort keyword pastes into subdirectories |

### Roadmap
- [X] Parameter input
- [ ] Index file for keywords
- [X] Index for keywords
17 changes: 15 additions & 2 deletions scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ def main():
keyword),
"green")

if args.noSorting is False:
path_file = path.join("files", keyword, "{0}.txt".format(entry["key"]))

with open(path_file, "w+", encoding='utf-8') as entry_file:
entry_file.write(entry_content)

break
else:
with open(path_file, "w+", encoding='utf-8') as entry_file:
entry_file.write(entry_content)

bar.suffix = "%(index)d/%(max)d Saving paste \'{0}\'".format(entry["key"])

bar.next()
Expand Down Expand Up @@ -113,7 +117,7 @@ def main():

AUTHOR = "SYRAPT0R"
COPYRIGHT = "2019-2020"
VERSION = "0.4.5"
VERSION = "0.5"

# parse arguments
keywords = None
Expand All @@ -123,6 +127,8 @@ def main():
parser.add_argument("-k", "--keywords", help="A file containing keywords for the search")
parser.add_argument("-i", "--infinite", help="Whether to run in infinite mode (Default: false)",
action="store_true", default=False)
parser.add_argument("-nS", "--noSorting", help="Whether to sort keyword pastes into subdirectories",
action="store_true", default=False)

args = parser.parse_args()

Expand All @@ -141,11 +147,18 @@ def main():

except IOError:
status(termcolor.colored("Unable to load specified keyword file. Aborting...", "red"))

exit(0)

keywords = [keyword.strip() for keyword in keywords]

# create subdirectories if required
if args.noSorting is False:
for keyword in keywords:
current_path = path.join("files", keyword)
if not path.isdir(current_path):
status(termcolor.colored("Creating directory {0}".format(current_path), "yellow"))
mkdir(current_path)

status("Loaded {0} keywords".format(len(keywords)))

# create paste ID index
Expand Down

0 comments on commit 6a9cbf5

Please sign in to comment.