changeset 4:2d7c91f89f6b

later ecclerig version
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 09 Mar 2020 17:38:52 +0000
parents 26d9c0308fcf
children bd1db1ed4c25
files mailer.py pdfCrawl.py trip2xml.py
diffstat 3 files changed, 27 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/mailer.py	Mon Mar 09 17:35:28 2020 +0000
+++ b/mailer.py	Mon Mar 09 17:38:52 2020 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 '''Attempt at flexible mailout functionality
-Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* -SA file[,file]* COLSPEC[,COLSPEC]* subject {addr-file|-} body-file
+Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* [-SA file[,file]*] [-R reply-to] COLSPEC[,COLSPEC]* subject {addr-file|-} body-file
 
 Sends the body as a message from me with subject to destinations per
 lines in the addr-file selected by COLSPECs (to:) or -c/-b COLSPECs (Cc:/Bcc:)
@@ -17,6 +17,7 @@
 -s for substitute into body
 -S for columns to substitute as such
 -p for augmentation pattern for a column
+-R for replyTo address
 
 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv
   a gives the column for an email address
@@ -247,8 +248,11 @@
   msg.attach(atm)
 
 dryrun=False
+replyTo=None
+
 sys.argv.pop(0)
 doSub=False
+
 pats=[]
 someExpand=False
 codec='iso-8859-1'
@@ -318,6 +322,12 @@
       pats.append(sys.argv.pop(0))
     else:
       usage('pat')
+  elif sys.argv[0]=='-R':
+    sys.argv.pop(0)
+    if sys.argv:
+      replyTo=sys.argv.pop(0)
+    else:
+      usage('reply to')
   elif sys.argv[0][0]=='-':
     print sys.argv
     usage()
@@ -406,8 +416,11 @@
   if attCols:
     for att in addrList(addrFields,attCols,True):
       doAtt(msg,att,codec)
+  if replyTo is not None:
+    msg["Reply-To"]=replyTo
   if dryrun:
     print recips
+    print msg.keys()
     print msg.as_string()
     exit()
   print "mailing to %s"%recips
--- a/pdfCrawl.py	Mon Mar 09 17:35:28 2020 +0000
+++ b/pdfCrawl.py	Mon Mar 09 17:38:52 2020 +0000
@@ -1,11 +1,5 @@
 import PyPDF2 as pyPdf, sys
 
-if sys.argv[1]=='-v':
-    verbose=True
-    sys.argv.pop(1)
-else:
-    verbose=False
-
 f = open(sys.argv[1],'rb')
 
 pdf = pyPdf.PdfFileReader(f)
@@ -20,13 +14,16 @@
     print '#',pg
     p = pdf.getPage(pg)
     o = p.getObject()
-    #print >>sys.stderr,o
+    print o
     if o.has_key(key):
         ann = o[key]
-        #print >>sys.stderr,key,ann
+        print key,len(ann),ann
+        i=0
         for a in ann:
             u = a.getObject()
-            if ank in u and uri in u[ank]:
-                if verbose:
-                    print u[ank]
-                print u[ank][uri]
+            if u[ank].has_key(uri):
+                try:
+                    print i,u[ank][uri]
+                except UnicodeEncodeError:
+                    print i,map(ord,u[ank][uri])
+            i+=1
--- a/trip2xml.py	Mon Mar 09 17:35:28 2020 +0000
+++ b/trip2xml.py	Mon Mar 09 17:38:52 2020 +0000
@@ -15,13 +15,11 @@
   def __init__(self):
     self.flights=[]
     self.p1=False
-    self.dd=None
 
   def addFlight(self,flight):
     self.flights.append(flight)
 
   def setDD(self,m):
-    print 'sdd'
     td="%s-%s-%s"%(year,m.group(2),m.group(1))
     self.ddate=datetime.datetime.strptime(td,"%Y-%B-%d").date()
     self.dd=self.ddate.isoformat()
@@ -31,7 +29,6 @@
       self.ads=""
 
   def setPlusOne(self):
-    print 'p1'
     self.p1=True
 
   def __str__(self):
@@ -57,8 +54,6 @@
   def setArr(self,ax):
     ass=ax.split('|')
     self.at=ass[0][:2]+ass[0][3:5]
-    if (ass[0].find('(+1 day)')==6):
-      self.at+="+1"
     self.ta=ass[1].split()[-1]
     
 print "<list type='defn'>"
@@ -72,12 +67,10 @@
     fl=Flight(m.group(1))
     cleg.addFlight(fl)
     continue
-  if ((cleg is not None) and
-      (cleg.dd is None)):
-    m=duration.search(l)
-    if m:
-      cleg.setDD(m)
-      continue
+  m=duration.search(l)
+  if m:
+    cleg.setDD(m)
+    continue
   m=plusOne.search(l)
   if m:
     cleg.setPlusOne()