Skip to content

Commit

Permalink
Add stdin support
Browse files Browse the repository at this point in the history
  • Loading branch information
KarimPwnz committed Dec 15, 2021
1 parent 4119158 commit c52646a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions waybacked/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import sys
import time
from functools import wraps
from random import randint
Expand Down Expand Up @@ -59,20 +60,29 @@ def run(self):
yield data


def main():
parser = argparse.ArgumentParser()
parser.add_argument("search", metavar="search", nargs=None, help="Search query")
args = parser.parse_args()
search = WaybackSearch(args.search)
def process_search(search):
search = WaybackSearch(search)
try:
for page in search.run():
for url in page:
print(url, flush=True)
except KeyboardInterrupt:
pass
except WaybackSearchError as e:
print(e)


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"search", metavar="search", nargs="?", help="Search query", default=None
)
args = parser.parse_args()
search_strs = (args.search,) if args.search else (l.rstrip("\n") for l in sys.stdin)
try:
for search in search_strs:
process_search(search)
except KeyboardInterrupt:
pass


if __name__ == "__main__":
main()

0 comments on commit c52646a

Please sign in to comment.