(new small feature) 0.1.3 - add an anime entry if
This commit is contained in:
@@ -5,3 +5,5 @@
|
||||
New small feature: update anime status
|
||||
** 0.1.2 <2022-07-08>
|
||||
New small feature: get an anime entry
|
||||
** 0.1.3 <2022-07-08>
|
||||
New small feature: add an anime entry if
|
||||
|
||||
@@ -74,7 +74,10 @@ class DataBase:
|
||||
connect.close()
|
||||
|
||||
def get_entry(self, url):
|
||||
"""Returns the entry if exists. Otherwise, return []."""
|
||||
"""
|
||||
Returns the enties as an list of tuples if exists.
|
||||
Otherwise, return [].
|
||||
"""
|
||||
connect = sqlite3.connect(self.PATH)
|
||||
cursor = connect.cursor()
|
||||
cursor.execute(f"SELECT * FROM {self.TABLE} WHERE Url = '{url}';")
|
||||
@@ -82,3 +85,22 @@ class DataBase:
|
||||
cursor.close()
|
||||
connect.close()
|
||||
return data
|
||||
|
||||
def add_anime_if(self, url, title, status):
|
||||
"""
|
||||
Return 0 if not exists.
|
||||
Return 1 if the same as the entry in the DB.
|
||||
Return -1 if the status is newer than the entry status.
|
||||
"""
|
||||
data = self.get_entry(url)
|
||||
# If not exists
|
||||
if data == []:
|
||||
self.add_anime(url, title, status)
|
||||
return 0
|
||||
# If the same
|
||||
if data[0][1:] == (url, title, status):
|
||||
return 1
|
||||
# If the status is newer than the entry status.
|
||||
if data[0][3] != status:
|
||||
self.update_anime_status(url, status)
|
||||
return -1
|
||||
|
||||
+8
-2
@@ -24,8 +24,14 @@ def main():
|
||||
# Test data
|
||||
#db.add_anime("test.url", "The anime", "1")
|
||||
#db.update_anime_status("test.url", "2")
|
||||
data = db.get_entry("test.url")
|
||||
print(f"{data=}")
|
||||
#data = db.get_entry("test.url")
|
||||
#print(f"{data=}")
|
||||
r = db.add_anime_if("test.url", "The anime", "1")
|
||||
print(f"1{r=}")
|
||||
r = db.add_anime_if("test.url", "The anime", "1")
|
||||
print(f"2{r=}")
|
||||
r = db.add_anime_if("test.url", "The anime", "2")
|
||||
print(f"3{r=}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user