parsagon 0.4.2__tar.gz → 0.5.0__tar.gz

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.
Files changed (33) hide show
  1. parsagon-0.5.0/PKG-INFO +15 -0
  2. parsagon-0.5.0/README.md +1 -0
  3. {parsagon-0.4.2 → parsagon-0.5.0}/setup.cfg +4 -4
  4. parsagon-0.5.0/src/parsagon/__init__.py +77 -0
  5. parsagon-0.5.0/src/parsagon.egg-info/PKG-INFO +15 -0
  6. parsagon-0.5.0/src/parsagon.egg-info/SOURCES.txt +10 -0
  7. parsagon-0.5.0/src/parsagon.egg-info/requires.txt +1 -0
  8. parsagon-0.4.2/PKG-INFO +0 -37
  9. parsagon-0.4.2/README.md +0 -23
  10. parsagon-0.4.2/bin/parsagon-server +0 -84
  11. parsagon-0.4.2/src/parsagon/__init__.py +0 -0
  12. parsagon-0.4.2/src/parsagon/nginx.conf +0 -45
  13. parsagon-0.4.2/src/parsagon/redis.conf +0 -1372
  14. parsagon-0.4.2/src/parsagon/server/celery.sh +0 -5
  15. parsagon-0.4.2/src/parsagon/server/celeryconfig.py +0 -11
  16. parsagon-0.4.2/src/parsagon/server/daphne.sh +0 -5
  17. parsagon-0.4.2/src/parsagon/server/manage.py +0 -22
  18. parsagon-0.4.2/src/parsagon/server/server/__init__.py +0 -7
  19. parsagon-0.4.2/src/parsagon/server/server/asgi.py +0 -16
  20. parsagon-0.4.2/src/parsagon/server/server/celery.py +0 -20
  21. parsagon-0.4.2/src/parsagon/server/server/permissions.py +0 -7
  22. parsagon-0.4.2/src/parsagon/server/server/settings.py +0 -139
  23. parsagon-0.4.2/src/parsagon/server/server/tasks.py +0 -50
  24. parsagon-0.4.2/src/parsagon/server/server/urls.py +0 -28
  25. parsagon-0.4.2/src/parsagon/server/server/views.py +0 -82
  26. parsagon-0.4.2/src/parsagon/server/server/wsgi.py +0 -16
  27. parsagon-0.4.2/src/parsagon/supervisor.conf +0 -34
  28. parsagon-0.4.2/src/parsagon.egg-info/PKG-INFO +0 -37
  29. parsagon-0.4.2/src/parsagon.egg-info/SOURCES.txt +0 -26
  30. {parsagon-0.4.2 → parsagon-0.5.0}/LICENSE +0 -0
  31. {parsagon-0.4.2 → parsagon-0.5.0}/pyproject.toml +0 -0
  32. {parsagon-0.4.2 → parsagon-0.5.0}/src/parsagon.egg-info/dependency_links.txt +0 -0
  33. {parsagon-0.4.2 → parsagon-0.5.0}/src/parsagon.egg-info/top_level.txt +0 -0
@@ -0,0 +1,15 @@
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
+
15
+ # Parsagon Python Library
@@ -0,0 +1 @@
1
+ # Parsagon Python Library
@@ -1,9 +1,9 @@
1
1
  [metadata]
2
2
  name = parsagon
3
- version = 0.4.2
3
+ version = 0.5.0
4
4
  author = Sandy Suh
5
5
  author_email = sandy@parsagon.io
6
- description = Parsagon Local Server
6
+ description = Parsagon Python SDK
7
7
  long_description = file: README.md
8
8
  long_description_content_type = text/markdown
9
9
  url = https://parsagon.io
@@ -13,11 +13,11 @@ classifiers =
13
13
  Operating System :: OS Independent
14
14
 
15
15
  [options]
16
+ install_requires =
17
+ httpx
16
18
  package_dir =
17
19
  = src
18
20
  packages = find:
19
- scripts =
20
- bin/parsagon-server
21
21
  python_requires = >=3.6
22
22
 
23
23
  [options.packages.find]
@@ -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,15 @@
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
+
15
+ # Parsagon Python Library
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ src/parsagon/__init__.py
6
+ src/parsagon.egg-info/PKG-INFO
7
+ src/parsagon.egg-info/SOURCES.txt
8
+ src/parsagon.egg-info/dependency_links.txt
9
+ src/parsagon.egg-info/requires.txt
10
+ src/parsagon.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ httpx
parsagon-0.4.2/PKG-INFO DELETED
@@ -1,37 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: parsagon
3
- Version: 0.4.2
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.2/README.md DELETED
@@ -1,23 +0,0 @@
1
- # parsagon-local-server
2
-
3
- To install on Ubuntu 20:
4
- ```
5
- sudo apt update
6
- sudo apt install python3-pip
7
- sudo apt install python3-venv
8
-
9
- python3 -m venv parsagon-venv
10
- source parsagon-venv/bin/activate
11
- pip install parsagon
12
- parsagon-server <paste your api_key here>
13
- ```
14
-
15
- For development:
16
- Make sure to include the test server as a second argument to parsagon-server:
17
- `parsagon-server <api_key> <test_server>`
18
-
19
- To add a proxy:
20
- Edit /etc/tinyproxy/tinyproxy.conf to point to your proxy, then run:
21
- `sudo service tinyproxy restart`
22
- and add
23
- `PROXY=127.0.0.1:8888` to `daphne.sh` and `celery.sh` and restart those tasks as well.
@@ -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
File without changes
@@ -1,45 +0,0 @@
1
- upstream backend {
2
- server 127.0.0.1:8000;
3
- }
4
-
5
- server {
6
- server_name $server_addr;
7
-
8
- listen [::]:443 ssl ipv6only=on;
9
- listen 443 ssl;
10
- ssl_certificate /home/ubuntu/parsagon/cert.pem;
11
- ssl_certificate_key /home/ubuntu/parsagon/key.pem;
12
- proxy_read_timeout 300;
13
- proxy_connect_timeout 300;
14
-
15
- location / {
16
- # Pass request to the upstream alias
17
- proxy_pass http://backend;
18
-
19
- # Require http version 1.1 to allow for upgrade requests
20
- proxy_http_version 1.1;
21
-
22
- # Depending on the request value, set the Upgrade and
23
- # connection headers
24
- proxy_set_header Upgrade $http_upgrade;
25
- proxy_set_header Connection "upgrade";
26
-
27
- # We've set the Host header, so we don't need Nginx to muddle
28
- # about with redirects
29
- proxy_redirect off;
30
-
31
- # Pass the Host: header from the client for the sake of redirects
32
- proxy_set_header Host $host;
33
-
34
- # Pass client IP instead of proxy IP
35
- proxy_set_header X-Real-IP $remote_addr;
36
-
37
- # http://en.wikipedia.org/wiki/X-Forwarded-For
38
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
39
-
40
- # Pass server name instead of proxy
41
- proxy_set_header X-Forwarded-Host $server_name;
42
-
43
- client_max_body_size 100M;
44
- }
45
- }