-
Notifications
You must be signed in to change notification settings - Fork 3
/
upload_to_appengine.py
executable file
·66 lines (54 loc) · 1.67 KB
/
upload_to_appengine.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
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
#
# Upload records which are complete to app engine.
import random
import re
import record
import fetcher
import sys
import httplib
import MultipartPostHandler, urllib2
rs = record.AllRecords()
f = fetcher.Fetcher('images', 0)
rs = [r for r in rs if (r.photo_url and f.InCache(r.photo_url))]
random.shuffle(rs)
rs = rs[0:100]
sys.stderr.write('Have %d full records\n' % len(rs))
#upload_url = 'http://localhost:8080/upload'
upload_url = 'http://sfgeocoder.appspot.com/upload'
if len(sys.argv) > 1:
upload_url = sys.argv[1]
print 'Will upload via %s' % upload_url
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
for i, r in enumerate(rs):
print '%03d Uploading %s' % (i, r.photo_id())
# Misc late-stage cleanup:
# Delete non-helpful "descriptions"
desc = r.description()
if re.match(r'^1 photographic print *: *color\.?$', desc) or \
re.match(r'^1 photographic print *: *b&w\.?$', desc):
desc = ''
# remove [] and trailing period from dates.
date = record.CleanDate(r.date())
# remove [graphic] from titles
title = record.CleanTitle(r.title())
# remove leading 'Folder: ', trailing period & convert various forms of
# dashes to a single form of slashes.
folder = r.location()
if folder: folder = record.CleanFolder(folder)
q = {
'seq_id': str(i),
'photo_id': r.photo_id(),
'title': title,
'date': date,
'folder': folder,
'description': desc,
'note': (r.note() or ''),
'library_url': r.preferred_url,
'image': open(f.CacheFile(r.photo_url), 'rb')
}
opener.open(upload_url, q)
# To clear the data store, run:
# import db
# qs = db.ImageRecord.all()
# for q in qs: q.delete()