Commit 9bef9a1b authored by Danielvdh03's avatar Danielvdh03
Browse files

added insert_tweet

parent 6d87d8af
......@@ -34,6 +34,8 @@ def trim(old_list : list):
return new_list
def cleanup_type(text):
text = str(text)
......@@ -87,6 +89,15 @@ 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):
......@@ -507,6 +518,27 @@ class Database:
tweet = input("Enter the contents of the tweet : ")
tweet = tweet.strip()
likes = input("Enter the number of likes this tweet has : ")
likes = likes.strip()
date = input("Enter the date that this tweet was created as YYYY-MM-DD : ")
date = date.strip()
id = 1 + self.get_count(tweet)
user_id = self.get_user_id()
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)
print(query)
def get_user_id(self, user_name):
query = "select id from user where display_name = \"{0}\"".format(user_name)
return self.execute_query(query)
if __name__ == "__main__":
......
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