-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.md~
81 lines (59 loc) · 1.92 KB
/
README.md~
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Link Parse
[Python](https://www.python.org/) library for parsing memento link headers.
## Installation
Installation of the library requires [pip](https://pip.pypa.io/en/stable/) package installer for Python.
Install pip: [https://pip.pypa.io/en/stable/installation/](https://pip.pypa.io/en/stable/installation/)
### 1. Using Git
```shell
pip install https://github.com/mahanama94/link-parser
```
### 2. Local copy
```shell
pip install path/to/package/directory
```
## Usage
```python
# sample.py
from linkparse.regex_parser import RegexLinkParser
from pprint import pprint
link_header = '<http://www.mementoweb.org:80/>; rel="original", '\
'<https://web.archive.org/web/timemap/link/http://www.mementoweb.org:80/>; rel="timemap"; '\
'type="application/link-format", <https://web.archive.org/web/http://www.mementoweb.org:80/>; '\
'rel="timegate", <https://web.archive.org/web/20090930115825/http://www.mementoweb.org/>; rel="first '\
'memento"; datetime="Wed, 30 Sep 2009 11:58:25 GMT" '
parser = RegexLinkParser()
parser_results = parser.parse(link_header)
for result in parser_results:
pprint(result.__dict__)
```
```shell
$ python sample.py
{'datetime': '',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'original',
'title': '',
'uri': 'http://www.mementoweb.org:80/'}
{'datetime': '',
'link_from': '',
'link_type': 'application/link-format',
'link_until': '',
'relationship': 'timemap',
'title': '',
'uri': 'https://web.archive.org/web/timemap/link/http://www.mementoweb.org:80/'}
{'datetime': '',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'timegate',
'title': '',
'uri': 'https://web.archive.org/web/http://www.mementoweb.org:80/'}
{'datetime': 'Wed, 30 Sep 2009 11:58:25 GMT',
'link_from': '',
'link_type': '',
'link_until': '',
'relationship': 'first memento',
'title': '',
'uri': 'https://web.archive.org/web/20090930115825/http://www.mementoweb.org/'}
```