(New feature) 0.4.2 - check for a new url and for the updated state

main
KKlochko 3 years ago
parent 36a4252d08
commit 95362fc3b6

@ -11,3 +11,6 @@
New feature: get an anime info from page New feature: get an anime info from page
** 0.3.0 <2022-07-09> ** 0.3.0 <2022-07-09>
New feature: send a notification New feature: send a notification
** 0.4.1 <2022-07-09>
New feature: check for new url or update state
New small feature: add the urls config file

@ -68,7 +68,7 @@ class DataBase:
"""Add entry of a content.""" """Add entry of a content."""
connect = sqlite3.connect(self.PATH) connect = sqlite3.connect(self.PATH)
cursor = connect.cursor() cursor = connect.cursor()
cursor.execute(f"UPDATE {self.TABLE} SET Status = {new_status} WHERE Url = '{url}'") cursor.execute(f"UPDATE {self.TABLE} SET Status = '{new_status}' WHERE Url = '{url}'")
connect.commit() connect.commit()
cursor.close() cursor.close()
connect.close() connect.close()

@ -18,20 +18,50 @@
# <https://www.gnu.org/licenses/>. # # <https://www.gnu.org/licenses/>. #
########################################################################## ##########################################################################
from db import DataBase from db import DataBase
from scraper import Scraper
from notify import Notification
def get_urls(file_path):
"""Read file that containes urls."""
urls = []
with open(file_path, 'r') as file:
for line in file:
if '\n' in line:
line = line.replace('\n', '')
urls.append(line)
return urls
def main(): def main():
# Const sections.
# Here you can change testing headers to yours.
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
}
MESSAGE = "New episode."
URL_FILE = "urls"
WAITING_PERIOD = 60 # seconds
# Initialising objects
scr = Scraper(HEADERS)
db = DataBase() db = DataBase()
# Test data
#db.add_anime("test.url", "The anime", "1") # Reading the URL_FILE for making list
#db.update_anime_status("test.url", "2") urls = get_urls(URL_FILE)
#data = db.get_entry("test.url") #print(f"{urls}")
#print(f"{data=}")
r = db.add_anime_if("test.url", "The anime", "1") # Checks for new urls in file and add as current state
print(f"1{r=}") # If one of page has updated then notifing.
r = db.add_anime_if("test.url", "The anime", "1") for url in urls:
print(f"2{r=}") data = scr.get_anime(url)
r = db.add_anime_if("test.url", "The anime", "2") if data == None:
print(f"3{r=}") continue
url, title, status = data
r = db.add_anime_if(url, title, status)
if r == -1:
n = Notification(title, MESSAGE)
n.send()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save