import re, json, subprocess, html, datetime as dt, collections
from concurrent.futures import ThreadPoolExecutor
M=[m for m in json.load(open('gg_msgs.json')) if m['author']=='David Hopwood' and ':00:00 AM' not in m['date_disp'].replace('\u202f',' ')]
ths=list(dict.fromkeys(m['thread'] for m in M))
def get(u): return subprocess.run(['curl','-s','-m','60','-A','Mozilla/5.0',u],capture_output=True,text=True).stdout
ATT=re.compile(r'(?:On\s+)?(?:[A-Z][a-z]{2},\s+)?(\d{1,2})\s+([A-Z][a-z]{2})\s+(\d{4})\s+(\d{1,2}):(\d{2})(?::(\d{2}))?\s*([+-]\d{4}|GMT|UTC|UT)\b[^\n]{0,80}?,?\s*([^\n<]{2,60}?)\s+(?:wrote|writes)')
MON={m:i for i,m in enumerate('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(),1)}
def work(t):
h=get(f'https://groups.google.com/g/sci.crypt/c/{t}'); secs=[]
for sec in re.split(r'(?=([^<]+)',sec)
b=re.search(r']*>(.*?)
',sec,re.S)
if au and d: secs.append((html.unescape(au.group(1)),d.group(1).replace('\u202f',' '),html.unescape(re.sub(r'<[^>]+>',' ',b.group(1))) if b else ''))
return t,secs
out=[]
with ThreadPoolExecutor(8) as ex:
for t,secs in ex.map(work,ths[:150]):
disp={}
for a,d,_ in secs:
try: disp.setdefault(a.split()[-1].lower(),[]).append(dt.datetime.strptime(d,'%b %d, %Y, %I:%M:%S %p'))
except: pass
for a,d,body in secs:
for m in ATT.finditer(body):
dd,mo,yy,hh,mi,ss,z,name=m.groups()
if mo not in MON: continue
off=0 if z in('GMT','UTC','UT') else (1 if z[0]=='+' else -1)*(int(z[1:3])*60+int(z[3:]))
utc=dt.datetime(int(yy),MON[mo],int(dd),int(hh),int(mi),int(ss or 0))-dt.timedelta(minutes=off)
key=name.strip().split()[-1].lower().strip('",.()<>') if name.strip() else ''
for cand in disp.get(key,[]):
diff=(cand-utc).total_seconds()/3600
if abs(diff)<15 and (ss is None or cand.second==int(ss)) and cand.minute==int(mi):
out.append(dict(thread=t,quoted_by=a,attr=m.group(0)[:100],utc=str(utc),disp=str(cand),display_minus_utc_h=diff))
json.dump(out,open('tz_matches.json','w'),indent=1)
c=collections.Counter((o['display_minus_utc_h'],o['utc'][5:7]) for o in out)
print(len(out)); print(sorted(c.items()))