11import tkinter as tk
22from PIL import Image , ImageTk
33import io
4- from random import randint
4+ from random import randint , choice
55import asyncio
66import time
77import aiohttp
@@ -28,19 +28,23 @@ def start(self):
2828 self .loop .run_until_complete (self .get_cache ())
2929 self .new_image ()
3030
31+
3132 async def get_cache (self ):
3233 print ("refreshing image cache" )
3334 t = time .time ()
3435 if not self .session :
35- headers = {'x-api-key' : 'd12e9702-f791-4d13-9ffd-0edeed9cecaf' }
36- self .session = aiohttp .ClientSession (headers = headers )
36+ self .session = aiohttp .ClientSession ()
3737 for _ in range (10 ):
38- if randint (0 ,10 ) == 9 :
38+ if randint (0 ,9 ) == 9 :
3939 image_number = randint (1 ,10 )
4040 im = Image .open (os .path .join (self .dir , os .path .join ("res" , os .path .join ("images" , f"{ image_number } .jpg" ))))
4141 im = im .resize ((400 , 400 ), Image .NEAREST )
4242 image = ImageTk .PhotoImage (im )
43- self .images .append ([image , True ])
43+ async with self .session .get ("https://www.pawclub.com.au/assets/js/namesTemp.json" ) as res :
44+ data = await res .json ()
45+ names = choice (data ["a" ])
46+ name = names ["name" ]
47+ self .images .append ([image , True , name ])
4448 else :
4549 async with self .session .get ('https://api.thecatapi.com/v1/images/search' ) as res :
4650 data = await res .json ()
@@ -50,10 +54,25 @@ async def get_cache(self):
5054 im = Image .open (io .BytesIO (image_bytes ))
5155 im = im .resize ((400 , 400 ), Image .NEAREST )
5256 image = ImageTk .PhotoImage (im )
53- self .images .append ([image , False ])
57+ async with self .session .get ("https://www.pawclub.com.au/assets/js/namesTemp.json" ) as res :
58+ data = await res .json ()
59+ letter = choice (list ('acdefghijklmnopqrstuvwxyz' ))
60+ names = choice (data [letter ])
61+ name = names ["name" ]
62+ self .images .append ([image , False , name ])
5463 print (time .time ()- t )
5564
5665
66+ async def get_bio (self ):
67+ #code to get bio goes here
68+ #probably want to return a dict of some sort
69+ pass
70+
71+
72+ def bio (self ):
73+ self .loop .run_until_complete (self .get_bio ())
74+
75+
5776 def all_children (self ):
5877 children = self .root .winfo_children ()
5978 for item in children :
@@ -68,16 +87,27 @@ def new_image(self):
6887 item .pack_forget ()
6988 self .frame = tk .Frame (self .root , bg = "black" )
7089 try :
71- image , jumpscare = self .images .pop (0 )
90+ image , jumpscare , cat_name = self .images .pop (0 )
7291 except IndexError :
7392 self .loop .run_until_complete (self .get_cache ())
74- image , jumpscare = self .images .pop (0 )
75- label = tk .Label (self .frame , image = image )
76- label .pack (side = tk .TOP , fill = "both" , expand = "yes" )
77- like = tk .Button (self .frame , text = "Like" , background = "green" , command = self .new_image )
78- like .pack (side = tk .RIGHT )
79- dislike = tk .Button (self .frame , text = "Dislike" , background = "red" , command = self .new_image )
80- dislike .pack (side = tk .LEFT )
93+ image , jumpscare , cat_name = self .images .pop (0 )
94+ name = tk .Text (self .frame , width = 40 , height = 1 )
95+ name .tag_configure ("center" , justify = tk .CENTER )
96+ name .insert ("1.0" , cat_name )
97+ name .tag_add ("center" , "1.0" , tk .END )
98+ name .configure (state = "disabled" )
99+ name .pack (side = tk .TOP )
100+ tk .Label (self .frame , image = image ).pack (side = tk .TOP )
101+ tk .Button (self .frame , text = "Like" , background = "green" , command = self .new_image ).pack (side = tk .RIGHT )
102+ tk .Button (self .frame , text = "Dislike" , background = "red" , command = self .new_image ).pack (side = tk .LEFT )
103+ def get_bio ():
104+ widget_list = self .all_children ()
105+ for item in widget_list :
106+ item .pack_forget ()
107+ self .frame = tk .Frame (self .root , bg = "black" )
108+ full_bio = self .loop .run_until_complete (self .get_bio ())
109+ bio = tk .Text (self .frame )
110+ tk .Button (self .frame , text = "Bio" , background = "blue" , command = get_bio ).pack (side = tk .BOTTOM )
81111 if jumpscare :
82112 mixer .music .load (os .path .join (self .dir , os .path .join ("res" , os .path .join ("sounds" , "jumpscare.mp3" ))))
83113 mixer .music .play ()
@@ -99,5 +129,6 @@ def motion(self,event):
99129 move_y = (15 - y ) - frame_y
100130 self .root .geometry (f"400x500+{ move_x } +{ move_y } " )
101131
132+
102133if __name__ == "__main__" :
103134 Tinder ().start ()
0 commit comments