Open successor1 opened 3 years ago
@successor1 try adding labels like: Username {username} | Tweet {tweet}
The docs for this are here: https://github.com/twintproject/twint/wiki/Tweet-attributes
I'm also running into the same issue when trying to format output. It seems that the problem happens here: https://github.com/twintproject/twint/blob/e7c8a0c764f6879188e5c21e25fb6f1f856a7221/twint/format.py#L23
Python's replace
function requires its arguments to be strings, and doesn't automatically coerce other types, opting to throw a TypeError
instead. Seems like an easy solution would be to go through and wrap all replacement values in str()
.
edit: In fact, it seems like there are multiple open PRs doing exactly that (#1179, #1213, #1221, maybe more that I missed). I do have to question whether this project has been abandoned.
Thought that I would leave this here. This is what fixed the issue for me
output = output.replace("{replies}", str(t.replies_count))
output = output.replace("{retweets}", str(t.retweets_count))
output = output.replace("{likes}", str(t.likes_count))
output = output.replace("{mentions}", ",".join(str(t.mentions)))
Since it looks like this isn't being fixed any time soon, I made a fork to fix it until they do. (if they ever decide to) https://github.com/cyxv/twint
Initial Check
pip3 install --user --upgrade -e git+https://github.com/twintproject/twint.git@origin/master#egg=twint
; checkCommand Ran
python twitter.py
code:
import twint
c = twint.Config() c.Search = "data science" c.Format = '{username} | {tweet}' c.Limit = 1 c.Pandas = True
twint.run.Search(c)
output: (venv) C:\Users\31622\Documents\test>python twitter.py Traceback (most recent call last): File "twitter.py", line 9, in
twint.run.Search(c)
File "c:\users\31622\documents\test\venv\src\twint\twint\run.py", line 410, in Search
run(config, callback)
File "c:\users\31622\documents\test\venv\src\twint\twint\run.py", line 329, in run
get_event_loop().run_until_complete(Twint(config).main(callback))
File "c:\users\31622\appdata\local\programs\python\python36\lib\asyncio\base_events.py", line 466, in run_until_complete
return future.result()
File "c:\users\31622\documents\test\venv\src\twint\twint\run.py", line 235, in main
await task
File "c:\users\31622\documents\test\venv\src\twint\twint\run.py", line 286, in run
await self.tweets()
File "c:\users\31622\documents\test\venv\src\twint\twint\run.py", line 226, in tweets
await output.Tweets(tweet, self.config, self.conn)
File "c:\users\31622\documents\test\venv\src\twint\twint\output.py", line 166, in Tweets
await checkData(tweets, config, conn)
File "c:\users\31622\documents\test\venv\src\twint\twint\output.py", line 137, in checkData
output = format.Tweet(config, tweet)
File "c:\users\31622\documents\test\venv\src\twint\twint\format.py", line 23, in Tweet
output = output.replace("{replies}", t.replies_count)
TypeError: replace() argument 2 must be str, not int
Description of Issue
c.Format gives the error, without c.Format it does work normally.
Environment Details
Windows, visual studio code, in virtual environment, python 3.6.0