-
Notifications
You must be signed in to change notification settings - Fork 0
/
markov.py
55 lines (48 loc) · 1.23 KB
/
markov.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Usage:
Call python markov.py tag1 tag2 tag3 ....
Options forthcoming.
"""
import flickr
import urllib
import Image
import time
import datetime
import sys
import os
from random import choice, shuffle
time_now = datetime.datetime.now()
folder_name = time_now.strftime('%m-%d,%H-%M-%S')
tags = []
alltags = set(tags)
def load_photo(url):
file, mime = urllib.urlretrieve(url.encode('utf-8'))
photo = Image.open(file)
return photo
def show_pic(tags, idx):
photos = flickr.photos_search(tags=tags,per_page=50)
ppp = choice(photos)
u = ppp.getURL(size='Medium',urlType='source')
ph = load_photo(u)
#ph.show()
ph.save("pictures/"+folder_name+"/"+str(idx)+".jpg","JPEG")
newtagset = tags[1:]
newtags = list(set(ppp.tags)-alltags)
if len(newtags)==0:
print 'done'
newtagset.append(choice(newtags).text.encode('utf-8'))
return newtagset
def main(*tag_list):
os.mkdir('pictures/'+folder_name)
f = open('pictures/'+folder_name+'/log.txt','w')
tags = list(tag_list[1:])
f.write('0: '+str(tags)+'\n')
alltags = set(tags)
for i in range(20):
tags = show_pic(tags, i)
alltags = alltags | set(tags)
f.write(str(i+1)+': '+str(tags)+'\n')
#print alltags
#time.sleep(.1)
f.close()
if __name__ == '__main__':
sys.exit(main(*sys.argv))