зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-29 21:16:25 +02:00
fix: tweet_details crash when tweet not found (now is None)
Этот коммит содержится в:
родитель
18a3e3b3e0
Коммит
c35dcb902c
@ -186,7 +186,7 @@ The default output is in the console (stdout), one document per line. So it can
|
|||||||
twscrape search "elon mask lang:es" --limit=20 > data.txt
|
twscrape search "elon mask lang:es" --limit=20 > data.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
By default, parsed data is returned. The original tweet responses can be retrieved with `--raw`
|
By default, parsed data is returned. The original tweet responses can be retrieved with `--raw` flag.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
twscrape search "elon mask lang:es" --limit=20 --raw
|
twscrape search "elon mask lang:es" --limit=20 --raw
|
||||||
@ -194,7 +194,7 @@ twscrape search "elon mask lang:es" --limit=20 --raw
|
|||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
NOTE: After 1 July 2023 Twitter [introduced limits](https://twitter.com/elonmusk/status/1675187969420828672) on the number of tweets per day per account (and these continue to change), so the values below may not be fully correct.
|
**NOTE:** After 1 July 2023 Twitter [introduced limits](https://twitter.com/elonmusk/status/1675187969420828672) on the number of tweets per day per account, so the values below may not be fully correct.
|
||||||
|
|
||||||
API rate limits (per account):
|
API rate limits (per account):
|
||||||
- Search API – 250 req / 15 min
|
- Search API – 250 req / 15 min
|
||||||
|
|||||||
@ -152,7 +152,8 @@ class API:
|
|||||||
async def tweet_details(self, twid: int, kv=None):
|
async def tweet_details(self, twid: int, kv=None):
|
||||||
rep = await self.tweet_details_raw(twid, kv=kv)
|
rep = await self.tweet_details_raw(twid, kv=kv)
|
||||||
obj = to_old_rep(rep.json())
|
obj = to_old_rep(rep.json())
|
||||||
return Tweet.parse(obj["tweets"][str(twid)], obj)
|
doc = obj["tweets"].get(str(twid), None)
|
||||||
|
return Tweet.parse(doc, obj) if doc else None
|
||||||
|
|
||||||
# followers
|
# followers
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,10 @@ def get_fn_arg(args):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def to_str(doc: httpx.Response | Tweet | User) -> str:
|
def to_str(doc: httpx.Response | Tweet | User | None) -> str:
|
||||||
|
if doc is None:
|
||||||
|
return "Not Found. See --raw for more details."
|
||||||
|
|
||||||
tmp = doc.json()
|
tmp = doc.json()
|
||||||
return tmp if isinstance(tmp, str) else json.dumps(tmp, default=str)
|
return tmp if isinstance(tmp, str) else json.dumps(tmp, default=str)
|
||||||
|
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user