-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
33 lines (24 loc) · 926 Bytes
/
log.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
import os.path
from checkmovies import *
def logTitle(title):
"""Method to log the title into a file called movies.txt"""
with open("movies.txt", "a", encoding="utf-8") as file:
file.write(title + "\n")
def loadTitles():
"""Method to load the titles on program start"""
titles = set()
# If the movies.txt file does exist (program has already been run before)
if(os.path.exists("movies.txt")):
# Create movies.txt and start writing to it
file = open("movies.txt", "r")
# Get each title and remove the \n on the end and add to titles set
for title in file:
titles.add(title.removesuffix("\n"))
file.close()
else: # Else this is the first time start up
# Get all current movies showing
titles = getMovieTitles()
# Log these titles
for title in titles:
logTitle(title)
return titles