Skip to content

Commit 8f0e2ed

Browse files
Update 0.5.1
- fixed a crash when no new pastes exist after hibernation
1 parent 6a9cbf5 commit 8f0e2ed

1 file changed

Lines changed: 34 additions & 29 deletions

File tree

scrape.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,48 @@ def main():
5555
if entry["key"] not in paste_ids:
5656
cleaned_json.append(entry)
5757

58-
# create a progress bar and start downloading pastes
59-
with Bar("Processing", max=len(cleaned_json), fill=">") as bar:
60-
for entry in cleaned_json:
61-
# download the raw paste data
62-
entry_request = requests.get("https://scrape.pastebin.com/api_scrape_item.php?i={0}"
63-
.format(entry["key"]))
58+
# create a progress bar and start downloading pastes if we have new ones
59+
if len(cleaned_json) is not 0:
60+
with Bar("Processing", max=len(cleaned_json), fill=">") as bar:
61+
for entry in cleaned_json:
62+
# download the raw paste data
63+
entry_request = requests.get("https://scrape.pastebin.com/api_scrape_item.php?i={0}"
64+
.format(entry["key"]))
6465

65-
entry_content = entry_request.text
66-
path_file = path.join("files", "{0}.txt".format(entry["key"]))
66+
entry_content = entry_request.text
67+
path_file = path.join("files", "{0}.txt".format(entry["key"]))
6768

68-
paste_ids.append(entry["key"])
69+
paste_ids.append(entry["key"])
6970

70-
# if we have a provided keyword list, check for keywords
71-
if keywords is not None:
72-
for keyword in keywords:
73-
if keyword.upper() in entry_content.upper():
74-
bar.suffix = "%(index)d/%(max)d " + termcolor.colored("[KEYWORD] Paste \'{0}\' contains "
75-
"keyword \'{1}\'".format(entry["key"],
76-
keyword),
77-
"green")
71+
# if we have a provided keyword list, check for keywords
72+
if keywords is not None:
73+
for keyword in keywords:
74+
if keyword.upper() in entry_content.upper():
75+
bar.suffix = "%(index)d/%(max)d " + termcolor.colored("[KEYWORD] Paste \'{0}\' contains "
76+
"keyword \'{1}\'".format(entry["key"],
77+
keyword),
78+
"green")
7879

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

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

85-
break
86-
else:
87-
with open(path_file, "w+", encoding='utf-8') as entry_file:
88-
entry_file.write(entry_content)
86+
break
87+
else:
88+
with open(path_file, "w+", encoding='utf-8') as entry_file:
89+
entry_file.write(entry_content)
8990

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

92-
bar.next()
93+
bar.next()
9394

94-
bar.finish()
95+
bar.finish()
96+
97+
# otherwise, just say that we didn't have any new content
98+
else:
99+
status("No new pastes found, skipping downloads...")
95100

96101
if args.infinite is False:
97102
if not isfile("runfile"):
@@ -117,7 +122,7 @@ def main():
117122

118123
AUTHOR = "SYRAPT0R"
119124
COPYRIGHT = "2019-2020"
120-
VERSION = "0.5"
125+
VERSION = "0.5.1"
121126

122127
# parse arguments
123128
keywords = None

0 commit comments

Comments
 (0)