-
Notifications
You must be signed in to change notification settings - Fork 129
/
helpers.py
63 lines (47 loc) · 2.16 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import tempfile
import os
from instagrapi.story import StoryBuilder
async def photo_upload_story_as_video(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.jpg') as fp:
fp.write(content)
mentions = kwargs.get('mentions') or []
caption = kwargs.get('caption') or ''
video = StoryBuilder(fp.name, caption, mentions).photo(15)
return cl.video_upload_to_story(video.path, **kwargs)
async def photo_upload_story_as_photo(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.jpg') as fp:
fp.write(content)
return cl.photo_upload_to_story(fp.name, **kwargs)
async def video_upload_story(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.mp4') as fp:
fp.write(content)
mentions = kwargs.get('mentions') or []
caption = kwargs.get('caption') or ''
video = StoryBuilder(fp.name, caption, mentions).video(15)
return cl.video_upload_to_story(video.path, **kwargs)
async def photo_upload_post(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.jpg') as fp:
fp.write(content)
return cl.photo_upload(fp.name, **kwargs)
async def video_upload_post(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.mp4') as fp:
fp.write(content)
return cl.video_upload(fp.name, **kwargs)
async def album_upload_post(cl, files, **kwargs):
with tempfile.TemporaryDirectory() as td:
paths = []
for i in range(len(files)):
filename, ext = os.path.splitext(files[i].filename)
fp = tempfile.NamedTemporaryFile(suffix=ext, delete=False, dir=td)
fp.write(await files[i].read())
fp.close()
paths.append(fp.name)
return cl.album_upload(paths, **kwargs)
async def igtv_upload_post(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.mp4') as fp:
fp.write(content)
return cl.igtv_upload(fp.name, **kwargs)
async def clip_upload_post(cl, content, **kwargs):
with tempfile.NamedTemporaryFile(suffix='.mp4') as fp:
fp.write(content)
return cl.clip_upload(fp.name, **kwargs)