
    lYj                        d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z
  ee      j                         j                  j                  dz  Z ee      j                         j                  j                  dz  dz  ZdZd	Zg d
ZddgZdededefdZdedededdfdZdefdZedk(  r ej6                   e              yy)u  Throwaway placeholder catalog: fetch public-domain originals, forge crude fakes.

The real authoring pipeline is deferred (see do.md). Nothing in the game may
depend on how this ran — it exists so the loop can be played at full length.

The generator emits each piece.json itself: it reads `aspect` off the image and
already knows `diff_rect`, because it chose where to edit. Worth keeping when
the real pipeline is built.

    python tools/make_placeholder_catalog.py
    N)Path)Imagedatai18nzart.csvi   z0masterpiece-or-not-dev/0.1 (placeholder catalog)))z	mona-lisaz9Mona Lisa, by Leonardo da Vinci, from C2RMF retouched.jpgz	Mona LisaLeonardo da Vinci)zstarry-nightz0Van Gogh - Starry Night - Google Art Project.jpgzThe Starry NightVincent van Gogh)z
the-screamzpEdvard Munch, 1893, The Scream, oil, tempera and pastel on cardboard, 91 x 73 cm, National Gallery of Norway.jpgz
The ScreamzEdvard Munch)zgirl-with-a-pearl-earringzMeisje met de parel.jpgzGirl with a Pearl EarringzJohannes Vermeer)zbirth-of-venuszJSandro Botticelli - La nascita di Venere - Google Art Project - edited.jpgzThe Birth of VenuszSandro Botticelli)z
great-wavez#Tsunami by hokusai 19th century.jpgzThe Great Wave off KanagawazKatsushika Hokusai)zamerican-gothicz5Grant Wood - American Gothic - Google Art Project.jpgzAmerican Gothicz
Grant Wood)zliberty-leading-the-peopleuD   Eugène Delacroix - Le 28 Juillet. La Liberté guidant le peuple.jpgzLiberty Leading the Peopleu   Eugène Delacroix)zthe-night-watchzThe Night Watch - HD.jpgzThe Night WatchzRembrandt van Rijn)zthe-kissz7The Kiss - Gustav Klimt - Google Cultural Institute.jpgzThe KisszGustav Klimt)
sunflowerszVincent Willem van Gogh 127.jpg
Sunflowersr   )zthe-last-supperz?Leonardo da Vinci (1452-1519) - The Last Supper (1495-1498).jpgzThe Last Supperr   )mirroredzA detail has been flipped.)333333?)\(?gQ?r   )
recolouredz)A colour is not the one the painter used.)g
ףp=
?g?r   gp=
ף?filenametargetreturnc           
         dt         j                  j                  |       t        fz  }t	        j
                  dddt        dt        |      |gd      }|j                  dk7  s|j                         sy		 t        j                  |      5 }|j                          d d d        y# 1 sw Y   yxY w# t        $ r |j                  d
       Y y	w xY w)Nz?https://commons.wikimedia.org/wiki/Special:FilePath/%s?width=%dcurlz-sLz-Az-oT)capture_outputr   F)
missing_ok)urllibparsequoteWIDTH
subprocessrunUAstr
returncodeexistsr   openverify	Exceptionunlink)r   r   urlresultims        0D:\dev\isitart\tools\make_placeholder_catalog.pyfetchr(   3   s    
K8$O C ^^	b$FS9$F AV]]_ZZ 	2IIK	
 	
   &s0   5B0 
B$B0 $B-)B0 -B0 0CCoriginaloutkindc           	      D   t        j                  |       5 }|j                  d      }|j                  \  }}t	        |d   |z        t	        |d   |z        t	        |d   |d   z   |z        t	        |d   |d   z   |z        f}|j                  |      }|dk(  r |j                  t         j                        }n-|j                         \  }	}
}t        j                  d||	|
f      }|j                  ||       |j                  |d       d d d        y # 1 sw Y   y xY w)	NRGBr            r   \   )quality)r   r    convertsizeintcrop	transposeFLIP_LEFT_RIGHTsplitmergepastesave)r)   r*   r+   rectr&   whboxpatchrgbs               r'   forgerE   G   s   	H	 !ZZww1Q!Q!a47"a'(a47"a'(	
 :OOE$9$9:EkkmGAq!KK1ay1E

R !! ! !s   C7DDc                  \   t         j                  d       dg} g g }}t        D ]  \  }}}}t         |z  }|j                  d       |dz  }|j                         s5t	        ||      s)|j                  |       t        j                  |d       nt        j                  |      5 }	|	j                  \  }
}d d d        d|j                         j                  dd      z  }| j                  | d	| d
       g }t        D ]  \  }}}|d| dz  }t        ||||       d|j                         j                  dd      d|j                         }| j                  | d	| d
       |j                  |j                  ||D cg c]  }t!        |d       c}d        |dz  j#                  t%        j&                  |||dt!        
z  d      |j                  |dd      dz   d       |j                  |       t)        d| d|
 d| d|
|z  d        t*        j#                  dj-                  |       dz   d       t)        dt/        |       dt/        |      t/        t              z   d       |rt)        d d!j-                  |              y"# 1 sw Y   xY wc c}w )#NT)exist_okzkeys,enzoriginal.jpg)ignore_errorszART_%s_TITLE-_z,""zfake-z.jpgART__FAKE_   )texturehint_key	diff_rectz
piece.jsonpainting)id	title_keyartisttypeaspectauthentic_texturefakesr/   )indent
zutf-8)encodingz  z: xz aspect=z.3fz	 pieces, z fakeszFAILED to fetch: z, r   )DATAmkdirPIECESr   r(   appendshutilrmtreer   r    r4   upperreplaceFAKESrE   nameround
write_textjsondumpsprintI18Njoinlen)rowsmadefailedpiece_idr   titlerU   folderr)   r&   widthheightrT   rY   r+   hintr=   r*   rP   vs                       r'   mainrz   [   s   JJJ;Dr&D-3 )M)(E6d#N* x)BMM(#MM&5ZZ! 	$RGGME6	$ #X^^%5%=%=c3%GG	ykE7!,- % 		D$U4&--C(Ct,+3>>+;+C+CC+Mtzz|\HKK8*BtfA./LL88$378aeAqk8 		 
,	**JJ& "2%-]]      	+ 	
 	H8*BugQvhhuv~c6JKLS)MV 	OODIIdOd*WO=	Bs4yk3t9s5z#9":&
AB!$))F"3!456K	$ 	$ 9s   'JJ)J&	__main__)__doc__rj   rb   r   sysurllib.parser   pathlibr   PILr   __file__resolveparentr^   rm   r   r   r`   rf   r   boolr(   rE   r5   rz   __name__exit     r'   <module>r      s   
    
   H~&&--6H~&&--6B7
" IY	C  $ (!D !t !3 ! !(4c 4n zCHHTV r   