|
1 | 1 | '''
|
2 | 2 | A quick sketch to demonstrate uploading library trip material.
|
3 | 3 | '''
|
| 4 | +import errno |
4 | 5 |
|
5 | 6 | import requests
|
6 | 7 | import json
|
|
25 | 26 | PASSWORD = None
|
26 | 27 |
|
27 | 28 | API_URL = "http://wikipaltz.org/api.php"
|
28 |
| -DIRECTORY = sys.argv[1] |
29 |
| - |
| 29 | +DIRECTORY = '/home/%s/Pictures/' % 'dominick' |
30 | 30 |
|
31 | 31 | # Settings
|
32 | 32 |
|
@@ -187,11 +187,14 @@ def resize(filename):
|
187 | 187 | Resizes the file to no larger than OUTPUT_SIZE x OUTPUT_SIZE
|
188 | 188 | '''
|
189 | 189 | 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 |
195 | 198 |
|
196 | 199 |
|
197 | 200 | 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):
|
378 | 381 | session = login(USERNAME, PASSWORD)
|
379 | 382 |
|
380 | 383 | for filename in os.listdir(DIRECTORY):
|
| 384 | +# try: |
| 385 | + # NOT IMPLEMENTED |
| 386 | + #if "==BLAHBLAH==" in filename: |
| 387 | + # left, right = split_vertical(filename) |
381 | 388 |
|
382 |
| - # NOT IMPLEMENTED |
383 |
| - #if "==BLAHBLAH==" in filename: |
384 |
| - # left, right = split_vertical(filename) |
385 | 389 |
|
386 | 390 |
|
387 | 391 |
|
| 392 | + # First let's split this file vertically |
388 | 393 |
|
389 |
| - # First let's split this file vertically |
| 394 | + full_path = DIRECTORY + filename |
390 | 395 |
|
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) |
408 | 397 |
|
| 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")) |
409 | 407 |
|
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]]" |
412 | 416 |
|
413 | 417 |
|
| 418 | + |
| 419 | + upload("%s-resized.jpg" % full_path, file_text, session=session).content |
| 420 | + |
| 421 | +# except IOError: |
| 422 | +# print "Hey Dumbass!" |
0 commit comments