Skip to content

Commit

Permalink
Update pattrmm.py
Browse files Browse the repository at this point in the history
Updated how Trakt Lists were posted to increase speed.
Changed how info was displayed during runs for a shorter and cleaner output.
  • Loading branch information
InsertDisc authored Sep 3, 2023
1 parent 2ee14d3 commit 9babaeb
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions pattrmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def tmdb_id(self, rating_key):
year = self.year(rating_key)
if year != None:
print("")
print("No TMDB ID found locally: Searching themoviedb.org with " + show_name + " and year " + str(year))
print("No TMDB ID found in Plex: Searching for " + show_name + " with year " + str(year))
search = self.search_tmdb_id(show_name, year)
if search == None:
year = int(year)
Expand Down Expand Up @@ -856,7 +856,7 @@ def __init__(self, id, title, firstAir, lastAir, nextAir, status, pop):

tmdb = json.loads(prettyJson(requests.get(tmdbUrl, headers=tmdbHeaders, params=tmdbParams).json()))

print("Refreshing data for " + tmdb['name'] + " ( " + str(tmdb['id']) + " )")
print("\033[KRefreshing data for " + tmdb['name'] + " ( " + str(tmdb['id']) + " )", end="\r", flush=True)

if tmdb['last_air_date'] != None and tmdb['last_air_date'] != "" :
lastAir = tmdb['last_air_date']
Expand Down Expand Up @@ -899,7 +899,7 @@ def __init__(self, id, title, firstAir, lastAir, nextAir, status, pop):
writeTmdb = open(cache, "w")
writeTmdb.write(listResults)
writeTmdb.close()
print(library + " TMDB data updated...")
print("\033[K" + library + " TMDB data updated...")


# write Template to Overlay file
Expand Down Expand Up @@ -1162,24 +1162,32 @@ def __init__(self, id, title, firstAir, lastAir, nextAir, status, pop):
traktMakeList = requests.post(traktListUrl, headers=traktHeaders, data=traktListData)
time.sleep(1.25)

traktListShow = '''
{
"shows": [
'''
for item in returningSorted:
print("Adding " + item['title'] + " | TMDB ID: " + str(item['id']) + ", to Returning Soon " + library + ".")

traktListShow = f'''
{{
"shows": [
traktListShow += f'''
{{
"ids": {{
"tmdb": "{str(item['id'])}"
}}
}}
}},'''

traktListShow = traktListShow.rstrip(",")
traktListShow += '''
]
}}
'''
postShow = requests.post(traktListUrlPostShow, headers=traktHeaders, data=traktListShow)
time.sleep(1.25)
}
'''

print("Added " + str(get_count(returningSorted)) + " entries to Trakt.")
postShow = requests.post(traktListUrlPostShow, headers=traktHeaders, data=traktListShow)
if postShow.status_code == 201:
print("Success")
print("Added " + str(get_count(returningSorted)) + " entries to Trakt.")
else:
print("Failure: " + str(postShow.status_code))
end_time = time.time()
elapsed_time = end_time - start_time
minutes, seconds = divmod(elapsed_time, 60)
Expand Down

0 comments on commit 9babaeb

Please sign in to comment.