Skip to content

Commit 9b2ae8e

Browse files
committed
rewrite with classes
1 parent 826f408 commit 9b2ae8e

15 files changed

+1164
-831
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ Internet-archive is a nice source for several OSINT-information. This tool is a
1111

1212
This tool allows you to download content from the Wayback Machine (archive.org). You can use it to download either the latest version or all versions of web page snapshots within a specified range.
1313

14+
# Content
15+
16+
➡️ [Installation](#installation) <br>
17+
➡️ [notes / issues / hints](#notes--issues--hints) <br>
18+
➡️ [import](#import) <br>
19+
➡️ [cli](#cli) <br>
20+
➡️ [Usage](#usage) <br>
21+
➡️ [Examples](#examples) <br>
22+
➡️ [Output](#output) <br>
23+
➡️ [Contributing](#contributing) <br>
24+
1425
## Installation
1526

1627
### Pip
@@ -43,8 +54,14 @@ This tool allows you to download content from the Wayback Machine (archive.org).
4354
You can import pywaybackup into your own scripts and run it. Args are the same as cli.
4455

4556
Additional args:
46-
- `silent` (default True): If True, suppresses all output to the console.
47-
- `debug` (default False): If True, disables writing errors to the error log file.
57+
- `silent` (default False): If True, suppresses all output to the console.
58+
- `debug` (default True): If False, disables writing errors to the error log file.
59+
60+
Use:
61+
- `run()`
62+
- `status()`
63+
- `paths()`
64+
- `stop()`
4865

4966
```python
5067
from pywaybackup import PyWayBackup
@@ -76,6 +93,29 @@ output:
7693
}
7794
```
7895

96+
... or run it asynchronously and print the current status or stop it whenever needed.
97+
98+
```python
99+
import time
100+
from pywaybackup import PyWayBackup
101+
102+
backup = PyWayBackup( ... )
103+
backup.run(daemon=True)
104+
print(backup.status())
105+
time.sleep(10)
106+
print(backup.status())
107+
backup.stop()
108+
```
109+
output:
110+
```bash
111+
{
112+
'task': 'downloading snapshots',
113+
'current': 15,
114+
'total': 84,
115+
'progress': '18%'
116+
}
117+
```
118+
79119
## cli
80120

81121
- `-h`, `--help`: Show the help message and exit.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages = ["pywaybackup"]
77

88
[project]
99
name = "pywaybackup"
10-
version = "3.4.1"
10+
version = "4.0.0"
1111
description = "Query and download archive.org as simple as possible."
1212
authors = [
1313
{ name = "bitdruid", email = "[email protected]" }

pywaybackup/Arguments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def __init__(self):
2424
optional = parser.add_argument_group("optional query parameters")
2525
optional.add_argument("-e", "--explicit", action="store_true", help="search only for the explicit given url")
2626
optional.add_argument("-r", "--range", type=int, metavar="", help="range in years to search")
27-
optional.add_argument("--start", type=int, metavar="", help="start timestamp format: YYYYMMDDhhmmss")
28-
optional.add_argument("--end", type=int, metavar="", help="end timestamp format: YYYYMMDDhhmmss")
27+
optional.add_argument("--start", type=int, metavar="", help="start timestamp format: YYYYMMDDHHMMSS")
28+
optional.add_argument("--end", type=int, metavar="", help="end timestamp format: YYYYMMDDHHMMSS")
2929
optional.add_argument("--limit", type=int, nargs="?", const=True, metavar="int", help="limit the number of snapshots to download")
3030
optional.add_argument("--filetype", type=str, metavar="", help="filetypes to download comma separated (js,css,...)")
3131
optional.add_argument("--statuscode", type=str, metavar="", help="statuscodes to download comma separated (200,404,...)")
@@ -55,3 +55,4 @@ def __init__(self):
5555
def get_args(self) -> dict:
5656
"""Returns the parsed arguments as a dictionary."""
5757
return vars(self.args)
58+

pywaybackup/Exception.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class Exception:
1414
command = None
1515

1616
@classmethod
17-
def init(cls, debug=None, output=None, command=None):
17+
def init(cls, debugfile=None, output=None, command=None):
1818
sys.excepthook = cls.exception_handler # set custom exception handler (uncaught exceptions)
19-
cls.debug = debug
19+
cls.debugfile = debugfile
2020
cls.output = output
2121
cls.command = command
2222

@@ -45,18 +45,18 @@ def exception(cls, message: str, e: Exception, tb=None):
4545
exception_message += "!-- Traceback is None\n"
4646
exception_message += f"!-- Description: {e}\n-------------------------"
4747
print(exception_message)
48-
if cls.debug:
49-
print(f"Exception log: {cls.debug}")
48+
if cls.debugfile:
49+
print(f"Exception log: {cls.debugfile}")
5050
if cls.new_debug: # new run, overwrite file
5151
cls.new_debug = False
52-
f = open(cls.debug, "w", encoding="utf-8")
52+
f = open(cls.debugfile, "w", encoding="utf-8")
5353
f.write("-------------------------\n")
5454
f.write(f"Version: {version('pywaybackup')}\n")
5555
f.write("-------------------------\n")
5656
f.write(f"Command: {cls.command}\n")
5757
f.write("-------------------------\n\n")
5858
else: # current run, append to file
59-
f = open(cls.debug, "a", encoding="utf-8")
59+
f = open(cls.debugfile, "a", encoding="utf-8")
6060
f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n")
6161
f.write(exception_message + "\n")
6262
f.write("!-- Local Variables:\n")
@@ -96,4 +96,4 @@ def exception_handler(exception_type, exception, traceback):
9696
if issubclass(exception_type, KeyboardInterrupt):
9797
sys.__excepthook__(exception_type, exception, traceback)
9898
return
99-
Exception.exception("UNCAUGHT EXCEPTION", exception, traceback) # uncaught exceptions also with custom scheme
99+
Exception.exception('UNCAUGHT EXCEPTION', exception, traceback) # uncaught exceptions also with custom scheme

0 commit comments

Comments
 (0)