def update_photos(): i = 0 empty = 0 for photo in Photo.select(): i += 1 if photo.colors == "": empty += 1 for pt in list(photo.tags): pt.delete_instance() photo.delete_instance() print i print empty
1230, #urbanwalls 1237, #graffitiart, 227, #streetphotography 1228, #streetarteverywhere 183, #londonstreetart 2262, #streetartuk 1967, #shoreditchstreetart 1975, #graffitilondon 4085, #murales ] if __name__ == "__main__": n_photos = 0 n_tags = 0 n = 0 for p in Photo.select(): n += 1 if n % 100 == 0: print 'processed: ' + str(n) print 'Removed photos: ' + str(n_photos) print 'Removed tags: ' + str(n_tags) if p.tags.count() == 0: continue for pt in p.tags: if pt.tag.id in save_tags: break else: n_photos += 1 for pt in p.tags: if pt.tag.photos.count() == 1:
import json from db import db, Photo, Tag, PhotoTag steps = {} if __name__ == '__main__': photos = [p.to_dict() for p in Photo.select()] with open('data/photos.json', 'w') as fp: json.dump(photos, fp)
import json from db import db, Photo, Tag, PhotoTag steps = {} if __name__ == '__main__': with open('data/data.txt', 'w') as fp: fp.write(Photo.string_header() + '\n') for photo in Photo.select(): fp.write(photo.to_string().encode('utf8') + '\n') #photo.to_string() + '\n'
img_path = 'data/img/%s.jpg' def calc_color(photo): img = Image.open(img_path % photo.insta_id) img.thumbnail((1, 1)) photo.color = '%d,%d,%d' % img.getpixel((0, 0)) photo.save() def remove_photo(photo): os.remove(img_path % photo.insta_id) if __name__ == "__main__": counter = 0 photos = list(Photo.select()) for photo in photos: if not os.path.isfile(img_path % photo.insta_id): r = requests.get(photo.thumb, stream=True) if r.status_code == 200: with open(img_path % photo.insta_id, 'wb') as f: r.raw.decode_content = True shutil.copyfileobj(r.raw, f) #calc_color(photo) else: print 'Cannot download %s' % photo.insta_id for pt in list(photo.tags): pt.delete_instance() photo.delete_instance() #elif photo.color == None: # calc_color(photo)
import os import shutil import settings from db import Photo,PhotoTag, Tag img_path = 'data/img/%s.jpg' new_path = 'data/no_tag/%s.jpg' if __name__ == "__main__": n = 0 for p in Photo.select().where(Photo.date >= settings.period['start']): n += 1 if n % 100 == 0: print 'processed: ' + str(n) if p.tags.count() == 0: shutil.copyfile(img_path % p.insta_id, new_path % p.insta_id,)