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
8ff31b14
Commit
8ff31b14
authored
May 26, 2018
by
Cody Zacharias
Committed by
GitHub
May 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update search.py
parent
e51c6c78
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
91 deletions
+79
-91
twint/search.py
twint/search.py
+79
-91
No files found.
twint/search.py
View file @
8ff31b14
from
.
import
datelock
,
db
,
get
,
feed
,
output
from
.
import
datelock
,
db
,
get
,
feed
,
output
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
import
aiohttp
import
asyncio
import
asyncio
import
concurrent.futures
import
concurrent.futures
import
datetime
import
datetime
...
@@ -10,17 +9,16 @@ import sys
...
@@ -10,17 +9,16 @@ import sys
class
Search
:
class
Search
:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
init
=
-
1
self
.
init
=
-
1
self
.
initial
=
-
1
self
.
feed
=
[
-
1
]
self
.
feed
=
[
-
1
]
self
.
count
=
0
self
.
count
=
0
self
.
config
=
config
self
.
config
=
config
self
.
d
=
datelock
.
Set
(
self
.
config
)
self
.
d
=
datelock
.
Set
(
self
.
config
)
if
self
.
config
.
Elasticsearch
:
if
self
.
config
.
Elasticsearch
:
print
(
"
Indexing to Elasticsearch @ "
+
str
(
self
.
config
.
Elasticsearch
))
print
(
"[+]
Indexing to Elasticsearch @ "
+
str
(
self
.
config
.
Elasticsearch
))
if
self
.
config
.
Database
:
if
self
.
config
.
Database
:
print
(
"
Inserting into Database: "
+
str
(
self
.
config
.
Database
))
print
(
"[+]
Inserting into Database: "
+
str
(
self
.
config
.
Database
))
self
.
conn
=
db
.
init
(
self
.
config
.
Database
)
self
.
conn
=
db
.
init
(
self
.
config
.
Database
)
if
isinstance
(
self
.
conn
,
str
):
if
isinstance
(
self
.
conn
,
str
):
print
(
str
)
print
(
str
)
...
@@ -38,25 +36,16 @@ class Search:
...
@@ -38,25 +36,16 @@ class Search:
loop
.
run_until_complete
(
self
.
main
())
loop
.
run_until_complete
(
self
.
main
())
async
def
Feed
(
self
):
async
def
Feed
(
self
):
connect
=
aiohttp
.
TCPConnector
(
verify_ssl
=
False
)
url
=
await
get
.
Url
(
self
.
config
,
self
.
init
)
.
search
()
if
self
.
init
==
-
1
:
response
=
await
get
.
Request
(
self
.
config
,
url
)
ua
=
{
'User-Agent'
:
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'
}
else
:
ua
=
""
async
with
aiohttp
.
ClientSession
(
headers
=
ua
,
connector
=
connect
)
as
session
:
response
=
await
get
.
Response
(
session
,
await
get
.
Url
(
self
.
config
,
self
.
init
)
.
search
())
self
.
feed
=
[]
self
.
feed
=
[]
try
:
try
:
if
self
.
init
==
-
1
:
self
.
feed
,
self
.
init
=
feed
.
Json
(
response
)
self
.
feed
,
self
.
init
=
feed
.
Initial
(
response
)
else
:
self
.
feed
,
self
.
init
=
feed
.
Cont
(
response
)
except
:
except
:
pass
pass
async
def
tweets
(
self
):
async
def
tweets
(
self
):
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
initial
!=
-
1
:
# Temporary fix
if
self
.
config
.
Location
:
if
self
.
config
.
Location
:
try
:
try
:
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
20
)
as
executor
:
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
20
)
as
executor
:
...
@@ -66,8 +55,8 @@ class Search:
...
@@ -66,8 +55,8 @@ class Search:
self
.
count
+=
1
self
.
count
+=
1
link
=
tweet
.
find
(
"a"
,
"tweet-timestamp js-permalink js-nav js-tooltip"
)[
"href"
]
link
=
tweet
.
find
(
"a"
,
"tweet-timestamp js-permalink js-nav js-tooltip"
)[
"href"
]
url
=
"https://twitter.com{}"
.
format
(
link
)
url
=
"https://twitter.com{}"
.
format
(
link
)
futures
.
append
(
loop
.
run_in_executor
(
executor
,
await
get
.
Tweet
(
url
,
self
.
config
,
self
.
conn
)))
futures
.
append
(
loop
.
run_in_executor
(
executor
,
await
get
.
Tweet
(
url
,
self
.
config
,
self
.
conn
)))
await
asyncio
.
gather
(
*
futures
)
await
asyncio
.
gather
(
*
futures
)
except
:
except
:
pass
pass
...
@@ -75,12 +64,11 @@ class Search:
...
@@ -75,12 +64,11 @@ class Search:
for
tweet
in
self
.
feed
:
for
tweet
in
self
.
feed
:
self
.
count
+=
1
self
.
count
+=
1
await
output
.
Tweets
(
tweet
,
""
,
self
.
config
,
self
.
conn
)
await
output
.
Tweets
(
tweet
,
""
,
self
.
config
,
self
.
conn
)
else
:
self
.
initial
=
0
async
def
main
(
self
):
async
def
main
(
self
):
if
self
.
config
.
User_id
is
not
None
:
if
self
.
config
.
User_id
is
not
None
:
self
.
config
.
Username
=
await
get
.
Username
(
self
.
config
.
User_id
)
self
.
config
.
Username
=
await
get
.
Username
(
self
.
config
)
if
self
.
config
.
Since
and
self
.
config
.
Until
:
if
self
.
config
.
Since
and
self
.
config
.
Until
:
while
self
.
d
.
_since
<
self
.
d
.
_until
:
while
self
.
d
.
_since
<
self
.
d
.
_until
:
self
.
config
.
Since
=
str
(
self
.
d
.
_until
-
datetime
.
timedelta
(
days
=
int
(
self
.
config
.
Timedelta
)))
self
.
config
.
Since
=
str
(
self
.
d
.
_until
-
datetime
.
timedelta
(
days
=
int
(
self
.
config
.
Timedelta
)))
...
...
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