|
Revision 561, 1.3 kB
(checked in by tim, 7 months ago)
|
|
Switch uploading to use rsync, add 308 event, fix Coastal Optical lens focal length
|
| Line | |
|---|
| 1 | import re |
|---|
| 2 | import sys |
|---|
| 3 | |
|---|
| 4 | #FIXME: http://www.photopla.net/wwp0506/index.php camera, lens, tripod!!! |
|---|
| 5 | |
|---|
| 6 | from defs import rules |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | def parseit(fn): |
|---|
| 10 | name_re = re.compile(r"^(.+?)\r?\n((?: .*\r?\n)+| FAILED)\r?\n", re.M) |
|---|
| 11 | data = file(fn, "r").read() |
|---|
| 12 | |
|---|
| 13 | # Setup parsing rule. |
|---|
| 14 | rep = [] |
|---|
| 15 | for type in rules: |
|---|
| 16 | t = [] |
|---|
| 17 | for r in type: |
|---|
| 18 | t.append((re.compile(r[0], re.I | re.M), r[1:])) |
|---|
| 19 | rep.append(t) |
|---|
| 20 | |
|---|
| 21 | # Now use 'em |
|---|
| 22 | k = ['user', 'camera', 'lens', 'panohead', 'tripod', 'software'] |
|---|
| 23 | print ",".join(k) |
|---|
| 24 | linestr = ",".join(['%%(%s)s' % i for i in k]) |
|---|
| 25 | for name in name_re.finditer(data): |
|---|
| 26 | #print name.group(1) |
|---|
| 27 | equip = name.group(2) |
|---|
| 28 | if equip.strip().startswith("FAILED"): |
|---|
| 29 | print name.group(1) |
|---|
| 30 | continue |
|---|
| 31 | me = {} |
|---|
| 32 | for i in k: me[i] = "?" |
|---|
| 33 | me['user'] = name.group(1) |
|---|
| 34 | for t in rep: |
|---|
| 35 | for r, i in t: |
|---|
| 36 | x = r.search(equip) |
|---|
| 37 | if x: |
|---|
| 38 | for a, b in i: |
|---|
| 39 | me[a] = b |
|---|
| 40 | #print " ", i, x.group(0) |
|---|
| 41 | break |
|---|
| 42 | print linestr % me |
|---|
| 43 | #"%(user)s,%(camera)s,%(lens)s,%(panohead)s,%(tripod)s,%(software)s" |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | if __name__ == "__main__": |
|---|
| 47 | parseit(sys.argv[1]) |
|---|