I am trying to do a simple windows app for picking a random movie from my trakt.tv watchlist, I used tkinter for a basic gui, then use random funciton to choice a movie from a txt file, then with trakt library fucntion I get my watch list from trakt and record it as a txt for random choice, define a function to one of my button to pick a random movie from there and show it in text box. It's working in that way but now I want to add overview, rating, year information related to the random movie, it is working good for just "some titles" but some movies get following error message; "trakt.errors.NotFoundException: Not Found - method exists, but no record found"
I think some movie's names can't get direct result from trakt.tv, so what could be solution for that? For example; can I get trakt_id from a watchlist and use it for all other information and how? I check library files but it seems get the info directly user list website and I couldn't figure out how can I get any other information from there. Also how can I add a random fanart under the buttons related to movie which choiced by random?
Sorry my English and if I can't explain my questions well :)
My code is below;
# -*- coding: utf8 -*-
import random
from tkinter import *
from trakt import init
from trakt.users import User
from trakt.movies import Movie
import tkinter as tk
### For Trakt.tv Authorize and Save It
### init('myusername', store=True)
my = User('username') ## Must be your username
watchlist = my.watchlist_movies
f=open("watchmovies.txt","w", encoding='utf-8')
f.write(str(watchlist))
f.close()
# TXT DOSYASINI DÜZENLEME
# Read in the file
with open('watchmovies.txt', 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('[', '')
filedata = filedata.replace(']', '')
# Write the file out again
with open('watchmovies.txt', 'w') as file:
file.write(filedata)
# New Line for Commas
f1=open("watchmovies.txt","r+")
input=f1.read()
print(input)
input=input.replace('<Movie>:','\n')
input=input.replace(',','')
f2=open("watchmovies.txt","w+")
f2.write(input)
f1.close()
f2.close()
# Pencere oluşturma
window = Tk()
window.title("Pick A Movie For Me")
window.geometry("300x500")
window.configure(background='black')
# Yazı Alanı oluşturma
T = Text(window, height=15, width=40, wrap = WORD)
T.configure(background='orange')
T.pack()
# Random bilgi için kaynak dosyası
lines = open('watchmovies.txt').read().splitlines()
# Buton işlemi
def callback():
myline = random.choice(lines)
print(myline)
myline2 = Movie(str(myline))
yeary = str(myline2.year)
ratingy = str(myline2.rating)[:4]
overviewy = str(myline2.overview)
T.delete('1.0', END)
showline= "\n" + myline + " " + ratingy + "\n" + yeary + "\n" + "\n" + overviewy
T.insert("1.0", showline)
T.tag_add('center', "1.0", "end")
T.tag_configure("center", justify='center', font='Calibri 11 bold')
# Butonlar
b = Button(window, text="Good Luck!", command=callback)
b.configure(background='black', foreground='white')
b.pack()
c = Button(window, text="Close", command=window.quit)
c.configure(background='black', foreground='white')
c.pack()
mainloop()
Aucun commentaire:
Enregistrer un commentaire