import json,sys,os,datetime as dt sys.path.insert(0,'tools') import sns_autopost as A from _tmp_texts_20261129 import LAB,SIM,ADAPT JST=A.JST S=json.load(open('sns/schedule.json'));P=json.load(open('sns/posted.json')) NOW='2026-11-29T08:40' def fut(e): return e['id'] not in P and e['post_at']>=NOW posts=S['posts'] removed={'x_ptm':[],'li':[]} keep=[] LABIDS=[f'{k}-x' for k in LAB]; SIMIDS=[f'{k}-x' for k in SIM]; AD=[f'{k}-x' for k in ADAPT] # 1) X @pixelstomotors: 記事の行・マンガを外し、選んだものだけ入れ直す。ショート・本編(YouTube 連動)と舞台型は残す for e in posts: if fut(e) and e['platform']=='x' and e.get('account')=='ptm': b=os.path.basename(e['source']) if b.startswith(('SHORT_','VIDEO_','BUTAI')): keep.append(e); continue if e['id'] in LABIDS+SIMIDS: continue # 入れ直す removed['x_ptm'].append(e['id']); continue if fut(e) and e['platform']=='x' and e['id'] in AD: continue if fut(e) and e['platform']=='linkedin': continue # 入れ直す keep.append(e) oldli={e['id']:e for e in posts if fut(e) and e['platform']=='linkedin'} S['posts']=keep def band(t): return 'day' if t.hour<17 else 'night' def busy_ptm(t): for e in S['posts']: if e['platform']!='x' or e.get('account')!='ptm': continue u=A.parse_time(e['post_at']).astimezone(JST) if u.date()==t.date() and band(u)==band(t): return True return False def busy_any(t): return any(e['platform']=='x' and A.parse_time(e['post_at']).astimezone(JST)==t for e in S['posts']) def slot(days, start, hours): d=start while True: if d.weekday() in days: for h,m in hours: t=dt.datetime(d.year,d.month,d.day,h,m,tzinfo=JST) if t>dt.datetime(2026,11,29,9,0,tzinfo=JST) and not busy_ptm(t): return t d+=dt.timedelta(days=1) def src(k): return f'sns/{k}_sns_posts.json' def settext(k,text,key='x'): p=src(k);raw=open(p).read();d=json.loads(raw);po=d['posts'] ind=len(raw.split('\n')[1])-len(raw.split('\n')[1].lstrip(' '));nl=raw.endswith('\n') if 'x_before_20261129' not in po: po['x_before_20261129']=po.get('x') url=d['meta'].get('url') po['x']=text+(('\n'+url) if url and k.startswith('LOG') else '') json.dump(d,open(p,'w'),ensure_ascii=False,indent=ind) if nl: open(p,'a').write('\n') start=dt.date(2026,11,30) plan=[] order_lab=['LOG567','LOG568','LOG572','LOG576','LOG580','LOG583','LOG591','LOG599','LOG600'] d=start for k in order_lab: t=slot((0,2,4),d,[(12,30),(19,30)]); settext(k,LAB[k]) S['posts'].append({'id':f'{k}-x','source':src(k),'platform':'x','post_at':t.isoformat(),'account':'ptm'}) plan.append((t,k)); d=t.date()+dt.timedelta(days=1) order_sim=['LOG423','LOG434','LOG440','LOG590','HAIZEN04','LOG477','LOG560','LOG563','LOG574','LOG585'] d=start for k in order_sim: t=slot((3,),d,[(12,30),(19,30)]); settext(k,SIM[k]) S['posts'].append({'id':f'{k}-x','source':src(k),'platform':'x','post_at':t.isoformat(),'account':'ptm'}) plan.append((t,k)); d=t.date()+dt.timedelta(days=1) # 2) @adaptdesignjp:ロボット研究の裏の AI 活用(週1本・火 19:30) d=dt.date(2026,12,8) for k in ['LOG557','LOG511','LOG528','LOG584','LOG448','LOG508','LOG559','LOG597']: while True: t=dt.datetime(d.year,d.month,d.day,19,30,tzinfo=JST) if d.weekday()==1 and not busy_any(t): break d+=dt.timedelta(days=1) settext(k,ADAPT[k]) S['posts'].append({'id':f'{k}-x','source':src(k),'platform':'x','post_at':t.isoformat(),'robot_ok':True}) plan.append((t,k+'(adapt)')); d=d+dt.timedelta(days=1) # 3) LinkedIn:週3本 so=['LOG544','LOG551','LOG556','LOG565','LOG567','LOG568','LOG572','LOG576','LOG580','LOG583','LOG591','LOG594','LOG599','LOG600'] sim=['LOG434','LOG440','LOG465','LOG477','LOG483','LOG485','LOG488','LOG491','LOG500','LOG515','LOG523','LOG526','LOG534','LOG560','LOG563','LOG564','LOG574','LOG585','LOG590'] res=[];i=j=0 while i