Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
Twint
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Twint
Commits
b94c64d8
Commit
b94c64d8
authored
Dec 19, 2019
by
Francesco Poldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned run.Feed, added check has_more_items
parent
48cef6e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
53 deletions
+60
-53
twint/run.py
twint/run.py
+60
-53
No files found.
twint/run.py
View file @
b94c64d8
...
@@ -21,6 +21,8 @@ class Twint:
...
@@ -21,6 +21,8 @@ class Twint:
self
.
feed
=
[
-
1
]
self
.
feed
=
[
-
1
]
self
.
count
=
0
self
.
count
=
0
self
.
consecutive_errors_count
=
0
self
.
has_more_items
=
True
self
.
user_agent
=
""
self
.
user_agent
=
""
self
.
config
=
config
self
.
config
=
config
self
.
conn
=
db
.
Conn
(
config
.
Database
)
self
.
conn
=
db
.
Conn
(
config
.
Database
)
...
@@ -44,64 +46,66 @@ class Twint:
...
@@ -44,64 +46,66 @@ class Twint:
async
def
Feed
(
self
):
async
def
Feed
(
self
):
logme
.
debug
(
__name__
+
':Twint:Feed'
)
logme
.
debug
(
__name__
+
':Twint:Feed'
)
consecutive_errors_count
=
0
while
True
:
response
=
await
get
.
RequestUrl
(
self
.
config
,
self
.
init
,
headers
=
[(
"User-Agent"
,
self
.
user_agent
)])
response
=
await
get
.
RequestUrl
(
self
.
config
,
self
.
init
,
headers
=
[(
"User-Agent"
,
self
.
user_agent
)])
if
self
.
config
.
Debug
:
print
(
response
,
file
=
open
(
"twint-last-request.log"
,
"w"
,
encoding
=
"utf-8"
))
if
self
.
config
.
Resume
:
if
self
.
config
.
Debug
:
print
(
self
.
init
,
file
=
open
(
self
.
config
.
Resume
,
"w"
,
encoding
=
"utf-8"
))
print
(
response
,
file
=
open
(
"twint-last-request.log"
,
"w"
,
encoding
=
"utf-8"
))
if
self
.
config
.
Resume
:
self
.
feed
=
[]
print
(
self
.
init
,
file
=
open
(
self
.
config
.
Resume
,
"w"
,
encoding
=
"utf-8"
))
try
:
if
self
.
config
.
Favorites
:
self
.
feed
=
[]
try
:
if
self
.
config
.
Favorites
:
self
.
feed
,
self
.
init
=
feed
.
Mobile
(
response
)
if
not
self
.
count
%
40
:
time
.
sleep
(
5
)
elif
self
.
config
.
Followers
or
self
.
config
.
Following
:
self
.
feed
,
self
.
init
=
feed
.
Follow
(
response
)
if
not
self
.
count
%
40
:
time
.
sleep
(
5
)
elif
self
.
config
.
Profile
:
if
self
.
config
.
Profile_full
:
self
.
feed
,
self
.
init
=
feed
.
Mobile
(
response
)
self
.
feed
,
self
.
init
=
feed
.
Mobile
(
response
)
if
not
self
.
count
%
40
:
time
.
sleep
(
5
)
elif
self
.
config
.
Followers
or
self
.
config
.
Following
:
self
.
feed
,
self
.
init
=
feed
.
Follow
(
response
)
if
not
self
.
count
%
40
:
time
.
sleep
(
5
)
elif
self
.
config
.
Profile
:
if
self
.
config
.
Profile_full
:
self
.
feed
,
self
.
init
=
feed
.
Mobile
(
response
)
else
:
self
.
feed
,
self
.
init
=
feed
.
profile
(
response
)
elif
self
.
config
.
TwitterSearch
:
self
.
feed
,
self
.
init
=
feed
.
Json
(
response
)
break
except
TimeoutError
as
e
:
if
self
.
config
.
Proxy_host
.
lower
()
==
"tor"
:
print
(
"[?] Timed out, changing Tor identity..."
)
if
self
.
config
.
Tor_control_password
is
None
:
logme
.
critical
(
__name__
+
':Twint:Feed:tor-password'
)
sys
.
stderr
.
write
(
"Error: config.Tor_control_password must be set for proxy autorotation!
\r\n
"
)
sys
.
stderr
.
write
(
"Info: What is it? See https://stem.torproject.org/faq.html#can-i-interact-with-tors-controller-interface-directly
\r\n
"
)
break
else
:
get
.
ForceNewTorIdentity
(
self
.
config
)
continue
else
:
else
:
logme
.
critical
(
__name__
+
':Twint:Feed:'
+
str
(
e
))
self
.
feed
,
self
.
init
=
feed
.
profile
(
response
)
print
(
str
(
e
))
elif
self
.
config
.
TwitterSearch
:
break
self
.
feed
,
self
.
init
,
_has_more_items
=
feed
.
Json
(
response
)
except
Exception
as
e
:
if
(
not
self
.
feed
)
and
self
.
has_more_items
:
if
self
.
config
.
Profile
or
self
.
config
.
Favorites
:
await
self
.
Feed
()
print
(
"[!] Twitter does not return more data, scrape stops here."
)
self
.
has_more_items
=
_has_more_items
break
return
logme
.
critical
(
__name__
+
':Twint:Feed:noData'
+
str
(
e
))
except
TimeoutError
as
e
:
# Sometimes Twitter says there is no data. But it's a lie.
if
self
.
config
.
Proxy_host
.
lower
()
==
"tor"
:
consecutive_errors_count
+=
1
print
(
"[?] Timed out, changing Tor identity..."
)
if
consecutive_errors_count
<
self
.
config
.
Retries_count
:
if
self
.
config
.
Tor_control_password
is
None
:
self
.
user_agent
=
await
get
.
RandomUserAgent
()
logme
.
critical
(
__name__
+
':Twint:Feed:tor-password'
)
continue
sys
.
stderr
.
write
(
"Error: config.Tor_control_password must be set for proxy autorotation!
\r\n
"
)
logme
.
critical
(
__name__
+
':Twint:Feed:Tweets_known_error:'
+
str
(
e
))
sys
.
stderr
.
write
(
"Info: What is it? See https://stem.torproject.org/faq.html#can-i-interact-with-tors-controller-interface-directly
\r\n
"
)
print
(
str
(
e
)
+
" [x] run.Feed"
)
exit
(
1
)
print
(
"[!] if get this error but you know for sure that more tweets exist, please open an issue and we will investigate it!"
)
else
:
break
get
.
ForceNewTorIdentity
(
self
.
config
)
await
self
.
Feed
()
else
:
logme
.
critical
(
__name__
+
':Twint:Feed:'
+
str
(
e
))
exit
(
str
(
e
))
except
Exception
as
e
:
if
self
.
config
.
Profile
or
self
.
config
.
Favorites
:
exit
(
"[!] Twitter does not return more data, scrape stops here."
)
logme
.
critical
(
__name__
+
':Twint:Feed:noData'
+
str
(
e
))
# Sometimes Twitter says there is no data. But it's a lie.
self
.
consecutive_errors_count
+=
1
if
self
.
consecutive_errors_count
<
self
.
config
.
Retries_count
:
self
.
user_agent
=
await
get
.
RandomUserAgent
()
time
.
sleep
(
5
)
await
self
.
Feed
()
logme
.
critical
(
__name__
+
':Twint:Feed:Tweets_known_error:'
+
str
(
e
))
exit
(
str
(
e
)
+
" [x] run.Feed
\n
"
+
"[!] if get this error but you know for sure that more tweets exist, please open an issue and we will investigate it!"
)
async
def
follow
(
self
):
async
def
follow
(
self
):
self
.
consecutive_errors_count
=
0
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
User_full
:
if
self
.
config
.
User_full
:
logme
.
debug
(
__name__
+
':Twint:follow:userFull'
)
logme
.
debug
(
__name__
+
':Twint:follow:userFull'
)
...
@@ -114,11 +118,13 @@ class Twint:
...
@@ -114,11 +118,13 @@ class Twint:
await
output
.
Username
(
username
,
self
.
config
,
self
.
conn
)
await
output
.
Username
(
username
,
self
.
config
,
self
.
conn
)
async
def
favorite
(
self
):
async
def
favorite
(
self
):
self
.
consecutive_errors_count
=
0
logme
.
debug
(
__name__
+
':Twint:favorite'
)
logme
.
debug
(
__name__
+
':Twint:favorite'
)
await
self
.
Feed
()
await
self
.
Feed
()
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
async
def
profile
(
self
):
async
def
profile
(
self
):
self
.
consecutive_errors_count
=
0
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
Profile_full
:
if
self
.
config
.
Profile_full
:
logme
.
debug
(
__name__
+
':Twint:profileFull'
)
logme
.
debug
(
__name__
+
':Twint:profileFull'
)
...
@@ -130,6 +136,7 @@ class Twint:
...
@@ -130,6 +136,7 @@ class Twint:
await
output
.
Tweets
(
tweet
,
self
.
config
,
self
.
conn
)
await
output
.
Tweets
(
tweet
,
self
.
config
,
self
.
conn
)
async
def
tweets
(
self
):
async
def
tweets
(
self
):
self
.
consecutive_errors_count
=
0
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
Location
:
if
self
.
config
.
Location
:
logme
.
debug
(
__name__
+
':Twint:tweets:location'
)
logme
.
debug
(
__name__
+
':Twint:tweets:location'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment