Skip to content

Commit

Permalink
add new batched endpoint TweetResultsByRestIds - fix download fn
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorhobenshield committed Dec 8, 2023
1 parent 1ae2856 commit 696cfa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion twitter/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "twitter-api-client"
__description__ = "Implementation of X/Twitter v1, v2, and GraphQL APIs."
__version__ = "0.10.13"
__version__ = "0.10.14"
__author__ = "Trevor Hobenshield"
__license__ = "MIT"
8 changes: 4 additions & 4 deletions twitter/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def users_by_id(self, user_ids: list[int], **kwargs) -> list[dict]:
"""
return self._run(Operation.UserByRestId, user_ids, **kwargs)

def download_media(self, ids: list[int], photos: bool = True, videos: bool = True, chunk_size: int = 8192, stream: bool = False) -> None:
def download_media(self, ids: list[int], photos: bool = True, videos: bool = True, chunk_size: int = 8192, stream: bool = False, out: str = 'media') -> None:
"""
Download media from tweets by tweet ids.
Expand All @@ -249,9 +249,9 @@ def download_media(self, ids: list[int], photos: bool = True, videos: bool = Tru
@params stream: flag to enable downloading raw stream
@return: None
"""
out = Path('media')
out = Path(out)
out.mkdir(parents=True, exist_ok=True)
tweets = self.tweets_by_id(ids)
tweets = self.tweets_by_id(ids) # todo: switch to batch method tweets_by_ids
urls = []
for tweet in tweets:
tweet_id = find_key(tweet, 'id_str')[0]
Expand Down Expand Up @@ -285,7 +285,7 @@ async def download(client: AsyncClient, post_url: str, cdn_url: str, stream: boo
else:
r = await client.get(cdn_url)
async with aiofiles.open(fname, 'wb') as fp:
for chunk in r.iter_bytes(chunk_size):
async for chunk in r.aiter_raw(chunk_size):
await fp.write(chunk)

except Exception as e:
Expand Down

0 comments on commit 696cfa4

Please sign in to comment.