instapost 0.2.0__tar.gz → 0.2.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.
- {instapost-0.2.0 → instapost-0.2.1}/PKG-INFO +1 -1
- {instapost-0.2.0 → instapost-0.2.1}/instapost/__init__.py +1 -1
- {instapost-0.2.0 → instapost-0.2.1}/instapost/api/base.py +27 -5
- {instapost-0.2.0 → instapost-0.2.1}/instapost/client.py +12 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/media/uploader.py +29 -7
- {instapost-0.2.0 → instapost-0.2.1}/instapost/posting/carousel.py +10 -1
- {instapost-0.2.0 → instapost-0.2.1}/instapost/posting/image.py +7 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/posting/reel.py +6 -0
- {instapost-0.2.0 → instapost-0.2.1}/pyproject.toml +1 -1
- {instapost-0.2.0 → instapost-0.2.1}/.github/workflows/publish-to-pypi.yml +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/.github/workflows/python-package.yml +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/.gitignore +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/LICENSE +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/MANIFEST.in +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/README.md +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/api/__init__.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/exceptions.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/media/__init__.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/instapost/posting/__init__.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/logo.png +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/requirements.txt +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/__init__.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/conftest.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/test_api.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/test_client.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/test_exceptions.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/test_media_uploader.py +0 -0
- {instapost-0.2.0 → instapost-0.2.1}/tests/test_posting.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: instapost
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A Python library for automating Instagram posting (images, reels, carousels)
|
|
5
5
|
Project-URL: Homepage, https://blaya.ia.br
|
|
6
6
|
Project-URL: Repository, https://github.com/pedroluz/instapost
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import requests
|
|
2
3
|
import time
|
|
3
4
|
from abc import ABC, abstractmethod
|
|
4
5
|
|
|
5
6
|
from ..exceptions import ContainerProcessingError, ContainerTimeoutError
|
|
6
7
|
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
class BaseInstagramClient(ABC):
|
|
9
12
|
"""Base class for Instagram API clients."""
|
|
@@ -18,47 +21,65 @@ class BaseInstagramClient(ABC):
|
|
|
18
21
|
"""Make a request to the Graph API."""
|
|
19
22
|
url = f"{self.BASE_URL}/{endpoint}"
|
|
20
23
|
kwargs.setdefault("params", {})["access_token"] = self.access_token
|
|
24
|
+
logger.debug(f"Making {method} request to {endpoint}")
|
|
21
25
|
response = requests.request(method, url, **kwargs)
|
|
22
26
|
response.raise_for_status()
|
|
27
|
+
logger.debug(f"{method} request to {endpoint} successful")
|
|
23
28
|
return response.json()
|
|
24
29
|
|
|
25
30
|
def _create_container(self, params: dict) -> str:
|
|
26
31
|
"""Create a media container and return its ID."""
|
|
32
|
+
logger.info(f"Creating media container with params: {params}")
|
|
27
33
|
result = self._request("POST", "me/media", params=params)
|
|
28
|
-
|
|
34
|
+
container_id = result["id"]
|
|
35
|
+
logger.info(f"Media container created with ID: {container_id}")
|
|
36
|
+
return container_id
|
|
29
37
|
|
|
30
38
|
def _publish_container(self, container_id: str) -> dict:
|
|
31
39
|
"""Publish a media container."""
|
|
32
|
-
|
|
40
|
+
logger.info(f"Publishing media container {container_id}")
|
|
41
|
+
result = self._request(
|
|
33
42
|
"POST",
|
|
34
43
|
"me/media_publish",
|
|
35
44
|
params={"creation_id": container_id},
|
|
36
45
|
)
|
|
46
|
+
logger.info(f"Media container {container_id} published successfully")
|
|
47
|
+
return result
|
|
37
48
|
|
|
38
49
|
def _wait_for_container(self, container_id: str, timeout: int = 60, interval: int = 5) -> None:
|
|
39
50
|
"""Wait for a media container to finish processing."""
|
|
51
|
+
logger.info(f"Waiting for container {container_id} to finish processing (timeout: {timeout}s)")
|
|
40
52
|
elapsed = 0
|
|
41
53
|
while elapsed < timeout:
|
|
42
54
|
result = self._request("GET", container_id, params={"fields": "status_code,status"})
|
|
43
55
|
status = result.get("status_code")
|
|
56
|
+
logger.debug(f"Container {container_id} status: {status}")
|
|
44
57
|
|
|
45
58
|
if status == "FINISHED":
|
|
59
|
+
logger.info(f"Container {container_id} finished processing")
|
|
46
60
|
return
|
|
47
61
|
if status == "ERROR":
|
|
48
|
-
|
|
62
|
+
error_msg = f"Container processing failed: {result.get('status')}"
|
|
63
|
+
logger.error(error_msg)
|
|
64
|
+
raise ContainerProcessingError(error_msg)
|
|
49
65
|
|
|
50
66
|
time.sleep(interval)
|
|
51
67
|
elapsed += interval
|
|
52
68
|
|
|
53
|
-
|
|
69
|
+
error_msg = f"Container {container_id} did not finish processing in {timeout}s"
|
|
70
|
+
logger.error(error_msg)
|
|
71
|
+
raise ContainerTimeoutError(error_msg)
|
|
54
72
|
|
|
55
73
|
def verify(self) -> dict:
|
|
56
74
|
"""Verify credentials and return account info."""
|
|
57
|
-
|
|
75
|
+
logger.info("Verifying Instagram credentials")
|
|
76
|
+
result = self._request(
|
|
58
77
|
"GET",
|
|
59
78
|
"me",
|
|
60
79
|
params={"fields": "id,username,name"},
|
|
61
80
|
)
|
|
81
|
+
logger.info(f"Credentials verified for user: {result.get('username')}")
|
|
82
|
+
return result
|
|
62
83
|
|
|
63
84
|
def publish(self, container_id: str) -> dict:
|
|
64
85
|
"""
|
|
@@ -70,6 +91,7 @@ class BaseInstagramClient(ABC):
|
|
|
70
91
|
Returns:
|
|
71
92
|
API response with the published media ID.
|
|
72
93
|
"""
|
|
94
|
+
logger.info(f"Publishing container {container_id}")
|
|
73
95
|
return self._publish_container(container_id)
|
|
74
96
|
|
|
75
97
|
@abstractmethod
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
from typing import Optional
|
|
2
3
|
import os
|
|
3
4
|
|
|
@@ -7,6 +8,8 @@ from .posting.reel import ReelPoster
|
|
|
7
8
|
from .posting.carousel import CarouselPoster
|
|
8
9
|
from .media.uploader import MediaUploader
|
|
9
10
|
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
class InstagramPoster(BaseInstagramClient):
|
|
12
15
|
"""Unified client for posting images, reels, and carousels to Instagram."""
|
|
@@ -40,8 +43,11 @@ class InstagramPoster(BaseInstagramClient):
|
|
|
40
43
|
Returns:
|
|
41
44
|
API response with published media ID
|
|
42
45
|
"""
|
|
46
|
+
image_display = image[:50] + "..." if len(image) > 50 else image
|
|
47
|
+
logger.info(f"Posting image: {image_display}")
|
|
43
48
|
# Auto-upload if local file
|
|
44
49
|
if os.path.exists(image):
|
|
50
|
+
logger.info("Detected local file, uploading to Catbox first")
|
|
45
51
|
image = MediaUploader.upload_image(image)
|
|
46
52
|
|
|
47
53
|
return self._image.post(image, caption)
|
|
@@ -78,11 +84,15 @@ class InstagramPoster(BaseInstagramClient):
|
|
|
78
84
|
Returns:
|
|
79
85
|
API response with published media ID
|
|
80
86
|
"""
|
|
87
|
+
video_display = video[:50] + "..." if len(video) > 50 else video
|
|
88
|
+
logger.info(f"Posting reel: {video_display}")
|
|
81
89
|
# Auto-upload if local files
|
|
82
90
|
if os.path.exists(video):
|
|
91
|
+
logger.info("Detected local video, uploading to Catbox first")
|
|
83
92
|
video = MediaUploader.upload_video(video)
|
|
84
93
|
|
|
85
94
|
if cover and os.path.exists(cover):
|
|
95
|
+
logger.info("Detected local cover image, uploading to Catbox first")
|
|
86
96
|
cover = MediaUploader.upload_image(cover)
|
|
87
97
|
|
|
88
98
|
return self._reel.post(video, caption, cover, share_to_feed, timeout)
|
|
@@ -103,11 +113,13 @@ class InstagramPoster(BaseInstagramClient):
|
|
|
103
113
|
Returns:
|
|
104
114
|
API response with published media ID
|
|
105
115
|
"""
|
|
116
|
+
logger.info(f"Posting carousel with {len(media_items)} items")
|
|
106
117
|
# Auto-upload local files
|
|
107
118
|
processed_items = []
|
|
108
119
|
for item in media_items:
|
|
109
120
|
media = item['media']
|
|
110
121
|
if os.path.exists(media):
|
|
122
|
+
logger.info("Detected local file in carousel, uploading to Catbox first")
|
|
111
123
|
media = MediaUploader.upload(media)
|
|
112
124
|
|
|
113
125
|
processed_items.append({
|
|
@@ -3,10 +3,13 @@ Media upload utilities for converting local files to public URLs.
|
|
|
3
3
|
Uses Catbox for all file uploads (images and videos).
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
+
import logging
|
|
6
7
|
import os
|
|
7
8
|
import requests
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
class MediaUploader:
|
|
12
15
|
"""Upload local media files to Catbox and return public URLs."""
|
|
@@ -33,17 +36,22 @@ class MediaUploader:
|
|
|
33
36
|
ValueError: If file type is not supported
|
|
34
37
|
requests.RequestException: If upload fails
|
|
35
38
|
"""
|
|
39
|
+
logger.info(f"Uploading media file: {file_path}")
|
|
36
40
|
if not os.path.exists(file_path):
|
|
37
|
-
|
|
41
|
+
error_msg = f"Media file not found: {file_path}"
|
|
42
|
+
logger.error(error_msg)
|
|
43
|
+
raise FileNotFoundError(error_msg)
|
|
38
44
|
|
|
39
45
|
file_ext = Path(file_path).suffix.lower()
|
|
40
46
|
|
|
41
47
|
# Validate file type
|
|
42
48
|
if file_ext not in (cls.SUPPORTED_IMAGES | cls.SUPPORTED_VIDEOS):
|
|
43
|
-
|
|
49
|
+
error_msg = (
|
|
44
50
|
f"Unsupported file type: {file_ext}. "
|
|
45
51
|
f"Supported: {cls.SUPPORTED_IMAGES | cls.SUPPORTED_VIDEOS}"
|
|
46
52
|
)
|
|
53
|
+
logger.error(error_msg)
|
|
54
|
+
raise ValueError(error_msg)
|
|
47
55
|
|
|
48
56
|
return cls._upload_to_catbox(file_path)
|
|
49
57
|
|
|
@@ -58,12 +66,17 @@ class MediaUploader:
|
|
|
58
66
|
Returns:
|
|
59
67
|
Public URL of the uploaded image
|
|
60
68
|
"""
|
|
69
|
+
logger.info(f"Uploading image: {image_path}")
|
|
61
70
|
if not os.path.exists(image_path):
|
|
62
|
-
|
|
71
|
+
error_msg = f"Image file not found: {image_path}"
|
|
72
|
+
logger.error(error_msg)
|
|
73
|
+
raise FileNotFoundError(error_msg)
|
|
63
74
|
|
|
64
75
|
file_ext = Path(image_path).suffix.lower()
|
|
65
76
|
if file_ext not in cls.SUPPORTED_IMAGES:
|
|
66
|
-
|
|
77
|
+
error_msg = f"Unsupported image format: {file_ext}"
|
|
78
|
+
logger.error(error_msg)
|
|
79
|
+
raise ValueError(error_msg)
|
|
67
80
|
|
|
68
81
|
return cls._upload_to_catbox(image_path)
|
|
69
82
|
|
|
@@ -78,12 +91,17 @@ class MediaUploader:
|
|
|
78
91
|
Returns:
|
|
79
92
|
Public URL of the uploaded video
|
|
80
93
|
"""
|
|
94
|
+
logger.info(f"Uploading video: {video_path}")
|
|
81
95
|
if not os.path.exists(video_path):
|
|
82
|
-
|
|
96
|
+
error_msg = f"Video file not found: {video_path}"
|
|
97
|
+
logger.error(error_msg)
|
|
98
|
+
raise FileNotFoundError(error_msg)
|
|
83
99
|
|
|
84
100
|
file_ext = Path(video_path).suffix.lower()
|
|
85
101
|
if file_ext not in cls.SUPPORTED_VIDEOS:
|
|
86
|
-
|
|
102
|
+
error_msg = f"Unsupported video format: {file_ext}"
|
|
103
|
+
logger.error(error_msg)
|
|
104
|
+
raise ValueError(error_msg)
|
|
87
105
|
|
|
88
106
|
return cls._upload_to_catbox(video_path)
|
|
89
107
|
|
|
@@ -101,6 +119,7 @@ class MediaUploader:
|
|
|
101
119
|
Raises:
|
|
102
120
|
requests.RequestException: If upload fails
|
|
103
121
|
"""
|
|
122
|
+
logger.debug(f"Uploading to Catbox: {file_path}")
|
|
104
123
|
with open(file_path, 'rb') as f:
|
|
105
124
|
files = {'fileToUpload': f}
|
|
106
125
|
data = {'reqtype': 'fileupload'}
|
|
@@ -110,6 +129,9 @@ class MediaUploader:
|
|
|
110
129
|
url = response.text.strip()
|
|
111
130
|
|
|
112
131
|
if not url or url.startswith('error'):
|
|
113
|
-
|
|
132
|
+
error_msg = f"Catbox upload failed: {url}"
|
|
133
|
+
logger.error(error_msg)
|
|
134
|
+
raise requests.RequestException(error_msg)
|
|
114
135
|
|
|
136
|
+
logger.info(f"Successfully uploaded to Catbox: {url}")
|
|
115
137
|
return url
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
1
3
|
from ..api.base import BaseInstagramClient
|
|
2
4
|
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
3
7
|
|
|
4
8
|
class CarouselPoster(BaseInstagramClient):
|
|
5
9
|
"""Post carousels (multiple images/videos) to Instagram."""
|
|
@@ -19,8 +23,11 @@ class CarouselPoster(BaseInstagramClient):
|
|
|
19
23
|
Returns:
|
|
20
24
|
Container ID for publishing.
|
|
21
25
|
"""
|
|
26
|
+
logger.info(f"Uploading carousel with {len(media_items)} items to Instagram")
|
|
22
27
|
if not self.MIN_ITEMS <= len(media_items) <= self.MAX_ITEMS:
|
|
23
|
-
|
|
28
|
+
error_msg = f"Carousel must have between {self.MIN_ITEMS} and {self.MAX_ITEMS} items"
|
|
29
|
+
logger.error(error_msg)
|
|
30
|
+
raise ValueError(error_msg)
|
|
24
31
|
|
|
25
32
|
children_ids = [self._create_child(media) for media in media_items]
|
|
26
33
|
return self._create_container({
|
|
@@ -31,11 +38,13 @@ class CarouselPoster(BaseInstagramClient):
|
|
|
31
38
|
|
|
32
39
|
def post(self, media_items: list[dict], caption: str = "") -> dict:
|
|
33
40
|
"""Upload and publish a carousel."""
|
|
41
|
+
logger.info("Publishing carousel post")
|
|
34
42
|
return self.publish(self.upload(media_items, caption))
|
|
35
43
|
|
|
36
44
|
def _create_child(self, media: dict) -> str:
|
|
37
45
|
"""Create a child container for a carousel item."""
|
|
38
46
|
media_type = media.get("type", "IMAGE").upper()
|
|
47
|
+
logger.debug(f"Creating carousel child item of type {media_type}")
|
|
39
48
|
params = {"is_carousel_item": "true"}
|
|
40
49
|
|
|
41
50
|
if media_type == "IMAGE":
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
1
3
|
from ..api.base import BaseInstagramClient
|
|
2
4
|
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
3
7
|
|
|
4
8
|
class ImagePoster(BaseInstagramClient):
|
|
5
9
|
"""Post single images to Instagram."""
|
|
@@ -15,8 +19,11 @@ class ImagePoster(BaseInstagramClient):
|
|
|
15
19
|
Returns:
|
|
16
20
|
Container ID for publishing.
|
|
17
21
|
"""
|
|
22
|
+
image_display = image[:50] + "..." if len(image) > 50 else image
|
|
23
|
+
logger.info(f"Uploading image to Instagram: {image_display}")
|
|
18
24
|
return self._create_container({"image_url": image, "caption": caption})
|
|
19
25
|
|
|
20
26
|
def post(self, image: str, caption: str = "") -> dict:
|
|
21
27
|
"""Upload and publish a single image."""
|
|
28
|
+
logger.info("Publishing image post")
|
|
22
29
|
return self.publish(self.upload(image, caption))
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
from typing import Optional
|
|
2
3
|
|
|
3
4
|
from ..api.base import BaseInstagramClient
|
|
4
5
|
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
class ReelPoster(BaseInstagramClient):
|
|
7
10
|
"""Post reels to Instagram."""
|
|
@@ -27,6 +30,8 @@ class ReelPoster(BaseInstagramClient):
|
|
|
27
30
|
Returns:
|
|
28
31
|
Container ID for publishing.
|
|
29
32
|
"""
|
|
33
|
+
video_display = video[:50] + "..." if len(video) > 50 else video
|
|
34
|
+
logger.info(f"Uploading reel to Instagram: {video_display}")
|
|
30
35
|
params = {
|
|
31
36
|
"media_type": "REELS",
|
|
32
37
|
"video_url": video,
|
|
@@ -49,4 +54,5 @@ class ReelPoster(BaseInstagramClient):
|
|
|
49
54
|
timeout: int = 120,
|
|
50
55
|
) -> dict:
|
|
51
56
|
"""Upload and publish a reel."""
|
|
57
|
+
logger.info("Publishing reel post")
|
|
52
58
|
return self.publish(self.upload(video, caption, cover, share_to_feed, timeout))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|