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 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): def init(db):
try: try:
...@@ -23,52 +36,82 @@ def init(db): ...@@ -23,52 +36,82 @@ def init(db):
link text, link text,
retweet bool, retweet bool,
user_rt text, user_rt text,
mentions text mentions text,
date_update text not null
); );
""" """
cursor.execute(table_tweets) cursor.execute(table_tweets)
table_users = """ table_followers_names = """
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
users ( followers_names (
user text, user text not null,
date_update text not null, date_update text not null,
num_tweets integer, follower text not null,
PRIMARY KEY (user, date_update) PRIMARY KEY (user, follower)
); );
""" """
cursor.execute(table_users) cursor.execute(table_followers_names)
table_search = """ table_following_names = """
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
searches ( following_names (
user text, user text not null,
date_update text not null, date_update text not null,
num_tweets integer, follows text not null,
search_keyword text, PRIMARY KEY (user, follows)
PRIMARY KEY (user, date_update, search_keyword)
); );
""" """
cursor.execute(table_search) cursor.execute(table_following_names)
table_followers = """ table_followers = """
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
followers ( 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, date_update text not null,
follower text not null, follower text not null,
PRIMARY KEY (user, follower) PRIMARY KEY (id, username, follower)
); );
""" """
cursor.execute(table_followers) cursor.execute(table_followers)
table_following = """ table_following = """
CREATE TABLE IF NOT EXISTS CREATE TABLE IF NOT EXISTS
following ( 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, date_update text not null,
follows text not null, follows text not null,
PRIMARY KEY (user, follows) PRIMARY KEY (id, username, follows)
); );
""" """
cursor.execute(table_following) cursor.execute(table_following)
...@@ -77,28 +120,64 @@ def init(db): ...@@ -77,28 +120,64 @@ def init(db):
except Exception as e: except Exception as e:
return str(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: try:
date_time = str(datetime.datetime.now()) date_time = str(datetime.now())
cursor = conn.cursor() cursor = conn.cursor()
entry = (user, date_time, follow,) entry = (User, date_time, Username,)
cursor.execute('INSERT INTO following VALUES(?,?,?)', entry) query = 'INSERT INTO {} VALUES(?,?,?)'.format(fTable(Followers))
cursor.execute(query, entry)
conn.commit() conn.commit()
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
pass pass
def followers(conn, user, follow): def user(conn, Username, Followers, User):
try: try:
date_time = str(datetime.datetime.now()) date_time = str(datetime.now())
cursor = conn.cursor() cursor = conn.cursor()
entry = (user, date_time, follow,) entry = (User.id,
cursor.execute('INSERT INTO followers VALUES(?,?,?)', entry) 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() conn.commit()
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
pass pass
def tweets(conn, Tweet): def tweets(conn, Tweet):
try: try:
date_time = str(datetime.now())
cursor = conn.cursor() cursor = conn.cursor()
entry = (Tweet.id, entry = (Tweet.id,
Tweet.user_id, Tweet.user_id,
...@@ -108,14 +187,14 @@ def tweets(conn, Tweet): ...@@ -108,14 +187,14 @@ def tweets(conn, Tweet):
Tweet.location, Tweet.location,
Tweet.username, Tweet.username,
Tweet.tweet, Tweet.tweet,
Tweet.replies,
Tweet.likes, Tweet.likes,
Tweet.retweets, Tweet.retweets,
",".join(Tweet.hashtags), ",".join(Tweet.hashtags),
Tweet.link, Tweet.link,
Tweet.is_retweet, Tweet.retweet,
Tweet.user_rt, Tweet.user_rt,
",".join(Tweet.mentions)) ",".join(Tweet.mentions),
date_time,)
cursor.execute('INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', entry) cursor.execute('INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', entry)
conn.commit() conn.commit()
except sqlite3.IntegrityError: 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