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
926e14fa
Commit
926e14fa
authored
Apr 29, 2018
by
Cody Zacharias
Committed by
GitHub
Apr 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create db.py
parent
f2ceb3cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
twint/db.py
twint/db.py
+105
-0
No files found.
twint/db.py
0 → 100644
View file @
926e14fa
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,
date text not null,
time text not null,
timezone text not null,
user text not null,
tweet text not null,
replies integer,
likes integer,
retweets integer,
hashtags 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 VALUE(?,?,?)'
,
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
def
tweets
(
conn
,
Tweet
):
try
:
cursor
=
conn
.
cursor
()
entry
=
(
Tweet
.
id
,
Tweet
.
datestamp
,
Tweet
.
timestamp
,
Tweet
.
timezone
,
Tweet
.
username
,
Tweet
.
tweet
,
Tweet
.
replies
,
Tweet
.
likes
,
Tweet
.
retweets
,
","
.
join
(
Tweet
.
hashtags
),)
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