This repository was archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (56 loc) · 2.54 KB
/
main.py
File metadata and controls
61 lines (56 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import click
import scrape
import download_webpage
@click.command()
@click.option('--url', help='Specify the URL to search for.', metavar='example.com')
@click.option('--term', help='Specify the search term.', metavar='"example"')
@click.option('--date', help='Specify a specific date.', metavar='YYYYMMDD')
@click.option('--time', help='Include the time in the search.', metavar='HHMMSS')
@click.option('--find', multiple=True, help='Find text on the webpage. (Case sensitive, include capitalization)', metavar='"Example"')
@click.option('--download', is_flag=True, help='Download webpage html.')
def main(url, term, date, time, find, download):
"""
CLI program to interact with the wayback machine.
"""
if not url and not term:
click.echo("--url or --term is required to begin search.")
return
elif term and not url:
click.echo(f"Searching for the term: {term}")
response = scrape.scrape(term, 'New')
scrape.termResults(response)
elif url and not term:
click.echo(f"Searching for the URL: {url}")
response = scrape.scrape(url, 'New')
info = scrape.getInfo(response)
if info:
print(info)
if date:
if time and len(time) == 6:
snapshot_url = scrape.makeUrl(info, url, date, time)
else:
snapshot_url = scrape.makeUrl(info, url, date, None)
if download and find:
terms = [term.strip() for terms_tuple in find for term in terms_tuple.split(',')]
scrape.find(terms, snapshot_url)
print('')
download_webpage.savePage(snapshot_url, date)
elif download and not find:
download_webpage.savePage(snapshot_url, date)
elif not download and find:
terms = [term.strip() for terms_tuple in find for term in terms_tuple.split(',')]
scrape.find(terms, snapshot_url)
else:
click.echo("Please specify an action. --find/--download")
return
else:
click.echo("Please specify a date. Use python main.py --help for more commands.")
return
else:
click.echo("Invalid URL please try again.")
return
else:
click.echo("Only one of the following options is allowed: --url --term")
return
if __name__ == '__main__':
main()