def get_photo_from_file(self,filepath): fin = open(filepath,'r') photos = [] photo = Photo() for line in fin: items = line.split(':', 1) key = items[0].strip() if(len(items)>1): value = items[1].strip() if(key=='ID'): photo = Photo() photo.photoId = value if(key=='owner'): photo.ownerId = value if(key=='tags'): value = value.split(',') photo.tags = [] for v in value: v = v.strip() keep = 0 for c in v: if(c>='a' and c<='z' or c>='A' and c<='Z'): keep = 1 else: keep = 0 break if (keep): photo.tags.append(v) if(key=='url'): photo.url = value; if(key=='datetaken'): value = value.split(' ') photo.datetaken = value[0].strip(); if (len(value) > 1): photo.timetaken = value[1].strip(); if(key=='secret'): photo.secret = value if(key=='farm'): photo.farm = value if(key=='url_s'): photo.url_s = value if(key=='url_q'): photo.url_q = value if(key=='url_t'): photo.url_t = value if(key=='url_m'): photo.url_m = value if(key=='url_z'): photo.url_z = value if(key=='url_b'): photo.url_b = value if(len(key)==0): if(self.is_valid_photo(photo)): photos.append(photo) return photos
def getPhotoFromFile(self,filepath): fin = open(filepath,'r') photo = Photo() for line in fin: items = line.split(':', 1) key = items[0].strip() if(len(items)>1): value = items[1].strip() if(key=='ID'): photo = Photo() photo.photoId = value if(key=='owner'): photo.ownerId = value if(key=='tags'): value = value.split(',') photo.tags = [] for v in value: v = v.strip() if(len(v)>30): continue; if(v>='a' and v<='z' or v>='A' and v<='Z'): photo.tags.append(v) if(key=='url'): photo.url = value; if(key=='datetaken'): value = value.split(' '); photo.datetaken = value[0].strip(); if (len(value) > 1): photo.timetaken = value[1].strip(); if(key=='secret'): photo.secret = value if(key=='farm'): photo.farm = value if(key=='url_s'): photo.url_s = value if(key=='url_q'): photo.url_q = value if(key=='url_t'): photo.url_t = value if(key=='url_m'): photo.url_m = value if(key=='url_z'): photo.url_z = value if(key=='url_b'): photo.url_b = value return photo