Skip to content

Commit 6a9cbf5

Browse files
Update 0.5
- scraped pastes now are automatically sorted into subdirectories unless the noSorting flag is set
1 parent 437aa09 commit 6a9cbf5

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@ keywords.txt
139139

140140
# pycharm stuff
141141
.idea/
142+
143+
# vscode
144+
.vscode/

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Parameters are back baby
1818
| Parameter | Optional? | Default | Effect |
1919
| --------- | --------- | ------- | ------ |
2020
| -k / --keywords | Yes | None | A file containing keywords to scrape for. One keyword per line. |
21-
| -i / --infinite | Yes | No | Whether to run in infinite mode or in keyfile mode |
21+
| -i / --infinite | Yes | False | Whether to run in infinite mode or in keyfile mode |
22+
| -nS / --noSorting | Yes | False | Whether to sort keyword pastes into subdirectories |
2223

2324
### Roadmap
2425
- [X] Parameter input
25-
- [ ] Index file for keywords
26+
- [X] Index for keywords

scrape.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ def main():
7676
keyword),
7777
"green")
7878

79+
if args.noSorting is False:
80+
path_file = path.join("files", keyword, "{0}.txt".format(entry["key"]))
81+
7982
with open(path_file, "w+", encoding='utf-8') as entry_file:
8083
entry_file.write(entry_content)
8184

8285
break
8386
else:
8487
with open(path_file, "w+", encoding='utf-8') as entry_file:
8588
entry_file.write(entry_content)
89+
8690
bar.suffix = "%(index)d/%(max)d Saving paste \'{0}\'".format(entry["key"])
8791

8892
bar.next()
@@ -113,7 +117,7 @@ def main():
113117

114118
AUTHOR = "SYRAPT0R"
115119
COPYRIGHT = "2019-2020"
116-
VERSION = "0.4.5"
120+
VERSION = "0.5"
117121

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

127133
args = parser.parse_args()
128134

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

142148
except IOError:
143149
status(termcolor.colored("Unable to load specified keyword file. Aborting...", "red"))
144-
145150
exit(0)
146151

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

154+
# create subdirectories if required
155+
if args.noSorting is False:
156+
for keyword in keywords:
157+
current_path = path.join("files", keyword)
158+
if not path.isdir(current_path):
159+
status(termcolor.colored("Creating directory {0}".format(current_path), "yellow"))
160+
mkdir(current_path)
161+
149162
status("Loaded {0} keywords".format(len(keywords)))
150163

151164
# create paste ID index

0 commit comments

Comments
 (0)