mirror of
https://github.com/SinTan1729/TvTimeToTrakt.git
synced 2024-12-26 05:18:36 -06:00
Change field selection to named columns instead of indexes. (csv.DictReader)
Allow empty menu input, defaulting to choice #1 Change total line count to reuse already opened CSV file Use enumerate() to track row ID
This commit is contained in:
parent
6d8818bc14
commit
9436798e47
1 changed files with 114 additions and 125 deletions
|
@ -1,17 +1,15 @@
|
||||||
# main.py
|
#!/usr/bin/env python3
|
||||||
from logging import error
|
|
||||||
import sys
|
|
||||||
from trakt import *
|
|
||||||
import trakt.core
|
|
||||||
import os
|
|
||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
|
||||||
import time
|
|
||||||
from tinydb import TinyDB, Query
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import trakt.core
|
||||||
|
from tinydb import Query, TinyDB
|
||||||
|
from trakt import Expando
|
||||||
from trakt.tv import TVShow
|
from trakt.tv import TVShow
|
||||||
|
|
||||||
# Adjust this value to increase/decrease your requests between episodes.
|
# Adjust this value to increase/decrease your requests between episodes.
|
||||||
|
@ -58,6 +56,7 @@ def getFollowedShowsPath():
|
||||||
|
|
||||||
|
|
||||||
def initTraktAuth():
|
def initTraktAuth():
|
||||||
|
return True
|
||||||
# Set the method of authentication
|
# Set the method of authentication
|
||||||
trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH
|
trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH
|
||||||
return init(config.TRAKT_USERNAME, store=True, client_id=config.CLIENT_ID, client_secret=config.CLIENT_SECRET)
|
return init(config.TRAKT_USERNAME, store=True, client_id=config.CLIENT_ID, client_secret=config.CLIENT_SECRET)
|
||||||
|
@ -291,42 +290,31 @@ def processWatchedShows():
|
||||||
# Total amount of rows which have been processed in the CSV file
|
# Total amount of rows which have been processed in the CSV file
|
||||||
rowsCount = 0
|
rowsCount = 0
|
||||||
# Total amount of rows in the CSV file
|
# Total amount of rows in the CSV file
|
||||||
rowsTotal = 0
|
|
||||||
# Total amount of errors which have occurred in one streak
|
|
||||||
errorStreak = 0
|
errorStreak = 0
|
||||||
|
|
||||||
# Get the total amount of rows in the CSV file,
|
|
||||||
# which is helpful for keeping track of progress.
|
|
||||||
# However, if you have a VERY large CSV file (e.g above 100,000 rows)
|
|
||||||
# then it might be a good idea to remove this due to the performance
|
|
||||||
# overhead.
|
|
||||||
with open(getWatchedShowsPath()) as f:
|
|
||||||
rowsTotal = sum(1 for line in f)
|
|
||||||
|
|
||||||
# Open the CSV file within the GDPR exported data
|
# Open the CSV file within the GDPR exported data
|
||||||
with open(getWatchedShowsPath(), newline='') as csvfile:
|
with open(getWatchedShowsPath(), newline='') as csvfile:
|
||||||
# Create the CSV reader, which will break up the fields using the delimiter ','
|
# Create the CSV reader, which will break up the fields using the delimiter ','
|
||||||
showsReader = csv.reader(csvfile, delimiter=',')
|
showsReader = csv.DictReader(csvfile, delimiter=',')
|
||||||
|
# Get the total amount of rows in the CSV file,
|
||||||
|
rowsTotal = len(list(showsReader))
|
||||||
|
# Move position to the beginning of the file
|
||||||
|
csvfile.seek(0, 0)
|
||||||
# Loop through each line/record of the CSV file
|
# Loop through each line/record of the CSV file
|
||||||
for row in showsReader:
|
|
||||||
# Increment the row counter to keep track of progress completing the
|
|
||||||
# records during the import process.
|
|
||||||
rowsCount += 1
|
|
||||||
# Get the name of the TV show
|
|
||||||
tvShowName = row[8]
|
|
||||||
|
|
||||||
# Ignore the header row
|
# Ignore the header row
|
||||||
if rowsCount > 1:
|
next(showsReader, None)
|
||||||
|
for rowsCount, row in enumerate(showsReader):
|
||||||
|
# Get the name of the TV show
|
||||||
|
tvShowName = row["tv_show_name"]
|
||||||
# Get the TV Time Episode Id
|
# Get the TV Time Episode Id
|
||||||
tvShowEpisodeId = row[4]
|
tvShowEpisodeId = row["episode_id"]
|
||||||
# Get the TV Time Season Number
|
# Get the TV Time Season Number
|
||||||
tvShowSeasonNo = row[5]
|
tvShowSeasonNo = row["episode_season_number"]
|
||||||
# Get the TV Time Episode Number
|
# Get the TV Time Episode Number
|
||||||
tvShowEpisodeNo = row[6]
|
tvShowEpisodeNo = row["episode_number"]
|
||||||
# Get the date which the show was marked 'watched' in TV Time
|
# Get the date which the show was marked 'watched' in TV Time
|
||||||
tvShowDateWatched = row[7]
|
tvShowDateWatched = row["updated_at"]
|
||||||
# Parse the watched date value into a Python type
|
# Parse the watched date value into a Python type
|
||||||
|
print(tvShowDateWatched)
|
||||||
tvShowDateWatchedConverted = datetime.strptime(
|
tvShowDateWatchedConverted = datetime.strptime(
|
||||||
tvShowDateWatched, '%Y-%m-%d %H:%M:%S')
|
tvShowDateWatched, '%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
@ -429,7 +417,8 @@ def start():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
menuSelection = int(input(f"Enter your menu selection: "))
|
menuSelection = input(f"Enter your menu selection: ")
|
||||||
|
menuSelection = 1 if not menuSelection else int(menuSelection)
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Invalid input. Please enter a numerical number.")
|
print("Invalid input. Please enter a numerical number.")
|
||||||
|
|
Loading…
Reference in a new issue