Skip to content

Commit 95dde62

Browse files
authored
v0.0.6
fixed instagram story updater
2 parents b511db0 + 525a76e commit 95dde62

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/build/
55
/dist/
66
/my_feed.egg-info/
7+
/my_feed/VERSION
78

89
examples/config.cfg
910
examples/img/

my_feed/modules/post.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@
44

55
class MediaModel:
66

7-
def __init__(self, media_id, url):
7+
def __init__(self, media_id, url, media_type):
88
self.id = media_id
99
self.url: str = url
10+
self.type: PostType = media_type
11+
12+
@property
13+
def is_image(self) -> bool:
14+
if self.type == PostType.IMAGE:
15+
return True
16+
return False
17+
18+
@property
19+
def is_video(self) -> bool:
20+
if self.type == PostType.VIDEO:
21+
return True
22+
return False
1023

1124

1225
class PostModel:
@@ -23,11 +36,11 @@ def __init__(self, post_id, title, created_at, url):
2336
def __repr__(self):
2437
return f'{self.url}'
2538

26-
def add_media(self, media_id, media_url) -> None:
39+
def add_media(self, media_id, media_url, media_type=PostType.NONE) -> None:
2740
"""
2841
Append a new media to the Post
2942
"""
30-
self.media.append(MediaModel(media_id, media_url))
43+
self.media.append(MediaModel(media_id, media_url, media_type))
3144

3245
@property
3346
def is_text(self) -> bool:
@@ -53,6 +66,12 @@ def is_video(self) -> bool:
5366
return True
5467
return False
5568

69+
@property
70+
def is_story(self) -> bool:
71+
if self.media and self.type == PostType.STORY:
72+
return True
73+
return False
74+
5675
@property
5776
def is_none(self) -> bool:
5877
if self.type == PostType.NONE:

my_feed/modules/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class PostType(Enum):
99
IMAGE = 'Image'
1010
VIDEO = 'Video'
1111
TEXT = 'Text'
12+
STORY = 'Story'
1213
NONE = None
1314

1415
@staticmethod

my_feed/platforms/instagram/__init__.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def get_media_url(media_data):
3131
media = media_data.get('standard_resolution', {})
3232
return media.get('url')
3333

34+
@staticmethod
35+
def build_story_url(reel):
36+
return f'https://www.instagram.com/stories/{reel.get("user", {}).get("username", "no")}/{reel.get("pk")}/'
37+
3438
def story(self, user_id, last_update_id) -> [PostModel]:
3539
"""
3640
story can be get only if you are logged in
@@ -46,25 +50,39 @@ def story(self, user_id, last_update_id) -> [PostModel]:
4650
return []
4751

4852
reels = reels.get('items')
53+
# reals are showed older first then reverse them
54+
# to check the newers id first
55+
reels.reverse()
56+
latest_reel = reels[0]
57+
58+
# generate a single post with all the reels inside
59+
post = PostModel(
60+
post_id=latest_reel.get('id'),
61+
title='',
62+
created_at=latest_reel.get('taken_at'),
63+
url=self.build_story_url(latest_reel)
64+
)
65+
post.type = PostType.STORY
66+
4967
for reel in reels:
5068

51-
post_id = reel.get('pk')
69+
post_id = reel.get('id')
5270
if post_id == last_update_id:
5371
break
5472

55-
post = PostModel(
56-
post_id=post_id,
57-
title='',
58-
created_at=reel.get('taken_at'),
59-
url=reel.get('link')
60-
)
61-
6273
media_type = MediaType(reel.get('type'))
63-
post.type = PostType.VIDEO if media_type == MediaType.video else PostType.IMAGE
6474
media = reel.get('videos' if media_type == MediaType.video else 'images')
65-
post.add_media(media_id=None, media_url=self.get_media_url(media))
75+
post.add_media(
76+
media_id=None,
77+
media_url=self.get_media_url(media),
78+
media_type=PostType.VIDEO if media_type == MediaType.video else PostType.IMAGE
79+
)
6680

67-
out.append(post)
81+
if not post.media:
82+
return []
83+
# reals are showed older first then reverse them
84+
post.media.reverse()
85+
out.append(post)
6886

6987
return out
7088

0 commit comments

Comments
 (0)