Skip to content

Commit 6cdc218

Browse files
committed
Created a try-except block in resize function
1 parent 0ee75cd commit 6cdc218

6 files changed

+462
-30
lines changed

library_tripper_bot.py

+39-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'''
22
A quick sketch to demonstrate uploading library trip material.
33
'''
4+
import errno
45

56
import requests
67
import json
@@ -25,8 +26,7 @@
2526
PASSWORD = None
2627

2728
API_URL = "http://wikipaltz.org/api.php"
28-
DIRECTORY = sys.argv[1]
29-
29+
DIRECTORY = '/home/%s/Pictures/' % 'dominick'
3030

3131
# Settings
3232

@@ -187,11 +187,14 @@ def resize(filename):
187187
Resizes the file to no larger than OUTPUT_SIZE x OUTPUT_SIZE
188188
'''
189189
size = OUTPUT_SIZE, OUTPUT_SIZE
190-
im = Image.open(filename)
191-
im.thumbnail(size, Image.ANTIALIAS)
192-
im.save("%s-resized.jpg" % filename, "JPEG")
193-
194-
return im
190+
try:
191+
im = Image.open(filename)
192+
im.thumbnail(size, Image.ANTIALIAS)
193+
im.save("%s-resized.jpg" % filename, "JPEG")
194+
return im
195+
except IOError:
196+
pass
197+
return None
195198

196199

197200
def get_pixel_values(image, left_edge, right_edge, variance_limit=VARIANCE_LIMIT, rlimit=None, llimit=None):
@@ -378,36 +381,42 @@ def split_vertical(filename):
378381
session = login(USERNAME, PASSWORD)
379382

380383
for filename in os.listdir(DIRECTORY):
384+
# try:
385+
# NOT IMPLEMENTED
386+
#if "==BLAHBLAH==" in filename:
387+
# left, right = split_vertical(filename)
381388

382-
# NOT IMPLEMENTED
383-
#if "==BLAHBLAH==" in filename:
384-
# left, right = split_vertical(filename)
385389

386390

387391

392+
# First let's split this file vertically
388393

389-
# First let's split this file vertically
394+
full_path = DIRECTORY + filename
390395

391-
full_path = DIRECTORY + filename
392-
393-
if "==NOCR==" in filename:
394-
file_text = "[[Category:No OCR]][[Category:Uncurated Images]]"
395-
else:
396-
file_text = "==Tesseract OCR Result==\n%s\
397-
\n==Cuneiform OCR Result==\n%s\
398-
\n[[Category:Uncurated Images]][[Category:OCR]]" % (ocr_read(full_path), ocr_read(full_path, program="cuneiform"))
399-
400-
if "==PLU==" in filename:
401-
file_text += "[[Category:Human Attention Needed]]"
402-
403-
if '==SJ==' in filename:
404-
file_text += "[[Category:Social Justice]]"
405-
406-
if "==SH==" in filename:
407-
file_text += "[[Category:Student Housing]]"
396+
resized = resize(DIRECTORY + filename)
408397

398+
if not resized:
399+
continue
400+
401+
if "==NOCR==" in filename:
402+
file_text = "[[Category:No OCR]][[Category:Uncurated Images]]"
403+
else:
404+
file_text = "==Tesseract OCR Result==\n%s\
405+
\n==Cuneiform OCR Result==\n%s\
406+
\n[[Category:Uncurated Images]][[Category:OCR]]" % (ocr_read(full_path), ocr_read(full_path, program="cuneiform"))
409407

410-
resize(DIRECTORY + filename)
411-
upload("%s-resized.jpg" % full_path, file_text, session=session).content
408+
if "==PLU==" in filename:
409+
file_text += "[[Category:Human Attention Needed]]"
410+
411+
if '==SJ==' in filename:
412+
file_text += "[[Category:Social Justice]]"
413+
414+
if "==SH==" in filename:
415+
file_text += "[[Category:Student Housing]]"
412416

413417

418+
419+
upload("%s-resized.jpg" % full_path, file_text, session=session).content
420+
421+
# except IOError:
422+
# print "Hey Dumbass!"

library_tripper_bot.pyc

10.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)