Commit 40b57383 authored by Danielvdh03's avatar Danielvdh03
Browse files

last command I swear add_user

parent 1e847646
......@@ -45,24 +45,27 @@ def cleanup_type(text):
def generate_commands():
commands = ("state_votes", "find_user", "county_results", "group_county_by", "get_tweet_candidate",
commands = ("state_votes", "add_user", "find_user", "county_results", "group_county_by", "get_tweet_candidate",
"count_tweet_region", "update_poll_count", "update_state_count", "insert_tweet",
"help", "quit")
"add_annotation_county","view_annotation_county", "help", "quit")
return commands
# Hardcoded list of available descriptions when running help command
def generate_descriptions():
descriptions = ("Enter in a state to view the total number of votes in the 2020 election. Option \"All\" to view votes in descending order by state",
descriptions = ("Enter in a state to view the total number of votes in the 2020 election. Option \"All\" to view votes in descending order by state",
"Adds a new user to the database. Used for supporting a new addition to the database."
"Used to find users with high follower counts by county",
"Prints out the final voting standings by party in a specific county",
"Ranks counties in a given state or across the nation in a specific category (ex. Covid Cases, Income)",
"Displays all tweets about a particular candidate above a certain like threshold",
"Displays the total amount of tweets about the election by region within a specific date range about a candidate",
"Displays the total amount of tweets about the election by region within a specific date range about a candidate",
"Updates the final vote count for a party. Used to update vote counts for parties as votes are being processed",
"Updates the total number of votes by state. Used to update voting data as votes are being processed",
"Inserts new tweet to the database by a specific user",
"Insert/Modify data annotations in a given county election race under each party",
"View previously insert data annotations on all parties in a given county",
"Prints out list of available commands and their options",
"Closes the CLI"
)
......@@ -490,7 +493,7 @@ class Database:
hashtag = hashtag.replace(" ", "")
user_id = self.get_user_id(username) # need user_id use username to get it
tweet_id = 1 + self.get_tweet_id() #tweet id is number of tweets in table + 1
tweet_id = 1 + self.get_new_tweet_id() #tweet id is number of tweets in table + 1
query = "insert into tweet (id, user_id, created_at, tweet, likes, hashtag) \n"
query += "values({0}, {1}, \"{2}\", \"{3}\", {4}, \"{5}\");".format(tweet_id, user_id , date, tweet, likes, hashtag)
......@@ -498,6 +501,7 @@ class Database:
# print(query)
results = self.execute_query(query)
# Gets user_id from a given username
def get_user_id(self, user_name):
query = "select id from user where display_name = \"{0}\"".format(user_name)
......@@ -505,9 +509,16 @@ class Database:
for row in result:
return row[0]
def get_tweet_id(self):
# Generates a new user_id by returning the maximum current id
def get_new_user_id(self):
result = self.execute_query("select count(*) from tweet;")
result = self.execute_query("select max(id) from user;")
for row in result:
return row[0]
# Generates a new tweet_id by returning the maximum current id
def get_new_tweet_id(self):
result = self.execute_query("select max(id) from tweet;")
for row in result:
return row[0]
......@@ -596,6 +607,38 @@ class Database:
annotate = "annotations"
return annotate in columns
def add_user(self):
county = input("Enter name of county that user resides in : ")
county = county.strip()
state = input("Enter name of state that {0} is in : ".format(county))
state = state.strip()
display = input("Enter username of the user : ")
display = display.strip()
followers = input("Enter their follower count : ")
followers = followers.strip()
identifier = self.get_new_user_id()+1 # Max current user id + 1
county_id = self.get_county_id(county, state)
query = "insert into user (id, county_id, display_name, follower_count) \n"
query += "values({0},{1},\"{2}\",{3});".format(identifier, county_id, display, followers)
print(query)
self.execute_query(query)
def get_county_id(self, county:str, state:str):
query = "select id from county where name = \"{0}\" and state_id = (select id from state where name = \"{1}\");".format(county,state)
print(query)
results = self.execute_query(query)
for result in results:
return result[0]
if __name__ == "__main__":
dotenv.load_dotenv(dotenv.find_dotenv())
......@@ -685,6 +728,10 @@ if __name__ == "__main__":
client.view_annotation_county()
elif command == "add_user":
client.add_user()
else:
......
Supports Markdown
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