Skip to content

Commit c6a8ab6

Browse files
author
2knal
committed
Publish to PyPi
Refactoring code, with version change.
1 parent 602882b commit c6a8ab6

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ Python package to generate a random proxy on the fly!
1919
- Fetch elite / transparent / anonymous proxies respectively.
2020
- Fetch directly from [free-proxy-list](https://free-proxy-list.net).
2121
- For better response time, fetch from an elasticsearch `cache_server`.
22-
- `cache_server` is updated via routines described [here](./random_proxies/cache_server/README.md)
22+
- `cache_server` is updated via routines described [here](./random_proxies/cache/README.md)
2323

2424

2525
## Example usage
26-
<!-- ```bash
27-
pip install random_proxies
26+
27+
```bash
28+
pip install random-proxies
2829
```
29-
or -->
30+
or
3031
```bash
3132
$ git clone https://github.com/2knal/random_proxies.git`
3233
$ cd random_proxies/
@@ -40,16 +41,16 @@ Open python interpreter. (Supports version 3.7+)
4041
'23.101.2.247:81'
4142
```
4243

43-
Refer more examples [here](./examples/)
44+
Refer more examples [here](./examples/example.py)
4445

4546
## TODO
4647

4748
- [x] Port to MongoDB
48-
- [ ] Publish package version 0.0.1
49+
- [x] Publish package version 0.0.2
4950
- [ ] Return meta data, response structure found [here](./random_proxies/cache/README.md)
5051
- [ ] Scrape proxies from other sources
5152
- [ ] Add support for SOCKS version 5
52-
- [ ] Implement REST API to allow other languages to interface with it
53+
- [x] Implement REST API to allow other languages to interface with it
5354
- [ ] Setup documentation page
5455
- [ ] Add unit tests
5556

examples/example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
(Once the package is published)
3-
pip install random_proxies
3+
pip install random-proxies
44
or
55
Follow example usage to import the package
66
'''

random_proxies/cache/app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def fetch():
2222
# Fetch from proxies
2323
proxies = proxies_collection.find(conditions)
2424
if proxies.count() == 0:
25-
raise NoSuchProxyError('No proxy satisfying given conditions.')
25+
return jsonify({ 'success': 'no' })
2626

2727
# Randomly select it
2828
proxies = list(proxies)
@@ -36,7 +36,7 @@ def fetch():
3636
# Add it to recents index
3737
recents_collection.insert_one(proxy)
3838

39-
return jsonify({ 'ip': ip })
39+
return jsonify({ 'ip': ip, 'success': 'yes' })
4040

4141
except Exception as e:
4242
template = 'An exception of type {0} occurred.\nArguments: {1!r}'

random_proxies/proxies/db.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
import json
55
import requests
6+
67
from random_proxies.proxies.settings import CACHE_SERVER_URL
8+
from random_proxies.proxies.exception import NoSuchProxyError
79

810
def pop(conditions):
911
query_string = '?'
@@ -14,4 +16,7 @@ def pop(conditions):
1416
data = requests.get(url).text
1517
data = json.loads(data)
1618

17-
return data['ip']
19+
if data['success'] == 'yes':
20+
return data['ip']
21+
else:
22+
raise NoSuchProxyError('No proxy satisfying given conditions.')

random_proxies/proxies/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
33

4-
__version__ = '0.0.1'
4+
__version__ = '0.0.2'
55

66
BASE_URL = 'https://free-proxy-list.net/'
77
SSL_URL = 'http://sslproxies.org/'

0 commit comments

Comments
 (0)