-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
66 lines (53 loc) · 3.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from datetime import datetime, timedelta
from notion_daily_journal import generate_journal_entry
from tracking_games.track_games_methods import update_games_list
import notion_reading_list_update
import goodreads
from firestore_methods import get_firestore_document, set_last_updated, get_current_books_from_store, add_current_book_to_store, get_last_updated
def main():
# create a new journal page daily
last_updated = get_last_updated('notion_journal')
if last_updated is None or last_updated.date() != datetime.now().date():
if generate_journal_entry():
print("Journal entry created")
set_last_updated('notion_journal')
# Goodreads/reading tracker (run at most every 3 hours)
last_updated = get_last_updated('notion_readingList')
if last_updated is None or last_updated < datetime.now() - timedelta(hours=3):
books_read, currently_reading = goodreads.get_read_and_reading(all_time=False)
prev_curr_books = get_current_books_from_store() # dict of book dicts
# get progress for books that are currently being read
if len(currently_reading) > 0:
books_progress = goodreads.get_progress_from_home_page()
for book in currently_reading:
progress = books_progress.get(book['title'])
if progress:
book['progress'] = progress
else:
print(f"Progress for {book['title']} not found")
firestore_book_key = f"{book['title']}, {book['author_name']}"
firestore_book = prev_curr_books.get(firestore_book_key, None)
# check if the book progress has changed
if not firestore_book or firestore_book.get('progress') != book.get('progress'):
add_current_book_to_store(book)
print(f"Book {book['title']} has been updated on Firestore")
prev_curr_books.pop(firestore_book_key, '') # remove the old book from store if it exists
for _key, fire_book in prev_curr_books.items():
if fire_book.get('progress', 0) == 100 and fire_book.get('date_read'):
continue # book has already been marked as 100% on Firestore
fire_book['progress'] = 100 # the book has been finished
goodreads_book_details = next((book for book in books_read if book["title"] == fire_book['title']), None)
fire_book['date_read'] = goodreads_book_details.get('date_read', None)
add_current_book_to_store(fire_book) # TODO: this should add book to finished reading store
print(f"Book {fire_book['title']} updated on Firestore to 100%")
notion_reading_list_update.update_reading_list(books_read, currently_reading)
set_last_updated('notion_readingList') # add a log that it was successfully updated
# gaming tracker (run at most every once a day)
last_updated = get_firestore_document('logs/notion_gamingTracker').get('lastUpdated')
if last_updated is None or last_updated.date() < datetime.now().date():
update_games_list()
set_last_updated('notion_gamingTracker') # add a log that it was successfully updated
# TODO: add commuting fares
# TODO: add subscription payments
if __name__ == '__main__':
main()