instapost 0.2.0__py3-none-any.whl → 0.2.1__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.
instapost/__init__.py CHANGED
@@ -19,4 +19,4 @@ __all__ = [
19
19
  "ContainerProcessingError",
20
20
  "ContainerTimeoutError",
21
21
  ]
22
- __version__ = "0.1.0"
22
+ __version__ = "0.2.1"
instapost/api/base.py CHANGED
@@ -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
- return result["id"]
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
- return self._request(
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
- raise ContainerProcessingError(f"Container processing failed: {result.get('status')}")
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
- raise ContainerTimeoutError(f"Container {container_id} did not finish processing in {timeout}s")
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
- return self._request(
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
instapost/client.py CHANGED
@@ -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
- raise FileNotFoundError(f"Media file not found: {file_path}")
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
- raise ValueError(
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
- raise FileNotFoundError(f"Image file not found: {image_path}")
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
- raise ValueError(f"Unsupported image format: {file_ext}")
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
- raise FileNotFoundError(f"Video file not found: {video_path}")
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
- raise ValueError(f"Unsupported video format: {file_ext}")
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
- raise requests.RequestException(f"Catbox upload failed: {url}")
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
- raise ValueError(f"Carousel must have between {self.MIN_ITEMS} and {self.MAX_ITEMS} items")
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))
instapost/posting/reel.py CHANGED
@@ -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))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: instapost
3
- Version: 0.2.0
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
@@ -0,0 +1,15 @@
1
+ instapost/__init__.py,sha256=NHYkbEq7lA_H-Q7NDxF9p-IGAvn-JGqf5kKKZ3jXL5g,539
2
+ instapost/client.py,sha256=b3je3b9F9AtY-0sgrt--yGLRbQg4ET8OIqzCd6XT4DI,4798
3
+ instapost/exceptions.py,sha256=M7G5fXuLjDNoRnDSvyVqVXluHx8pxYn1VxtDX3qf3BU,347
4
+ instapost/api/__init__.py,sha256=6RVaMnFTtJm0l9nIC5tMBxJw7B_NFXxor7AlsqWb7hc,73
5
+ instapost/api/base.py,sha256=gCNl04a89ilSd4PyNALznFzwpl2bC3ZeSZD8wm3XORg,3977
6
+ instapost/media/__init__.py,sha256=rhLMklySKJzeL1cCvhYfX4x-n23NAhgIzDXUT-0Aav0,65
7
+ instapost/media/uploader.py,sha256=FcS87nzDrm00Y0oLWDaIW3Q6_BYdFV2eQwJGG4n62a8,4216
8
+ instapost/posting/__init__.py,sha256=Jedqh7qWBfGtE9AoVPV8dWzZoNZ6xbZbejxbpmUU4lI,156
9
+ instapost/posting/carousel.py,sha256=K0RTBEfftR7Qn7sMCo4Q0nld2m8txmAv4CpSqi2NKFc,2122
10
+ instapost/posting/image.py,sha256=H3jlQOTo6FubjfyEAmZ2HWgj7ELqGNgT85kIzOTVd-o,963
11
+ instapost/posting/reel.py,sha256=utXeaaD_sbg0_S5U54ixoKvElY4sC075oCDRaEH-lsI,1803
12
+ instapost-0.2.1.dist-info/METADATA,sha256=Iwv4OgdrMVQijnXLiys8Bri5aLtbmZoWTETIK0rHEto,4199
13
+ instapost-0.2.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
+ instapost-0.2.1.dist-info/licenses/LICENSE,sha256=dkJtwqp6h8qdcFKHbnKzGIMZx09yloEYxasC3rlSjP8,1071
15
+ instapost-0.2.1.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- instapost/__init__.py,sha256=HhTIume5EvcD7jWTFnJmZee3h0dpramjur8501ccWLs,539
2
- instapost/client.py,sha256=M6K41MNDb0KGHGeJYtPrb-BAnXF92BoEEP6Cc7OVfgU,4099
3
- instapost/exceptions.py,sha256=M7G5fXuLjDNoRnDSvyVqVXluHx8pxYn1VxtDX3qf3BU,347
4
- instapost/api/__init__.py,sha256=6RVaMnFTtJm0l9nIC5tMBxJw7B_NFXxor7AlsqWb7hc,73
5
- instapost/api/base.py,sha256=eNVUOqF_er1Kt6MMwdsk-FfO-3lUI0L-CcmPcDCy4Ko,2836
6
- instapost/media/__init__.py,sha256=rhLMklySKJzeL1cCvhYfX4x-n23NAhgIzDXUT-0Aav0,65
7
- instapost/media/uploader.py,sha256=cLbXUNau8EqtmnSj1xXOox4UuhHRnBo0fqlETWMcoMU,3384
8
- instapost/posting/__init__.py,sha256=Jedqh7qWBfGtE9AoVPV8dWzZoNZ6xbZbejxbpmUU4lI,156
9
- instapost/posting/carousel.py,sha256=2Rl_VQfKtW3s8HGsfsdNYtwpawOoWE8SUlQO5FwA3Ec,1789
10
- instapost/posting/image.py,sha256=RH5VUyDkeiO6twRLklnLbvPkS_TJSxLG-Dl19oulHX8,721
11
- instapost/posting/reel.py,sha256=-Uwbz2HoCmYzI-ZHJ97LPFMmmc4acnt0rRwgBH24RVU,1564
12
- instapost-0.2.0.dist-info/METADATA,sha256=BkI4-cwMW4fH4w3SJ97FLfGTvD1GSMud1O2vb9lE7s0,4199
13
- instapost-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- instapost-0.2.0.dist-info/licenses/LICENSE,sha256=dkJtwqp6h8qdcFKHbnKzGIMZx09yloEYxasC3rlSjP8,1071
15
- instapost-0.2.0.dist-info/RECORD,,