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
c32948c8
Commit
c32948c8
authored
Apr 04, 2018
by
Francesco Poldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added searches table
parent
f47d011e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
6 deletions
+33
-6
tweep.py
tweep.py
+33
-6
No files found.
tweep.py
View file @
c32948c8
...
@@ -15,6 +15,8 @@ import re
...
@@ -15,6 +15,8 @@ import re
import
sys
import
sys
import
sqlite3
import
sqlite3
user_list
=
{}
## clean some output
## clean some output
class
RecycleObject
(
object
):
class
RecycleObject
(
object
):
def
write
(
self
,
junk
):
pass
def
write
(
self
,
junk
):
pass
...
@@ -52,12 +54,24 @@ def initdb(db):
...
@@ -52,12 +54,24 @@ def initdb(db):
table_users
=
"""
table_users
=
"""
CREATE TABLE IF NOT EXISTS
CREATE TABLE IF NOT EXISTS
users (
users (
user text
primary key
,
user text,
date_update text not null,
date_update text not null,
num_tweets integer
num_tweets integer,
PRIMARY KEY (user, date_update)
);
);
"""
"""
cursor
.
execute
(
table_users
)
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
)
return
conn
return
conn
except
Exception
as
e
:
except
Exception
as
e
:
return
str
(
e
)
return
str
(
e
)
...
@@ -218,6 +232,11 @@ async def outTweet(tweet):
...
@@ -218,6 +232,11 @@ async def outTweet(tweet):
entry
=
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
,
replies
,
likes
,
retweets
,
hashtags
,)
entry
=
(
tweetid
,
date
,
time
,
timezone
,
username
,
text
,
replies
,
likes
,
retweets
,
hashtags
,)
cursor
.
execute
(
'INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?)'
,
entry
)
cursor
.
execute
(
'INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?)'
,
entry
)
conn
.
commit
()
conn
.
commit
()
if
username
in
list
(
user_list
):
old_tot
=
user_list
[
list
(
user_list
)[
list
(
user_list
)
.
index
(
username
)]]
user_list
.
update
({
username
:
old_tot
+
1
})
else
:
user_list
.
update
({
username
:
1
})
except
sqlite3
.
IntegrityError
:
# this happens if the tweet is already in the db
except
sqlite3
.
IntegrityError
:
# this happens if the tweet is already in the db
return
""
return
""
...
@@ -395,7 +414,7 @@ async def main():
...
@@ -395,7 +414,7 @@ async def main():
'''
'''
if
arg
.
elasticsearch
:
if
arg
.
elasticsearch
:
print
(
"Indexing to Elasticsearch @"
+
str
(
arg
.
elasticsearch
))
print
(
"Indexing to Elasticsearch @
"
+
str
(
arg
.
elasticsearch
))
if
arg
.
database
:
if
arg
.
database
:
print
(
"Inserting into Database: "
+
str
(
arg
.
database
))
print
(
"Inserting into Database: "
+
str
(
arg
.
database
))
...
@@ -427,10 +446,18 @@ async def main():
...
@@ -427,10 +446,18 @@ async def main():
break
break
if
arg
.
database
:
if
arg
.
database
:
now
=
str
(
datetime
.
datetime
.
now
())
cursor
=
conn
.
cursor
()
cursor
=
conn
.
cursor
()
entry
=
(
str
(
arg
.
u
),
str
(
datetime
.
datetime
.
now
()),
num
,)
if
arg
.
s
:
cursor
.
execute
(
'INSERT OR REPLACE INTO users VALUES(?,?,?)'
,
entry
)
for
user
in
list
(
user_list
):
conn
.
commit
()
tot
=
user_list
[
list
(
user_list
)[
list
(
user_list
)
.
index
(
user
)]]
entry
=
(
user
,
now
,
tot
,
str
(
arg
.
s
),)
cursor
.
execute
(
'INSERT OR REPLACE INTO searches VALUES(?,?,?,?)'
,
entry
)
conn
.
commit
()
else
:
entry
=
(
str
(
arg
.
u
),
now
,
num
,)
cursor
.
execute
(
'INSERT OR REPLACE INTO users VALUES(?,?,?)'
,
entry
)
conn
.
commit
()
conn
.
close
()
conn
.
close
()
if
arg
.
count
:
if
arg
.
count
:
...
...
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