Commit a902bb01 authored by Danielvdh03's avatar Danielvdh03
Browse files

bug fix on insert_tweet

parent 2e84e64a
......@@ -48,7 +48,7 @@ def cleanup_type(text):
def generate_commands():
commands = ("state_votes", "find_user", "county_results", "group_county_by", "get_tweet_candidate",
"count_tweet_region", "update_poll_count", "update_state_count", "insert_tweet", "annotate_poll", "view_annotations",
"count_tweet_region", "update_poll_count", "update_state_count", "insert_tweet",
"help", "quit")
return commands
......@@ -63,8 +63,6 @@ def generate_descriptions():
"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",
"Used to create/edit annotations about a specific party in a specific county's election result",
"View created annotations about a specific party in a county",
"Prints out list of available commands and their optoins",
"Closes the CLI"
)
......@@ -96,15 +94,6 @@ class Database:
# print(fields)
return fields
def get_count(self, table: str):
query = "select count(*) from {0}".format(table)
result = self.execute_query(query)
for entry in result:
return entry[0]
def setup_stateid_table(self):
......@@ -167,7 +156,7 @@ class Database:
query = self.generate_create_query(table_name, attributes, type, max_length, num_floating, pk)
print(query) # For debugging purposes
# print(query) # For debugging purposes
results = self.execute_query(query)
......@@ -270,7 +259,7 @@ class Database:
for result in results:
print("Number of votes from {0} is currently : {1}".format(state, result[0]))
value = input("Enter new value that you wish to update the state count to")
value = input("Enter new value that you wish to update the state count to : ")
query = "update state \n"
query += "set total_votes = {0} \n".format(value)
......@@ -309,7 +298,7 @@ class Database:
query = "select display_name, follower_count from user where follower_count between {0} and {1} and " \
"county_id in (select id from county where state_id = (select id from state where name=\"{2}\")) order by follower_count desc {3};".format(
min_follower_count, max_follower_count, state, limit_string)
print(query)
#print(query)
results = self.execute_query(query)
if len(results) == 0:
......@@ -333,7 +322,7 @@ class Database:
" county_id = (select id from county where name = \"{2}\" and state_id = (select id from state where name = \"{3}\" )) order by follower_count desc {4};".format(min_follower_count, max_follower_count,
county, state , limit_string)
print(query)
# print(query)
results = self.execute_query(query)
if len(results) == 0:
......@@ -359,7 +348,7 @@ class Database:
"where name = \"{1}\"));".format(county,state)
results = self.execute_query(query)
print(query)
# print(query)
if len(results) == 0:
print("No results to show")
return
......@@ -440,7 +429,7 @@ class Database:
query += order_string
query += limit_string
query += ";"
print(query)
#print(query)
results = self.execute_query(query)
if len(results)== 0:
......@@ -471,7 +460,7 @@ class Database:
query = "select display_name, tweet, likes from user inner join tweet on tweet.user_id=user.id where tweet > {0} and hashtag = \"{1}\"" \
" and county_id = (select id from county where name = \"{2}\" and state_id = (select id from state where name = \"{3}\")) ;" .format(likes, candidate_name, region, state )
print(query)
#print(query)
results = self.execute_query(query)
if len(results) == 0:
......@@ -485,7 +474,7 @@ class Database:
def count_tweet_region(self):
candidate_name = input("Enter the candidate name (Joe Biden/ Donald Trump) : ")
candidate_name = input("Enter the candidate name (Joe Biden/Donald Trump) : ")
candidate_name = candidate_name.strip()
candidate_name = candidate_name.replace(" ", "")
......@@ -496,18 +485,25 @@ class Database:
likes = input("Input the minimum amount of likes to query by")
likes = likes.strip()
starting_date = input("Enter Start Date to filter by (YYYY-MM-DD): ")
starting_date = starting_date.strip()
starting_date += " 00:00:00"
end_date = input("Enter End Date to filter by (YYYY-MM-DD): ")
end_date = end_date.strip()
end_date+=" 00:00:00"
query = "select count(tweet) from tweet inner join user on tweet.user_id=user.id where tweet > {0} and hashtag = \"{1}\"" \
" and county_id = (select id from county where name = \"{2}\" and state_id = (select id from state where name = \"{3}\")) ;" .format(likes, candidate_name, region, state )
print(query)
# print(query)
results = self.execute_query(query)
if len(results) == 0:
print("No tweets in county {0} above {1} likes".format(region, likes))
print("No tweets in county {0} above {1} likes in this timeframe".format(region, likes))
return
print("Number of tweets in county {0} above {1} likes is {2}".format(region, likes, results[0]))
print("Number of tweets in county {0} above {1} likes in timeframe is {2}".format(region, likes, results[0]))
def update_poll_count(self):
......@@ -523,7 +519,7 @@ class Database:
results = self.execute_query(query)
if len(results) == 0:
print("No results to show")
print("No results to show. State/County pairing does not exist.")
return
counter = 1
......@@ -544,7 +540,7 @@ class Database:
query += "Where party = \"{0}\" and county_id = (select id from county where name = \"{1}\"" \
" and state_id = (select id from state where name = \"{2}\"));".format(party, county, state)
print(query)
#print(query)
results = self.execute_query(query)
print(results)
......@@ -562,28 +558,27 @@ class Database:
date = input("Enter the date that this tweet was created as YYYY-MM-DD : ")
date = date.strip()
id = self.get_id(username)
user_id = self.get_user_id()
user_id = self.get_user_id(username)
tweet_id = 1 + self.get_tweet_id() #tweet id is number of tweets in table + 1
query = "insert into tweet (id, user_id, created_at, tweet, likes) \n"
query+="values({0}, {1}, {2}, {3}, {4});".format(id, user_id , date, tweet, likes)
query+="values({0}, {1}, \"{2}\", \"{3}\", {4});".format(tweet_id, user_id , date, tweet, likes)
print(query)
results = self.execute_query(query)
def get_user_id(self, user_name):
query = "select id from user where display_name = \"{0}\"".format(user_name)
result = self.execute_query(query)
for row in result:
return row[0]
return self.execute_query(query)
def annotate_poll(self):
pass
def view_annotations(self):
pass
def get_tweet_id(self):
result = self.execute_query("select count(*) from tweet;")
for row in result:
return row[0]
if __name__ == "__main__":
......@@ -635,40 +630,35 @@ if __name__ == "__main__":
client.find_user()
elif command == "county_results":
elif command == "county_results": # Works
client.results_county()
elif command == "group_county_by":
elif command == "group_county_by": # Works
client.group_county_by()
elif command == "get_tweet_candidate":
elif command == "get_tweet_candidate": # Untested
client.get_tweet_candidate()
elif command == "count_tweet_region":
elif command == "count_tweet_region": # Untested
client.count_tweet_region()
elif command == "update_poll_count":
elif command == "update_poll_count": # Works
client.update_poll_count()
elif command == "update_state_count":
elif command == "update_state_count": # Works
client.update_state_count()
elif command == "insert_tweet":
elif command == "insert_tweet": # Untested
client.insert_tweet()
elif command == "annotate_poll":
client.annotate_poll()
elif command == "view_annotation_poll":
client.view_annotations()
else:
print("Invalid command, please enter a valid command!")
......
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