Commit 1e847646 authored by Danielvdh03's avatar Danielvdh03
Browse files

Added create_annotation and view_annotations

parent 36b53a73
......@@ -34,8 +34,6 @@ def trim(old_list : list):
return new_list
def cleanup_type(text):
text = str(text)
......@@ -488,11 +486,14 @@ class Database:
date = input("Enter the date that this tweet was created as YYYY-MM-DD : ")
date = date.strip()
hashtag = input("Enter the hashtag for this tweet (Donald Trump/Joe Biden)")
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
query = "insert into tweet (id, user_id, created_at, tweet, likes) \n"
query += "values({0}, {1}, \"{2}\", \"{3}\", {4});".format(tweet_id, user_id , date, tweet, likes)
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)
# print(query)
results = self.execute_query(query)
......@@ -510,6 +511,91 @@ class Database:
for row in result:
return row[0]
def add_annotation_county(self):
if self.check_annotation_column() == False:
self.add_annotation_column()
county = input("Enter the county to add/modify the annotation for : ")
county = county.strip()
state = input("Enter the state that {0} belongs to : ".format(county))
state = state.strip()
query = "select candidate, party, annotations from county_candidate_statistics where " \
"county_id = (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)
if len(results) == 0:
print("No results to show. State/County pairing does not exist.")
return
counter = 1
print("Poll Rankings in {0} are as follows : ".format(county))
for result in results:
print("Candidate Name : {0}, Party Affiliation : {1}, Annotations : {2}".format(result[0], result[1], result[2]))
counter += 1
party = input("Enter the party that you wish to add an annotation for : ")
annotation = input("Enter the annotation that you wish to add : ")
query = "update county_candidate_statistics \n"
query += "set annotations = \"{0}\" where party = \"{1}\" and county_id = (select id from county where name=\"{2}\" and state_id = ( select id from state " \
"where name = \"{3}\"));".format(annotation, party, county, state)
print(query)
result = self.execute_query(query)
def view_annotation_county(self):
if self.check_annotation_column() == False:
print("No annotations created")
return
else:
county = input("Enter the county that you wish to view the annotation for : ")
county = county.strip()
state = input("Enter the state that {0} belongs to : ".format(county))
state = state.strip()
query = "select candidate, party, annotations from county_candidate_statistics where county_id = (select id from county where name = \"{0}\" and state_id = (select id from state where name = \"{1}\"));".format(county, state)
result = self.execute_query(query)
if len(result) == 0:
print("No results to display for county {0} in the state of {1}".format(county, state))
return
for row in result:
print("Candidate Name : {0}, Party : {1}, Annotations : {2}".format(row[0], row[1], row[2]))
def add_annotation_column(self):
query = "alter table county_candidate_statistics \n"
query += "add column annotations varchar(255);"
result = self.execute_query(query)
db.commit()
return
# Check if we already added annotations column
def check_annotation_column(self):
columns = self.get_column("county_candidate_statistics")
annotate = "annotations"
return annotate in columns
if __name__ == "__main__":
dotenv.load_dotenv(dotenv.find_dotenv())
......@@ -591,6 +677,14 @@ if __name__ == "__main__":
client.insert_tweet()
elif command == "add_annotation_county":
client.add_annotation_county()
elif command == "view_annotation_county":
client.view_annotation_county()
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