Commit 93c8d273 authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

1.1.3 Update

parent f93c3998
import datetime
from datetime import datetime
import sqlite3
import sys
def Conn(Database):
if Database:
print("[+] Inserting into Database: " + str(Database))
conn = init(Database)
if isinstance(conn, str):
print(str)
sys.exit(1)
else:
conn = ""
return conn
def init(db):
try:
......@@ -23,52 +36,82 @@ def init(db):
link text,
retweet bool,
user_rt text,
mentions text
mentions text,
date_update text not null
);
"""
cursor.execute(table_tweets)
table_users = """
table_followers_names = """
CREATE TABLE IF NOT EXISTS
users (
user text,
followers_names (
user text not null,
date_update text not null,
num_tweets integer,
PRIMARY KEY (user, date_update)
follower text not null,
PRIMARY KEY (user, follower)
);
"""
cursor.execute(table_users)
cursor.execute(table_followers_names)
table_search = """
table_following_names = """
CREATE TABLE IF NOT EXISTS
searches (
user text,
following_names (
user text not null,
date_update text not null,
num_tweets integer,
search_keyword text,
PRIMARY KEY (user, date_update, search_keyword)
follows text not null,
PRIMARY KEY (user, follows)
);
"""
cursor.execute(table_search)
cursor.execute(table_following_names)
table_followers = """
CREATE TABLE IF NOT EXISTS
followers (
user text not null,
id integer not null,
name text,
username text not null,
bio text,
url text,
join_date text not null,
join_time text not null,
tweets integer,
following integer,
followers integer,
likes integer,
media integer,
private text not null,
verified text not null,
avatar text not null,
date_update text not null,
follower text not null,
PRIMARY KEY (user, follower)
PRIMARY KEY (id, username, follower)
);
"""
cursor.execute(table_followers)
table_following = """
CREATE TABLE IF NOT EXISTS
following (
user text not null,
id integer not null,
name text,
username text not null,
bio text,
location text,
url text,
join_date text not null,
join_time text not null,
tweets integer,
following integer,
followers integer,
likes integer,
media integer,
private text not null,
verified text not null,
avatar text not null,
date_update text not null,
follows text not null,
PRIMARY KEY (user, follows)
PRIMARY KEY (id, username, follows)
);
"""
cursor.execute(table_following)
......@@ -77,28 +120,64 @@ def init(db):
except Exception as e:
return str(e)
def following(conn, user, follow):
def fTable(Followers):
if Followers:
table = "followers_names"
else:
table = "following_names"
return table
def uTable(Followers):
if Followers:
table = "followers"
else:
table = "following"
return table
def follow(conn, Username, Followers, User):
try:
date_time = str(datetime.datetime.now())
date_time = str(datetime.now())
cursor = conn.cursor()
entry = (user, date_time, follow,)
cursor.execute('INSERT INTO following VALUES(?,?,?)', entry)
entry = (User, date_time, Username,)
query = 'INSERT INTO {} VALUES(?,?,?)'.format(fTable(Followers))
cursor.execute(query, entry)
conn.commit()
except sqlite3.IntegrityError:
pass
def followers(conn, user, follow):
def user(conn, Username, Followers, User):
try:
date_time = str(datetime.datetime.now())
date_time = str(datetime.now())
cursor = conn.cursor()
entry = (user, date_time, follow,)
cursor.execute('INSERT INTO followers VALUES(?,?,?)', entry)
entry = (User.id,
User.name,
User.username,
User.bio,
User.location,
User.url,
User.join_date,
User.join_time,
User.tweets,
User.following,
User.followers,
User.likes,
User.media_count,
User.is_private,
User.is_verified,
User.avatar,
date_time,
Username,)
query = 'INSERT INTO {} VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'.format(uTable(Followers))
cursor.execute(query, entry)
conn.commit()
except sqlite3.IntegrityError:
pass
def tweets(conn, Tweet):
try:
date_time = str(datetime.now())
cursor = conn.cursor()
entry = (Tweet.id,
Tweet.user_id,
......@@ -108,14 +187,14 @@ def tweets(conn, Tweet):
Tweet.location,
Tweet.username,
Tweet.tweet,
Tweet.replies,
Tweet.likes,
Tweet.retweets,
",".join(Tweet.hashtags),
Tweet.link,
Tweet.is_retweet,
Tweet.retweet,
Tweet.user_rt,
",".join(Tweet.mentions))
",".join(Tweet.mentions),
date_time,)
cursor.execute('INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', entry)
conn.commit()
except sqlite3.IntegrityError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment