parsagon 0.4.1__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- parsagon/__init__.py +77 -0
- parsagon-0.5.0.dist-info/METADATA +16 -0
- parsagon-0.5.0.dist-info/RECORD +6 -0
- {parsagon-0.4.1.dist-info → parsagon-0.5.0.dist-info}/WHEEL +1 -1
- parsagon-0.4.1.data/scripts/parsagon-server +0 -84
- parsagon-0.4.1.dist-info/METADATA +0 -37
- parsagon-0.4.1.dist-info/RECORD +0 -7
- {parsagon-0.4.1.dist-info → parsagon-0.5.0.dist-info}/LICENSE +0 -0
- {parsagon-0.4.1.dist-info → parsagon-0.5.0.dist-info}/top_level.txt +0 -0
parsagon/__init__.py
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
import asyncio
|
2
|
+
import time
|
3
|
+
import httpx
|
4
|
+
|
5
|
+
|
6
|
+
POLL_INTERVAL = 5
|
7
|
+
ENVIRONMENTS = {
|
8
|
+
'local': 'LOCAL',
|
9
|
+
'cloud': 'DC',
|
10
|
+
'unblockable': 'RESID',
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
# Configuration variables
|
15
|
+
api_key = None
|
16
|
+
api_base = "https://parsagon.io/api"
|
17
|
+
|
18
|
+
|
19
|
+
def _request_to_exception(response):
|
20
|
+
if response.status_code == 500:
|
21
|
+
raise Exception('A server error occurred. Please notify Parsagon.')
|
22
|
+
if response.status_code in (502, 503, 504):
|
23
|
+
raise Exception('Lost connection to server.')
|
24
|
+
errors = response.json()
|
25
|
+
if 'non_field_errors' in errors:
|
26
|
+
raise Exception(errors['non_field_errors'])
|
27
|
+
else:
|
28
|
+
raise Exception(errors)
|
29
|
+
|
30
|
+
|
31
|
+
def _extract(api_endpoint, data):
|
32
|
+
headers = {"Authorization": f"Token {api_key}"}
|
33
|
+
r = httpx.post(api_endpoint, headers=headers, json=data)
|
34
|
+
if not r.is_success:
|
35
|
+
_request_to_exception(r)
|
36
|
+
poll_key = r.json()["poll_key"]
|
37
|
+
while True:
|
38
|
+
time.sleep(POLL_INTERVAL)
|
39
|
+
r = httpx.get(f"{api_base}/extract/poll/?poll_key={poll_key}", headers=headers)
|
40
|
+
if not r.is_success:
|
41
|
+
_request_to_exception(r)
|
42
|
+
data = r.json()
|
43
|
+
if data["done"]:
|
44
|
+
return data
|
45
|
+
|
46
|
+
|
47
|
+
async def _aextract(api_endpoint, data):
|
48
|
+
headers = {"Authorization": f"Token {api_key}"}
|
49
|
+
async with httpx.AsyncClient() as client:
|
50
|
+
r = await client.post(api_endpoint, headers=headers, json=data)
|
51
|
+
if not r.is_success:
|
52
|
+
_request_to_exception(r)
|
53
|
+
poll_key = r.json()["poll_key"]
|
54
|
+
while True:
|
55
|
+
asyncio.sleep(POLL_INTERVAL)
|
56
|
+
r = await client.get(f"{api_base}/extract/poll/?poll_key={poll_key}", headers=headers)
|
57
|
+
if not r.is_success:
|
58
|
+
_request_to_exception(r)
|
59
|
+
data = r.json()
|
60
|
+
if data["done"]:
|
61
|
+
return data
|
62
|
+
|
63
|
+
|
64
|
+
def get_product(url):
|
65
|
+
return _extract(f"{api_base}/extract/product/", {"url": url})
|
66
|
+
|
67
|
+
|
68
|
+
async def aget_product(url):
|
69
|
+
return await _aextract(f"{api_base}/extract/product/", {"url": url})
|
70
|
+
|
71
|
+
|
72
|
+
def get_product_list(url):
|
73
|
+
return _extract(f"{api_base}/extract/product-list/", {"url": url})
|
74
|
+
|
75
|
+
|
76
|
+
async def aget_product_list(url):
|
77
|
+
return await _aextract(f"{api_base}/extract/product-list/", {"url": url})
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: parsagon
|
3
|
+
Version: 0.5.0
|
4
|
+
Summary: Parsagon Python SDK
|
5
|
+
Home-page: https://parsagon.io
|
6
|
+
Author: Sandy Suh
|
7
|
+
Author-email: sandy@parsagon.io
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.6
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: httpx
|
15
|
+
|
16
|
+
# Parsagon Python Library
|
@@ -0,0 +1,6 @@
|
|
1
|
+
parsagon/__init__.py,sha256=KCcVCKj3LzCuTnYIfFqGr0dgvRpD9KxbMKvbBzQYj8M,2207
|
2
|
+
parsagon-0.5.0.dist-info/LICENSE,sha256=Uh1vwgS0bVQOH6l9NjvjVZ29D-Fc2oooaFuSHACEIWE,1095
|
3
|
+
parsagon-0.5.0.dist-info/METADATA,sha256=7jNpIsWEjeo56ubE5GGLZPtBHddANQ7Z82KQe4hCEyk,441
|
4
|
+
parsagon-0.5.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
5
|
+
parsagon-0.5.0.dist-info/top_level.txt,sha256=ih5uYQzW4qjhRKppys-WiHLIbXVZ99YdqDcfAtlcQwk,9
|
6
|
+
parsagon-0.5.0.dist-info/RECORD,,
|
@@ -1,84 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
ORIG_DIR=$PWD
|
4
|
-
IP_ADDR=$(dig @resolver4.opendns.com myip.opendns.com +short)
|
5
|
-
|
6
|
-
if [ -e /home/ubuntu/parsagon ]
|
7
|
-
then
|
8
|
-
rm -rf /home/ubuntu/parsagon
|
9
|
-
fi
|
10
|
-
|
11
|
-
mkdir -p /home/ubuntu/parsagon
|
12
|
-
cd /home/ubuntu/parsagon
|
13
|
-
git clone https://github.com/Sand1929/parsagon-local-server.git
|
14
|
-
|
15
|
-
cd /home/ubuntu/parsagon
|
16
|
-
echo $1 > api_key
|
17
|
-
if [ -z "$2" ]
|
18
|
-
then
|
19
|
-
echo 'parsagon.io' > parsagon_host
|
20
|
-
else
|
21
|
-
echo $2 > parsagon_host
|
22
|
-
fi
|
23
|
-
cd /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/server
|
24
|
-
printf '%s\n%s\n%s\n' "export PARSAGON_HOST=$(cat /home/ubuntu/parsagon/parsagon_host)" "export API_KEY=$(cat /home/ubuntu/parsagon/api_key)" "$(cat daphne.sh)" > daphne.sh
|
25
|
-
printf '%s\n%s\n%s\n' "export PARSAGON_HOST=$(cat /home/ubuntu/parsagon/parsagon_host)" "export API_KEY=$(cat /home/ubuntu/parsagon/api_key)" "$(cat celery.sh)" > celery.sh
|
26
|
-
|
27
|
-
sudo apt update
|
28
|
-
sudo apt -y upgrade
|
29
|
-
|
30
|
-
sudo apt -y install tinyproxy
|
31
|
-
sudo cp /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/tinyproxy.conf /etc/tinyproxy/tinyproxy.conf
|
32
|
-
|
33
|
-
sudo apt -y install libpq-dev python3-dev
|
34
|
-
|
35
|
-
sudo apt -y install unzip xvfb libxi6 libgconf-2-4
|
36
|
-
cd /home/ubuntu/parsagon
|
37
|
-
wget -O chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_99.0.4844.51-1_amd64.deb
|
38
|
-
sudo apt install -y /home/ubuntu/parsagon/chrome.deb
|
39
|
-
rm chrome.deb
|
40
|
-
|
41
|
-
sudo apt -y install redis-server
|
42
|
-
sudo cp /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/redis.conf /etc/redis/redis.conf
|
43
|
-
sudo systemctl restart redis.service
|
44
|
-
|
45
|
-
sudo apt -y install python3-venv
|
46
|
-
python3 -m venv /home/ubuntu/parsagon/venv
|
47
|
-
|
48
|
-
sudo apt -y install daphne
|
49
|
-
/home/ubuntu/parsagon/venv/bin/pip install -r /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/server/requirements.txt
|
50
|
-
|
51
|
-
if ! command -v mkcert &> /dev/null
|
52
|
-
then
|
53
|
-
cd /home/ubuntu/parsagon
|
54
|
-
sudo apt -y install libnss3-tools
|
55
|
-
sudo apt -y install golang-go
|
56
|
-
git clone https://github.com/FiloSottile/mkcert && cd mkcert
|
57
|
-
go build -ldflags "-X main.Version=$(git describe --tags)"
|
58
|
-
sudo cp mkcert /usr/local/bin/mkcert
|
59
|
-
sudo chmod +x /usr/local/bin/mkcert
|
60
|
-
fi
|
61
|
-
mkcert -cert-file /home/ubuntu/parsagon/cert.pem -key-file /home/ubuntu/parsagon/key.pem $IP_ADDR
|
62
|
-
|
63
|
-
sudo apt -y install nginx
|
64
|
-
sudo ufw allow 'Nginx HTTPS'
|
65
|
-
sudo cp /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/nginx.conf /etc/nginx/sites-available
|
66
|
-
if [ ! -e /etc/nginx/sites-enabled/nginx.conf ]
|
67
|
-
then
|
68
|
-
sudo ln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabled/
|
69
|
-
fi
|
70
|
-
if [ -e /etc/nginx/sites-enabled/default ]
|
71
|
-
then
|
72
|
-
sudo rm /etc/nginx/sites-enabled/default
|
73
|
-
fi
|
74
|
-
sudo systemctl restart nginx
|
75
|
-
|
76
|
-
sudo apt -y install supervisor
|
77
|
-
sudo cp /home/ubuntu/parsagon/parsagon-local-server/src/parsagon/supervisor.conf /etc/supervisor/conf.d/
|
78
|
-
sudo supervisorctl stop all
|
79
|
-
sudo supervisorctl update
|
80
|
-
sudo supervisorctl start all
|
81
|
-
|
82
|
-
sudo apt -y autoremove
|
83
|
-
|
84
|
-
cd $ORIG_DIR
|
@@ -1,37 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: parsagon
|
3
|
-
Version: 0.4.1
|
4
|
-
Summary: Parsagon Local Server
|
5
|
-
Home-page: https://parsagon.io
|
6
|
-
Author: Sandy Suh
|
7
|
-
Author-email: sandy@parsagon.io
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Requires-Python: >=3.6
|
12
|
-
Description-Content-Type: text/markdown
|
13
|
-
License-File: LICENSE
|
14
|
-
|
15
|
-
# parsagon-local-server
|
16
|
-
|
17
|
-
To install on Ubuntu 20:
|
18
|
-
```
|
19
|
-
sudo apt update
|
20
|
-
sudo apt install python3-pip
|
21
|
-
sudo apt install python3-venv
|
22
|
-
|
23
|
-
python3 -m venv parsagon-venv
|
24
|
-
source parsagon-venv/bin/activate
|
25
|
-
pip install parsagon
|
26
|
-
parsagon-server <paste your api_key here>
|
27
|
-
```
|
28
|
-
|
29
|
-
For development:
|
30
|
-
Make sure to include the test server as a second argument to parsagon-server:
|
31
|
-
`parsagon-server <api_key> <test_server>`
|
32
|
-
|
33
|
-
To add a proxy:
|
34
|
-
Edit /etc/tinyproxy/tinyproxy.conf to point to your proxy, then run:
|
35
|
-
`sudo service tinyproxy restart`
|
36
|
-
and add
|
37
|
-
`PROXY=127.0.0.1:8888` to `daphne.sh` and `celery.sh` and restart those tasks as well.
|
parsagon-0.4.1.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
parsagon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
parsagon-0.4.1.data/scripts/parsagon-server,sha256=LMv09HAMFORjKHxpN--nOtfMTfVQB5WSPSiUKTOwojg,2877
|
3
|
-
parsagon-0.4.1.dist-info/LICENSE,sha256=Uh1vwgS0bVQOH6l9NjvjVZ29D-Fc2oooaFuSHACEIWE,1095
|
4
|
-
parsagon-0.4.1.dist-info/METADATA,sha256=kM8PZywttz0rUHy3t6uia5unnyolRc4FQd-LoNPDCpM,1009
|
5
|
-
parsagon-0.4.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
6
|
-
parsagon-0.4.1.dist-info/top_level.txt,sha256=ih5uYQzW4qjhRKppys-WiHLIbXVZ99YdqDcfAtlcQwk,9
|
7
|
-
parsagon-0.4.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|