Skip to content

Commit 6af29d9

Browse files
committed
update readme's
1 parent c8c0f34 commit 6af29d9

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,38 @@ For more information, please see the Ruby [README] [ruby-readme].
8282

8383
## Usage: Python
8484

85-
The Python version of this library still uses the **old** API, and identifies search referers only:
85+
Create a new instance of a Referer object by passing in the url you want to parse:
8686

8787
```python
8888
from referer_parser import Referer
8989

9090
referer_url = 'http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari'
9191

9292
r = Referer(referer_url)
93+
```
94+
95+
The `r` variable now holds a Referer instance. The important attributes are:
9396

97+
```python
9498
print(r.known) # True
9599
print(r.referer) # 'Google'
100+
print(r.medium) # 'search'
96101
print(r.search_parameter) # 'q'
97102
print(r.search_term) # 'gateway oracle cards denise linn'
98103
print(r.uri) # ParseResult(scheme='http', netloc='www.google.com', path='/search', params='', query='q=gateway+oracle+cards+denise+linn&hl=en&client=safari', fragment='')
99104
```
100105

106+
Optionally, pass in the current URL as well, to handle internal referers
107+
108+
```python
109+
from referer_parser import Referer
110+
111+
referer_url = 'http://www.snowplowanalytics.com/about/team'
112+
curr_url = 'http://www.snowplowanalytics.com/account/profile'
113+
114+
r = Referer(referer_url, curr_url)
115+
```
116+
101117
For more information, please see the Python [README] [python-readme].
102118

103119
## Usage: .NET

python/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ This is the Python implementation of [referer-parser] [referer-parser], the libr
55
The implementation uses the shared 'database' of known referers found in [`referers.yml`] [referers-yml] (converted to a `referers.json` file,
66
see below).
77

8-
**Currently the Python library only extracts search engine referers - it needs updating with the additional functionality now found in the Java/Scala version.**
9-
108
The Python version of referer-parser is maintained by [Don Spaulding] [donspaulding].
119

1210
## Installation
@@ -30,11 +28,34 @@ The `r` variable now holds a Referer instance. The important attributes are:
3028
```python
3129
print(r.known) # True
3230
print(r.referer) # 'Google'
31+
print(r.medium) # 'search'
3332
print(r.search_parameter) # 'q'
3433
print(r.search_term) # 'gateway oracle cards denise linn'
3534
print(r.uri) # ParseResult(scheme='http', netloc='www.google.com', path='/search', params='', query='q=gateway+oracle+cards+denise+linn&hl=en&client=safari', fragment='')
3635
```
3736

37+
Optionally, pass in the current URL as well, to handle internal referers
38+
39+
```python
40+
from referer_parser import Referer
41+
42+
referer_url = 'http://www.snowplowanalytics.com/about/team'
43+
curr_url = 'http://www.snowplowanalytics.com/account/profile'
44+
45+
r = Referer(referer_url, curr_url)
46+
```
47+
48+
The attributes would be
49+
50+
```python
51+
print(r.known) # True
52+
print(r.referer) # None
53+
print(r.medium) # 'internal'
54+
print(r.search_parameter) # None
55+
print(r.search_term) # None
56+
print(r.uri) # ParseResult(scheme='http', netloc='www.snowplowanalytics.com', path='/about/team', params='', query='', fragment='')
57+
```
58+
3859
The `uri` attribute is an instance of ParseResult from the standard library's `urlparse` module.
3960

4061
## referers.json

python/referer_parser/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, ref_url, curr_url=None):
3535
ref_uri = urlparse(ref_url)
3636
ref_host = ref_uri.hostname
3737
self.known = ref_uri.scheme in {'http', 'https'}
38+
self.uri = ref_uri
3839

3940
# print "Scheme: %s" % ref_uri.scheme
4041

0 commit comments

Comments
 (0)