MeliAPIClient 0.0.1__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.
- MeliAPIClient-0.0.1/MeliAPIClient/__init__.py +3 -0
- MeliAPIClient-0.0.1/MeliAPIClient/actions.py +36 -0
- MeliAPIClient-0.0.1/MeliAPIClient/bill.py +42 -0
- MeliAPIClient-0.0.1/MeliAPIClient/order.py +66 -0
- MeliAPIClient-0.0.1/MeliAPIClient/session.py +74 -0
- MeliAPIClient-0.0.1/MeliAPIClient/ship.py +18 -0
- MeliAPIClient-0.0.1/MeliAPIClient.egg-info/PKG-INFO +60 -0
- MeliAPIClient-0.0.1/MeliAPIClient.egg-info/SOURCES.txt +13 -0
- MeliAPIClient-0.0.1/MeliAPIClient.egg-info/dependency_links.txt +1 -0
- MeliAPIClient-0.0.1/MeliAPIClient.egg-info/requires.txt +1 -0
- MeliAPIClient-0.0.1/MeliAPIClient.egg-info/top_level.txt +1 -0
- MeliAPIClient-0.0.1/PKG-INFO +60 -0
- MeliAPIClient-0.0.1/README.md +44 -0
- MeliAPIClient-0.0.1/setup.cfg +4 -0
- MeliAPIClient-0.0.1/setup.py +36 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from requests import request
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Actions:
|
|
6
|
+
|
|
7
|
+
def get(self, url, headers, params={}, data={}):
|
|
8
|
+
|
|
9
|
+
response = request("GET",
|
|
10
|
+
url,
|
|
11
|
+
headers=headers,
|
|
12
|
+
params=params,
|
|
13
|
+
data=data)
|
|
14
|
+
|
|
15
|
+
if response.status_code == 404:
|
|
16
|
+
return False
|
|
17
|
+
|
|
18
|
+
return json.loads(response.text)
|
|
19
|
+
|
|
20
|
+
def post(self, url: str, headers, params: dict = {},
|
|
21
|
+
data: dict = {}, file: dict = {}):
|
|
22
|
+
|
|
23
|
+
response = request("POST",
|
|
24
|
+
url,
|
|
25
|
+
headers=headers,
|
|
26
|
+
params=params,
|
|
27
|
+
data=data,
|
|
28
|
+
files=file)
|
|
29
|
+
|
|
30
|
+
if response.status_code == 404:
|
|
31
|
+
response = json.loads(response.text)
|
|
32
|
+
return print("[ERROR] ", response)
|
|
33
|
+
|
|
34
|
+
elif response.status_code == 204:
|
|
35
|
+
response = json.loads(response.text)
|
|
36
|
+
return print(response)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from .actions import Actions
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Bill(Actions):
|
|
5
|
+
|
|
6
|
+
def __init__(self, session) -> None:
|
|
7
|
+
self.session = session
|
|
8
|
+
|
|
9
|
+
def info(self, id):
|
|
10
|
+
|
|
11
|
+
'''Return billing information from a order by id'''
|
|
12
|
+
|
|
13
|
+
url = f"https://api.mercadolibre.com/orders/{id}/billing_info"
|
|
14
|
+
|
|
15
|
+
response = self.get(url, self.session.headers)
|
|
16
|
+
|
|
17
|
+
return response
|
|
18
|
+
|
|
19
|
+
def documents(self, pack_id):
|
|
20
|
+
|
|
21
|
+
'''check if order has a invoice return True of False'''
|
|
22
|
+
|
|
23
|
+
url = f"https://api.mercadolibre.com/packs/{pack_id}/fiscal_documents"
|
|
24
|
+
|
|
25
|
+
response = self.get(url, self.session.headers)
|
|
26
|
+
|
|
27
|
+
if response is False:
|
|
28
|
+
return response
|
|
29
|
+
|
|
30
|
+
return True
|
|
31
|
+
|
|
32
|
+
def upload(self, id, url_file):
|
|
33
|
+
|
|
34
|
+
url = f"https://api.mercadolibre.com/packs/{id}/fiscal_documents"
|
|
35
|
+
|
|
36
|
+
files = {
|
|
37
|
+
'fiscal_document': open(url_file, 'rb')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
response = self.post(url, self.session.headers, fl=files)
|
|
41
|
+
|
|
42
|
+
return response
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from calendar import monthrange
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from .actions import Actions
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Order(Actions):
|
|
7
|
+
|
|
8
|
+
def __init__(self, session) -> None:
|
|
9
|
+
|
|
10
|
+
self.session = session
|
|
11
|
+
|
|
12
|
+
def date(self, year=None, month=None):
|
|
13
|
+
|
|
14
|
+
dt = datetime.now()
|
|
15
|
+
|
|
16
|
+
if year is not None and month is not None:
|
|
17
|
+
dt = datetime(year, month, 1)
|
|
18
|
+
|
|
19
|
+
days = monthrange(int(dt.strftime("%Y")), int(dt.strftime("%m")))[1]
|
|
20
|
+
|
|
21
|
+
date: dict = {"start": dt.strftime("%Y-%m-01T00:00:00.000-00:00"),
|
|
22
|
+
"end": dt.strftime(f"%Y-%m-{days}T23:59:59.000-00:00"),
|
|
23
|
+
"year": int(dt.strftime("%Y")),
|
|
24
|
+
"month": str(dt.strftime("%b"))}
|
|
25
|
+
|
|
26
|
+
return date
|
|
27
|
+
|
|
28
|
+
def list(self, offset=0, year=None, month=None):
|
|
29
|
+
|
|
30
|
+
'''read orders from mercado libre api, max 50 orders, and starts with \
|
|
31
|
+
a order offset to read new orders'''
|
|
32
|
+
|
|
33
|
+
# set date range
|
|
34
|
+
date = self.date(year, month)
|
|
35
|
+
|
|
36
|
+
# endpoint
|
|
37
|
+
url = "https://api.mercadolibre.com/orders/search"
|
|
38
|
+
|
|
39
|
+
params = {
|
|
40
|
+
"seller": self.session.ml_user["id"],
|
|
41
|
+
"order.date_created.from": date["start"],
|
|
42
|
+
"order.date_created.to": date["end"],
|
|
43
|
+
"limit": 50,
|
|
44
|
+
"sort": "date_asc",
|
|
45
|
+
"offset": offset
|
|
46
|
+
}
|
|
47
|
+
print(params)
|
|
48
|
+
response = self.get(url, self.session.headers, params)
|
|
49
|
+
|
|
50
|
+
return response
|
|
51
|
+
|
|
52
|
+
def info(self, id):
|
|
53
|
+
|
|
54
|
+
url = f"https://api.mercadolibre.com/orders/{id}"
|
|
55
|
+
|
|
56
|
+
response = self.get(url, self.session.headers)
|
|
57
|
+
|
|
58
|
+
return response
|
|
59
|
+
|
|
60
|
+
def pack(self, order):
|
|
61
|
+
|
|
62
|
+
url = f"https://api.mercadolibre.com/packs/{order}"
|
|
63
|
+
|
|
64
|
+
response = self.get(url, self.session.headers)
|
|
65
|
+
|
|
66
|
+
return response
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from datetime import datetime, timedelta
|
|
2
|
+
from requests import request
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Session:
|
|
7
|
+
|
|
8
|
+
def __init__(self, keys: json, token: json, user: json) -> None:
|
|
9
|
+
|
|
10
|
+
self.headers: dict = {
|
|
11
|
+
"Authorization": "",
|
|
12
|
+
"format-new": "true"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
self.ml_keys = read(keys)
|
|
16
|
+
self.ml_token = read(token)
|
|
17
|
+
self.ml_user = read(user)
|
|
18
|
+
|
|
19
|
+
self.access()
|
|
20
|
+
|
|
21
|
+
def access(self) -> dict:
|
|
22
|
+
|
|
23
|
+
time_flag = timedelta(hours=5, minutes=59, seconds=0.0)
|
|
24
|
+
date_token = datetime.fromisoformat(self.ml_token['date'])
|
|
25
|
+
token_time = datetime.now()-date_token
|
|
26
|
+
|
|
27
|
+
if time_flag > token_time:
|
|
28
|
+
self.headers['Authorization'] = \
|
|
29
|
+
f'Bearer {self.ml_token["access_token"]}'
|
|
30
|
+
return self.ml_token
|
|
31
|
+
|
|
32
|
+
self.refresh()
|
|
33
|
+
self.headers['Authorization'] = \
|
|
34
|
+
f'Bearer {self.ml_token["access_token"]}'
|
|
35
|
+
|
|
36
|
+
return self.ml_token
|
|
37
|
+
|
|
38
|
+
def refresh(self) -> None:
|
|
39
|
+
|
|
40
|
+
url = "https://api.mercadolibre.com/oauth/token"
|
|
41
|
+
|
|
42
|
+
payload: dict = {
|
|
43
|
+
"grant_type": "refresh_token",
|
|
44
|
+
"client_id": self.ml_keys['client_id'],
|
|
45
|
+
"client_secret": self.ml_keys['client_secret'],
|
|
46
|
+
"refresh_token": self.ml_token['refresh_token']
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
headers: dict = {
|
|
50
|
+
'accept': 'application/json',
|
|
51
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
response = request("POST", url, headers=headers, data=payload)
|
|
55
|
+
|
|
56
|
+
ml_response: dict = json.loads(response.text)
|
|
57
|
+
ml_response["date"] = datetime.isoformat(datetime.now())
|
|
58
|
+
|
|
59
|
+
write("ml_token.json", ml_response)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def read(file_name: str) -> dict:
|
|
63
|
+
with open(file_name, "r") as content:
|
|
64
|
+
return (json.load(content))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def write(file_name: str, data: dict) -> None:
|
|
68
|
+
with open(file_name, 'w') as content:
|
|
69
|
+
json.dump(data, content, ensure_ascii=False, indent=2)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
session = Session()
|
|
74
|
+
print(session.user["id"])
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .actions import Actions
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Ship(Actions):
|
|
5
|
+
|
|
6
|
+
def __init__(self, session) -> None:
|
|
7
|
+
|
|
8
|
+
self.session = session
|
|
9
|
+
|
|
10
|
+
def info(self, id) -> dict:
|
|
11
|
+
|
|
12
|
+
'''Return shipping information from a order by id'''
|
|
13
|
+
|
|
14
|
+
url = f"https://api.mercadolibre.com/shipments/{id}"
|
|
15
|
+
|
|
16
|
+
response = self.get(url, self.session.headers)
|
|
17
|
+
|
|
18
|
+
return response
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: MeliAPIClient
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Este paquete nos permite consumir el API de mercado libre
|
|
5
|
+
Home-page: https://github.com/andresroh/MeliAPIClient
|
|
6
|
+
Author: Camilo Andrés Rodríguez Higuera
|
|
7
|
+
Author-email: hola@camilordz.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: python,mercado libre,mercadolibre.com
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# MeliAPIClient
|
|
18
|
+
|
|
19
|
+
Este módulo permite interactuar con el API de mercado libre para leer, actualizar y crear productos y órdenes. Este módulo es útil para integrar el API de Mercado libre con otros sistemas.
|
|
20
|
+
|
|
21
|
+
## Instalación
|
|
22
|
+
|
|
23
|
+
Para instalar este módulo, ejecute el siguiente comando:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install MeliAPIClient
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Uso básico
|
|
30
|
+
|
|
31
|
+
Para usar este módulo, debemos guardar las credenciales en 3 archivos tipo JSON. El archivo `ml_keys` almacena el `client_id` y `client_secret`, `ml_token` almacena la información para renovar la sesión después del límite de 6 horas, y `ml_user` que almacena la información del usuario, donde el dato más importante es el ID del usuario.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from MeliAPIClient import Session
|
|
35
|
+
from MeliAPIClient import Order
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def run():
|
|
39
|
+
|
|
40
|
+
session = Session("ml_keys.json", 'ml_token.json', "ml_user.json")
|
|
41
|
+
orders = Order(session)
|
|
42
|
+
|
|
43
|
+
orders.list(year=2024, month=5)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
run()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Créditos
|
|
51
|
+
|
|
52
|
+
Camilo Andrés Rodriguez
|
|
53
|
+
|
|
54
|
+
## referencias
|
|
55
|
+
|
|
56
|
+
https://developers.mercadolibre.com/
|
|
57
|
+
|
|
58
|
+
## Licencia
|
|
59
|
+
|
|
60
|
+
Este proyecto está bajo la Licencia [MIT].
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
MeliAPIClient/__init__.py
|
|
4
|
+
MeliAPIClient/actions.py
|
|
5
|
+
MeliAPIClient/bill.py
|
|
6
|
+
MeliAPIClient/order.py
|
|
7
|
+
MeliAPIClient/session.py
|
|
8
|
+
MeliAPIClient/ship.py
|
|
9
|
+
MeliAPIClient.egg-info/PKG-INFO
|
|
10
|
+
MeliAPIClient.egg-info/SOURCES.txt
|
|
11
|
+
MeliAPIClient.egg-info/dependency_links.txt
|
|
12
|
+
MeliAPIClient.egg-info/requires.txt
|
|
13
|
+
MeliAPIClient.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MeliAPIClient
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: MeliAPIClient
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Este paquete nos permite consumir el API de mercado libre
|
|
5
|
+
Home-page: https://github.com/andresroh/MeliAPIClient
|
|
6
|
+
Author: Camilo Andrés Rodríguez Higuera
|
|
7
|
+
Author-email: hola@camilordz.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: python,mercado libre,mercadolibre.com
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# MeliAPIClient
|
|
18
|
+
|
|
19
|
+
Este módulo permite interactuar con el API de mercado libre para leer, actualizar y crear productos y órdenes. Este módulo es útil para integrar el API de Mercado libre con otros sistemas.
|
|
20
|
+
|
|
21
|
+
## Instalación
|
|
22
|
+
|
|
23
|
+
Para instalar este módulo, ejecute el siguiente comando:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install MeliAPIClient
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Uso básico
|
|
30
|
+
|
|
31
|
+
Para usar este módulo, debemos guardar las credenciales en 3 archivos tipo JSON. El archivo `ml_keys` almacena el `client_id` y `client_secret`, `ml_token` almacena la información para renovar la sesión después del límite de 6 horas, y `ml_user` que almacena la información del usuario, donde el dato más importante es el ID del usuario.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from MeliAPIClient import Session
|
|
35
|
+
from MeliAPIClient import Order
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def run():
|
|
39
|
+
|
|
40
|
+
session = Session("ml_keys.json", 'ml_token.json', "ml_user.json")
|
|
41
|
+
orders = Order(session)
|
|
42
|
+
|
|
43
|
+
orders.list(year=2024, month=5)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
run()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Créditos
|
|
51
|
+
|
|
52
|
+
Camilo Andrés Rodriguez
|
|
53
|
+
|
|
54
|
+
## referencias
|
|
55
|
+
|
|
56
|
+
https://developers.mercadolibre.com/
|
|
57
|
+
|
|
58
|
+
## Licencia
|
|
59
|
+
|
|
60
|
+
Este proyecto está bajo la Licencia [MIT].
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# MeliAPIClient
|
|
2
|
+
|
|
3
|
+
Este módulo permite interactuar con el API de mercado libre para leer, actualizar y crear productos y órdenes. Este módulo es útil para integrar el API de Mercado libre con otros sistemas.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
Para instalar este módulo, ejecute el siguiente comando:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install MeliAPIClient
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Uso básico
|
|
14
|
+
|
|
15
|
+
Para usar este módulo, debemos guardar las credenciales en 3 archivos tipo JSON. El archivo `ml_keys` almacena el `client_id` y `client_secret`, `ml_token` almacena la información para renovar la sesión después del límite de 6 horas, y `ml_user` que almacena la información del usuario, donde el dato más importante es el ID del usuario.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from MeliAPIClient import Session
|
|
19
|
+
from MeliAPIClient import Order
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run():
|
|
23
|
+
|
|
24
|
+
session = Session("ml_keys.json", 'ml_token.json', "ml_user.json")
|
|
25
|
+
orders = Order(session)
|
|
26
|
+
|
|
27
|
+
orders.list(year=2024, month=5)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
run()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Créditos
|
|
35
|
+
|
|
36
|
+
Camilo Andrés Rodriguez
|
|
37
|
+
|
|
38
|
+
## referencias
|
|
39
|
+
|
|
40
|
+
https://developers.mercadolibre.com/
|
|
41
|
+
|
|
42
|
+
## Licencia
|
|
43
|
+
|
|
44
|
+
Este proyecto está bajo la Licencia [MIT].
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
this_directory = Path(__file__).parent
|
|
5
|
+
long_description = (this_directory / "README.md").read_text()
|
|
6
|
+
|
|
7
|
+
VERSION = '0.0.1'
|
|
8
|
+
DESCRIPTION = 'Este paquete nos permite consumir el API de mercado libre'
|
|
9
|
+
PACKAGE_NAME = 'MeliAPIClient'
|
|
10
|
+
AUTHOR = 'Camilo Andrés Rodríguez Higuera'
|
|
11
|
+
EMAIL = 'hola@camilordz.com'
|
|
12
|
+
GITHUB_URL = 'https://github.com/andresroh/MeliAPIClient'
|
|
13
|
+
|
|
14
|
+
setup(
|
|
15
|
+
name=PACKAGE_NAME,
|
|
16
|
+
packages=[PACKAGE_NAME],
|
|
17
|
+
version=VERSION,
|
|
18
|
+
license='MIT',
|
|
19
|
+
description=DESCRIPTION,
|
|
20
|
+
long_description_content_type="text/markdown",
|
|
21
|
+
long_description=long_description,
|
|
22
|
+
author=AUTHOR,
|
|
23
|
+
author_email=EMAIL,
|
|
24
|
+
url=GITHUB_URL,
|
|
25
|
+
keywords=['python', 'mercado libre', 'mercadolibre.com'],
|
|
26
|
+
install_requires=[
|
|
27
|
+
'requests',
|
|
28
|
+
],
|
|
29
|
+
classifiers=[
|
|
30
|
+
'Development Status :: 3 - Alpha',
|
|
31
|
+
'Intended Audience :: Developers',
|
|
32
|
+
'Topic :: Software Development :: Build Tools',
|
|
33
|
+
'License :: OSI Approved :: MIT License',
|
|
34
|
+
'Programming Language :: Python :: 3',
|
|
35
|
+
],
|
|
36
|
+
)
|