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
67daa0c1
Commit
67daa0c1
authored
Sep 28, 2018
by
Francesco Poldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update
parent
773e5c68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
25 deletions
+30
-25
twint/get.py
twint/get.py
+7
-3
twint/output.py
twint/output.py
+3
-4
twint/run.py
twint/run.py
+20
-18
No files found.
twint/get.py
View file @
67daa0c1
...
@@ -112,7 +112,7 @@ async def Tweet(url, config, conn):
...
@@ -112,7 +112,7 @@ async def Tweet(url, config, conn):
location
=
location
[
15
:]
.
replace
(
"
\n
"
,
" "
)[:
-
10
]
location
=
location
[
15
:]
.
replace
(
"
\n
"
,
" "
)[:
-
10
]
await
Tweets
(
tweet
,
location
,
config
,
conn
)
await
Tweets
(
tweet
,
location
,
config
,
conn
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
str
(
e
)
+
" [x] get.Tweet"
)
async
def
User
(
url
,
config
,
conn
):
async
def
User
(
url
,
config
,
conn
):
#loggin.info("[<] " + str(datetime.now()) + ':: get+User')
#loggin.info("[<] " + str(datetime.now()) + ':: get+User')
...
@@ -121,7 +121,7 @@ async def User(url, config, conn):
...
@@ -121,7 +121,7 @@ async def User(url, config, conn):
soup
=
BeautifulSoup
(
response
,
"html.parser"
)
soup
=
BeautifulSoup
(
response
,
"html.parser"
)
await
Users
(
soup
,
config
,
conn
)
await
Users
(
soup
,
config
,
conn
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
str
(
e
)
+
" [x] get.User"
)
def
Limit
(
Limit
,
count
):
def
Limit
(
Limit
,
count
):
#loggin.info("[<] " + str(datetime.now()) + ':: get+Limit')
#loggin.info("[<] " + str(datetime.now()) + ':: get+Limit')
...
@@ -156,6 +156,10 @@ async def Multi(feed, config, conn):
...
@@ -156,6 +156,10 @@ async def Multi(feed, config, conn):
await
asyncio
.
gather
(
*
futures
)
await
asyncio
.
gather
(
*
futures
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
# TODO: fix error not error
# print(str(e) + " [x] get.Multi")
# will return "'NoneType' object is not callable"
# but still works
pass
return
count
return
count
twint/output.py
View file @
67daa0c1
...
@@ -40,10 +40,9 @@ def _output(obj, output, config, **extra):
...
@@ -40,10 +40,9 @@ def _output(obj, output, config, **extra):
if
config
.
Lowercase
:
if
config
.
Lowercase
:
if
isinstance
(
obj
,
str
):
if
isinstance
(
obj
,
str
):
obj
=
obj
.
lower
()
obj
=
obj
.
lower
()
elif
str
(
type
(
obj
))
.
split
()[
0
]
==
"<class
"
:
elif
str
(
type
(
obj
))
==
"<class 'twint.user.user'>
"
:
pass
pass
else
:
else
:
print
(
type
(
obj
))
obj
.
username
=
obj
.
username
.
lower
()
obj
.
username
=
obj
.
username
.
lower
()
for
i
in
range
(
len
(
obj
.
mentions
)):
for
i
in
range
(
len
(
obj
.
mentions
)):
obj
.
mentions
[
i
]
=
obj
.
mentions
[
i
]
.
lower
()
obj
.
mentions
[
i
]
=
obj
.
mentions
[
i
]
.
lower
()
...
@@ -54,7 +53,7 @@ def _output(obj, output, config, **extra):
...
@@ -54,7 +53,7 @@ def _output(obj, output, config, **extra):
try
:
try
:
write
.
Csv
(
obj
,
config
)
write
.
Csv
(
obj
,
config
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Error: "
+
str
(
e
)
)
print
(
str
(
e
)
+
" [x] output._output"
)
elif
config
.
Store_json
:
elif
config
.
Store_json
:
write
.
Json
(
obj
,
config
)
write
.
Json
(
obj
,
config
)
else
:
else
:
...
@@ -77,7 +76,7 @@ def _output(obj, output, config, **extra):
...
@@ -77,7 +76,7 @@ def _output(obj, output, config, **extra):
print
(
output
)
print
(
output
)
pass
pass
except
UnicodeEncodeError
:
except
UnicodeEncodeError
:
print
(
"unicode error"
)
print
(
"unicode error
[x] output._output
"
)
async
def
Tweets
(
tw
,
location
,
config
,
conn
):
async
def
Tweets
(
tw
,
location
,
config
,
conn
):
#logging.info("[<] " + str(datetime.now()) + ':: output+Tweets')
#logging.info("[<] " + str(datetime.now()) + ':: output+Tweets')
...
...
twint/run.py
View file @
67daa0c1
...
@@ -7,7 +7,7 @@ from .storage import db
...
@@ -7,7 +7,7 @@ from .storage import db
class
Twint
:
class
Twint
:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+__init__')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+__init__')
if
config
.
Resume
is
not
None
and
config
.
TwitterSearch
:
if
config
.
Resume
is
not
None
and
config
.
TwitterSearch
:
self
.
init
=
f
"TWEET-{config.Resume}-0"
self
.
init
=
f
"TWEET-{config.Resume}-0"
else
:
else
:
...
@@ -32,7 +32,7 @@ class Twint:
...
@@ -32,7 +32,7 @@ class Twint:
self
.
config
.
Timedelta
=
(
self
.
d
.
_until
-
self
.
d
.
_since
)
.
days
self
.
config
.
Timedelta
=
(
self
.
d
.
_until
-
self
.
d
.
_since
)
.
days
async
def
Feed
(
self
):
async
def
Feed
(
self
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+Feed')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+Feed')
response
=
await
get
.
RequestUrl
(
self
.
config
,
self
.
init
)
response
=
await
get
.
RequestUrl
(
self
.
config
,
self
.
init
)
if
self
.
config
.
Debug
:
if
self
.
config
.
Debug
:
print
(
response
,
file
=
open
(
"twint-last-request.log"
,
"w"
,
encoding
=
"utf-8"
))
print
(
response
,
file
=
open
(
"twint-last-request.log"
,
"w"
,
encoding
=
"utf-8"
))
...
@@ -51,10 +51,10 @@ class Twint:
...
@@ -51,10 +51,10 @@ class Twint:
elif
self
.
config
.
TwitterSearch
:
elif
self
.
config
.
TwitterSearch
:
self
.
feed
,
self
.
init
=
feed
.
Json
(
response
)
self
.
feed
,
self
.
init
=
feed
.
Json
(
response
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
str
(
e
)
+
" [x] run.Feed"
)
async
def
follow
(
self
):
async
def
follow
(
self
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+follow')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+follow')
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
User_full
:
if
self
.
config
.
User_full
:
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
...
@@ -65,12 +65,12 @@ class Twint:
...
@@ -65,12 +65,12 @@ 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
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+favorite')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+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
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+profile')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+profile')
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
Profile_full
:
if
self
.
config
.
Profile_full
:
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
...
@@ -80,7 +80,7 @@ class Twint:
...
@@ -80,7 +80,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
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+tweets')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+tweets')
await
self
.
Feed
()
await
self
.
Feed
()
if
self
.
config
.
Location
:
if
self
.
config
.
Location
:
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
self
.
count
+=
await
get
.
Multi
(
self
.
feed
,
self
.
config
,
self
.
conn
)
...
@@ -90,7 +90,7 @@ class Twint:
...
@@ -90,7 +90,7 @@ class Twint:
await
output
.
Tweets
(
tweet
,
""
,
self
.
config
,
self
.
conn
)
await
output
.
Tweets
(
tweet
,
""
,
self
.
config
,
self
.
conn
)
async
def
main
(
self
):
async
def
main
(
self
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+main')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+main')
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
.
User_id
)
...
@@ -105,7 +105,7 @@ class Twint:
...
@@ -105,7 +105,7 @@ class Twint:
self
.
d
.
_until
=
self
.
d
.
_until
-
_days
self
.
d
.
_until
=
self
.
d
.
_until
-
_days
self
.
feed
=
[
-
1
]
self
.
feed
=
[
-
1
]
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+main+CallingGetLimit1')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+main+CallingGetLimit1')
if
get
.
Limit
(
self
.
config
.
Limit
,
self
.
count
):
if
get
.
Limit
(
self
.
config
.
Limit
,
self
.
count
):
self
.
d
.
_until
=
self
.
d
.
_until
-
_days
self
.
d
.
_until
=
self
.
d
.
_until
-
_days
self
.
feed
=
[
-
1
]
self
.
feed
=
[
-
1
]
...
@@ -123,7 +123,7 @@ class Twint:
...
@@ -123,7 +123,7 @@ class Twint:
else
:
else
:
break
break
#loggin.info("[<] " + str(datetime.now()) + ':: run+Twint+main+CallingGetLimit2')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Twint+main+CallingGetLimit2')
if
get
.
Limit
(
self
.
config
.
Limit
,
self
.
count
):
if
get
.
Limit
(
self
.
config
.
Limit
,
self
.
count
):
break
break
...
@@ -131,16 +131,16 @@ class Twint:
...
@@ -131,16 +131,16 @@ class Twint:
verbose
.
Count
(
self
.
count
,
self
.
config
)
verbose
.
Count
(
self
.
count
,
self
.
config
)
def
run
(
config
):
def
run
(
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+run')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+run')
get_event_loop
()
.
run_until_complete
(
Twint
(
config
)
.
main
())
get_event_loop
()
.
run_until_complete
(
Twint
(
config
)
.
main
())
def
Favorites
(
config
):
def
Favorites
(
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Favorites')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Favorites')
config
.
Favorites
=
True
config
.
Favorites
=
True
run
(
config
)
run
(
config
)
def
Followers
(
config
):
def
Followers
(
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Followers')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Followers')
output
.
clean_follow_list
()
output
.
clean_follow_list
()
config
.
Followers
=
True
config
.
Followers
=
True
config
.
Following
=
False
config
.
Following
=
False
...
@@ -149,10 +149,11 @@ def Followers(config):
...
@@ -149,10 +149,11 @@ def Followers(config):
storage
.
panda
.
_autoget
(
"followers"
)
storage
.
panda
.
_autoget
(
"followers"
)
if
config
.
User_full
:
if
config
.
User_full
:
storage
.
panda
.
_autoget
(
"user"
)
storage
.
panda
.
_autoget
(
"user"
)
storage
.
panda
.
clean
()
if
config
.
Pandas
:
storage
.
panda
.
clean
()
def
Following
(
config
):
def
Following
(
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Following')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Following')
output
.
clean_follow_list
()
output
.
clean_follow_list
()
config
.
Following
=
True
config
.
Following
=
True
config
.
Followers
=
False
config
.
Followers
=
False
...
@@ -161,15 +162,16 @@ def Following(config):
...
@@ -161,15 +162,16 @@ def Following(config):
storage
.
panda
.
_autoget
(
"following"
)
storage
.
panda
.
_autoget
(
"following"
)
if
config
.
User_full
:
if
config
.
User_full
:
storage
.
panda
.
_autoget
(
"user"
)
storage
.
panda
.
_autoget
(
"user"
)
storage
.
panda
.
clean
()
if
config
.
Pandas
:
storage
.
panda
.
clean
()
def
Profile
(
config
):
def
Profile
(
config
):
config
.
Profile
=
True
config
.
Profile
=
True
#loggin.info("[<] " + str(datetime.now()) + ':: run+Profile')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Profile')
run
(
config
)
run
(
config
)
def
Search
(
config
):
def
Search
(
config
):
#loggin.info("[<] " + str(datetime.now()) + ':: run+Search')
#loggin
g
.info("[<] " + str(datetime.now()) + ':: run+Search')
config
.
TwitterSearch
=
True
config
.
TwitterSearch
=
True
config
.
Following
=
False
config
.
Following
=
False
config
.
Followers
=
False
config
.
Followers
=
False
...
...
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