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
63600485
Commit
63600485
authored
May 26, 2018
by
Cody Zacharias
Committed by
GitHub
May 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update spacing / Add values
parent
bbe48859
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
101 deletions
+108
-101
twint/db.py
twint/db.py
+108
-101
No files found.
twint/db.py
View file @
63600485
...
...
@@ -2,110 +2,117 @@ import datetime
import
sqlite3
def
init
(
db
):
try
:
conn
=
sqlite3
.
connect
(
db
)
cursor
=
conn
.
cursor
()
table_tweets
=
"""
CREATE TABLE IF NOT EXISTS
tweets (
id integer primary key,
user_id integer,
date text not null,
time text not null,
timezone text not null,
location text not null,
user text not null,
tweet text not null,
replies integer,
likes integer,
retweets integer,
hashtags text,
link text
);
"""
cursor
.
execute
(
table_tweets
)
table_users
=
"""
CREATE TABLE IF NOT EXISTS
users (
user text,
date_update text not null,
num_tweets integer,
PRIMARY KEY (user, date_update)
);
"""
cursor
.
execute
(
table_users
)
table_search
=
"""
CREATE TABLE IF NOT EXISTS
searches (
user text,
date_update text not null,
num_tweets integer,
search_keyword text,
PRIMARY KEY (user, date_update, search_keyword)
);
"""
cursor
.
execute
(
table_search
)
table_followers
=
"""
CREATE TABLE IF NOT EXISTS
followers (
user text not null,
date_update text not null,
follower text not null,
PRIMARY KEY (user, follower)
);
"""
cursor
.
execute
(
table_followers
)
table_following
=
"""
CREATE TABLE IF NOT EXISTS
following (
user text not null,
date_update text not null,
follows text not null,
PRIMARY KEY (user, follows)
);
"""
cursor
.
execute
(
table_following
)
return
conn
except
Exception
as
e
:
return
str
(
e
)
try
:
conn
=
sqlite3
.
connect
(
db
)
cursor
=
conn
.
cursor
()
table_tweets
=
"""
CREATE TABLE IF NOT EXISTS
tweets (
id integer primary key,
user_id integer,
date text not null,
time text not null,
timezone text not null,
location text not null,
user text not null,
tweet text not null,
replies integer,
likes integer,
retweets integer,
hashtags text,
link text
retweet bool,
user_rt text
);
"""
cursor
.
execute
(
table_tweets
)
table_users
=
"""
CREATE TABLE IF NOT EXISTS
users (
user text,
date_update text not null,
num_tweets integer,
PRIMARY KEY (user, date_update)
);
"""
cursor
.
execute
(
table_users
)
table_search
=
"""
CREATE TABLE IF NOT EXISTS
searches (
user text,
date_update text not null,
num_tweets integer,
search_keyword text,
PRIMARY KEY (user, date_update, search_keyword)
);
"""
cursor
.
execute
(
table_search
)
table_followers
=
"""
CREATE TABLE IF NOT EXISTS
followers (
user text not null,
date_update text not null,
follower text not null,
PRIMARY KEY (user, follower)
);
"""
cursor
.
execute
(
table_followers
)
table_following
=
"""
CREATE TABLE IF NOT EXISTS
following (
user text not null,
date_update text not null,
follows text not null,
PRIMARY KEY (user, follows)
);
"""
cursor
.
execute
(
table_following
)
return
conn
except
Exception
as
e
:
return
str
(
e
)
def
following
(
conn
,
user
,
follow
):
try
:
date_time
=
str
(
datetime
.
datetime
.
now
())
cursor
=
conn
.
cursor
()
entry
=
(
user
,
date_time
,
follow
,)
cursor
.
execute
(
'INSERT INTO following VALUES(?,?,?)'
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
try
:
date_time
=
str
(
datetime
.
datetime
.
now
())
cursor
=
conn
.
cursor
()
entry
=
(
user
,
date_time
,
follow
,)
cursor
.
execute
(
'INSERT INTO following VALUES(?,?,?)'
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
def
followers
(
conn
,
user
,
follow
):
try
:
date_time
=
str
(
datetime
.
datetime
.
now
())
cursor
=
conn
.
cursor
()
entry
=
(
user
,
date_time
,
follow
,)
cursor
.
execute
(
'INSERT INTO followers VALUES(?,?,?)'
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
try
:
date_time
=
str
(
datetime
.
datetime
.
now
())
cursor
=
conn
.
cursor
()
entry
=
(
user
,
date_time
,
follow
,)
cursor
.
execute
(
'INSERT INTO followers VALUES(?,?,?)'
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
def
tweets
(
conn
,
Tweet
):
try
:
cursor
=
conn
.
cursor
()
entry
=
(
Tweet
.
id
,
Tweet
.
user_id
,
Tweet
.
datestamp
,
Tweet
.
timestamp
,
Tweet
.
timezone
,
Tweet
.
location
,
Tweet
.
username
,
Tweet
.
tweet
,
Tweet
.
replie
s
,
Tweet
.
likes
,
Tweet
.
retweets
,
","
.
join
(
Tweet
.
hashtags
)
,
Tweet
.
link
,
)
cursor
.
execute
(
"INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)"
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
try
:
cursor
=
conn
.
cursor
()
entry
=
(
Tweet
.
id
,
Tweet
.
user_id
,
Tweet
.
datestamp
,
Tweet
.
timezone
,
Tweet
.
location
,
Tweet
.
username
,
Tweet
.
tweet
,
Tweet
.
likes
,
Tweet
.
retweet
s
,
","
.
join
(
Tweet
.
hashtags
)
,
Tweet
.
link
,
Tweet
.
is_retweet
,
Tweet
.
user_rt
)
cursor
.
execute
(
'INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)'
,
entry
)
conn
.
commit
()
except
sqlite3
.
IntegrityError
:
pass
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