echo off

setlocal
setlocal enabledelayedexpansion


set DRIVE=E:
set CITY=podwire
set PTH=%DRIVE%\CRIME-WATCH-%CITY%
cd WIP

set iftttKey=dqoV39DfD26Szyfh0ojhhd

rem goto :HERE
rem goto :HEREYESTART

:LOOPBACK
echo Find new PODWIRE stories to post

if "%CITY%" == "podwire" (
   rem USE wget.exe to get source for podwire news links
   echo PASS1 - Processing 1 of 18 - thebreakfastclub.iheart.com
   %PTH%\wget.exe https://thebreakfastclub.iheart.com --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-iheart-stories.txt -o %CITY%-iheart-logfile.txt
   
   echo PASS1 - Processing 2 of 18 - drinkchamps.com   
   %PTH%\wget.exe https://drinkchamps.com --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-drinkchamps-stories.txt -o %CITY%-drinkchamps-logfile.txt
   
   echo PASS1 - Processing 3 of 18 - stevenbartlett.com/doac
   %PTH%\wget.exe https://stevenbartlett.com/doac  --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-stevenbartlett-stories.txt  -o %CITY%-stevenbartlett-logfile.txt
   
   echo PASS1 - Processing 4 of 18 - elliseverafter.com
   %PTH%\wget.exe https://elliseverafter.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-elliseverafter-stories.txt -o %CITY%-elliseverafter-logfile.txt
      
   echo PASS1 - Processing 5 of 18 - tmz.com
   %PTH%\wget.exe https://tmz.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-tmz-stories.txt -o %CITY%-tmz-logfile.txt
      
   echo PASS1 - Processing 5A of 18 - tmz.com/hip-hop
   %PTH%\wget.exe https://tmz.com/hip-hop     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-tmz-hip-hop-stories.txt -o %CITY%-tmz-hip-hop-logfile.txt
      
   echo PASS1 - Processing 5B of 18 - tmz.com/deals
   %PTH%\wget.exe https://tmz.com/deals     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-tmz-deals-stories.txt -o %CITY%-tmz-deals-logfile.txt
   
   echo PASS1 - Processing 6 of 18 - theshaderoom.com
   %PTH%\wget.exe https://theshaderoom.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-theshaderoom-stories.txt -o %CITY%-theshaderoom-logfile.txt
      
   echo PASS1 - Processing 7 of 18 - hollywoodreporter.com
   %PTH%\wget.exe https://hollywoodreporter.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-hollywoodreporter-stories.txt -o %CITY%-hollywoodreporter-logfile.txt
      
   echo PASS1 - Processing 8 of 18 - variety.com
   %PTH%\wget.exe https://variety.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-variety-stories.txt -o %CITY%-variety-logfile.txt
      
   echo PASS1 - Processing 9 of 18 - pagesix.com
   %PTH%\wget.exe https://pagesix.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-pagesix-stories.txt -o %CITY%-pagesix-logfile.txt
      
   echo PASS1 - Processing 10 of 18 - people.com
   %PTH%\wget.exe https://people.com/celebrity     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-people-stories.txt -o %CITY%-people-logfile.txt
      
   echo PASS1 - Processing 11 of 18 - etonline.com
   %PTH%\wget.exe https://etonline.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-etonline-stories.txt -o %CITY%-etonline-logfile.txt
      
   echo PASS1 - Processing 12 of 18 - eonline.com
   %PTH%\wget.exe https://eonline.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-eonline-stories.txt -o %CITY%-eonline-logfile.txt
      
   echo PASS1 - Processing 13 of 18 - complex.com/style
   %PTH%\wget.exe https://complex.com/style     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-complex-style-stories.txt -o %CITY%-complex-style-logfile.txt
   
   echo PASS1 - Processing 13A of 18 - complex.com/music
   %PTH%\wget.exe https://complex.com/music     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-complex-music-stories.txt -o %CITY%-complex-music-logfile.txt
   
   echo PASS1 - Processing 13B of 18 - complex.com/pop-culture
   %PTH%\wget.exe https://complex.com/pop-culture     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-complex-pop-culture-stories.txt -o %CITY%-complex-pop-culture-logfile.txt
            
   echo PASS1 - Processing 14 of 18 - xxlmag.com
   %PTH%\wget.exe https://xxlmag.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-xxlmag-stories.txt -o %CITY%-xxlmag-logfile.txt
      
   echo PASS1 - Processing 15 of 18 - bet.com/shows
   %PTH%\wget.exe https://bet.com/shows    --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-bet-stories.txt -o %CITY%-bet-logfile.txt
      
   echo PASS1 - Processing 16 of 18 - bossip.com
   %PTH%\wget.exe https://bossip.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-bossip-stories.txt -o %CITY%-bossip-logfile.txt
      
   echo PASS1 - Processing 17 of 18 - 85southshow.com
   %PTH%\wget.exe https://85southshow.com/portfolio     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-85southshow-stories.txt -o %CITY%-85southshow-logfile.txt
      
   echo PASS1 - Processing 18 of 18 - theyoungturks.com
   %PTH%\wget.exe https://theyoungturks.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-theyoungturks-stories.txt -o %CITY%-theyoungturks-logfile.txt
   
   echo ----------------------------------------------

   rem use wget.exe to search for chicago news links
   echo PASS2 - Processing 1 of 18 - thebreakfastclub.iheart.com
   %PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-iheart-stories.txt -F -B https://thebreakfastclub.iheart.com -o %CITY%-iheart-urls.txt -O %CITY%-iheart-urls-logfile.txt --spider

	echo PASS2 - Processing 2 of 18 - drinkchamps.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-drinkchamps-stories.txt    -F -B https://drinkchamps.com -o %CITY%-drinkchamps-urls.txt -O %CITY%-drinkchamps-urls-logfile.txt --spider

	echo PASS2 - Processing 3 of 18 - stevenbartlett.com/doac 
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-stevenbartlett-stories.txt    -F -B https://stevenbartlett.com/doac  -o %CITY%-stevenbartlett-urls.txt  -O %CITY%-stevenbartlett-urls-logfile.txt --spider

	echo PASS2 - Processing 4 of 18 - elliseverafter.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-elliseverafter-stories.txt  -F -B https://elliseverafter.com  -o %CITY%-elliseverafter-urls.txt -O %CITY%-elliseverafter-urls-logfile.txt --spider

	echo PASS2 - Processing 5 of 18 - tmz.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-tmz-stories.txt  -F -B https://tmz.com  -o %CITY%-tmz-urls.txt -O %CITY%-tmz-urls-logfile.txt --spider

	echo PASS2 - Processing 5A of 18 - tmz.com/hip-hop
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-tmz-stories.txt  -F -B https://tmz.com/hip-hop  -o %CITY%-tmz-hip-hop-urls.txt -O %CITY%-tmz-hip-hop-urls-logfile.txt --spider

	echo PASS2 - Processing 5B of 18 - tmz.com/deals
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-tmz-deals-stories.txt  -F -B https://tmz.com/deals  -o %CITY%-tmz-deals-urls.txt -O %CITY%-tmz-deals-urls-logfile.txt --spider
	
	echo PASS2 - Processing 6 of 18 - theshaderoom.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-theshaderoom-stories.txt  -F -B https://theshaderoom.com  -o %CITY%-theshaderoom-urls.txt -O %CITY%-theshaderoom-urls-logfile.txt --spider
	
	echo PASS2 - Processing 7 of 18 - hollywoodreporter.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-hollywoodreporter-stories.txt  -F -B https://hollywoodreporter.com  -o %CITY%-hollywoodreporter-urls.txt -O %CITY%-hollywoodreporter-urls-logfile.txt --spider
	
	echo PASS2 - Processing 8 of 18 - variety.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-variety-stories.txt  -F -B https://variety.com  -o %CITY%-variety-urls.txt -O %CITY%-variety-urls-logfile.txt --spider
	
	echo PASS2 - Processing 9 of 18 - pagesix.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-pagesix-stories.txt  -F -B https://pagesix.com  -o %CITY%-pagesix-urls.txt -O %CITY%-pagesix-urls-logfile.txt --spider
	
	echo PASS2 - Processing 10 of 18 - people.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-people-stories.txt  -F -B https://people.com/celebrity   -o %CITY%-people-urls.txt -O %CITY%-people-urls-logfile.txt --spider
	
	echo PASS2 - Processing 11 of 18 - etonline.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-etonline-stories.txt  -F -B https://etonline.com  -o %CITY%-etonline-urls.txt -O %CITY%-etonline-urls-logfile.txt --spider
	
	echo PASS2 - Processing 12 of 18 - eonline.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-eonline-stories.txt  -F -B https://eonline.com  -o %CITY%-eonline-urls.txt -O %CITY%-eonline-urls-logfile.txt --spider
	
	echo PASS2 - Processing 13 of 18 - complex.com/style
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-complex-style-stories.txt  -F -B https://complex.com/style  -o %CITY%-complex-style-urls.txt -O %CITY%-complex-style-urls-logfile.txt --spider
	
	echo PASS2 - Processing 13A of 18 - complex.com/music
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-complex-music-stories.txt  -F -B https://complex.com/music  -o %CITY%-complex-music-urls.txt -O %CITY%-complex-music-urls-logfile.txt --spider
	
	echo PASS2 - Processing 13B of 18 - complex.com/pop-culture
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-complex-pop-culture-stories.txt  -F -B https://complex.com/pop-culture  -o %CITY%-complex-pop-culture-urls.txt -O %CITY%-complex-pop-culture-urls-logfile.txt --spider
	
	echo PASS2 - Processing 14 of 18 - xxlmag.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-xxlmag-stories.txt  -F -B https://xxlmag.com  -o %CITY%-xxlmag-urls.txt -O %CITY%-xxlmag-urls-logfile.txt --spider
	
	echo PASS2 - Processing 15 of 18 - bet.com/shows
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-bet-stories.txt  -F -B https://bet.com/shows  -o %CITY%-bet-urls.txt -O %CITY%-bet-urls-logfile.txt --spider
	
	echo PASS2 - Processing 16 of 18 - bossip.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-bossip-stories.txt  -F -B https://bossip.com  -o %CITY%-bossip-urls.txt -O %CITY%-bossip-urls-logfile.txt --spider
	
	echo PASS2 - Processing 17 of 18 - 85southshow.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-85southshow-stories.txt  -F -B https://85southshow.com/portfolio  -o %CITY%-85southshow-urls.txt -O %CITY%-85southshow-urls-logfile.txt --spider
	
	echo PASS2 - Processing 18 of 18 - theyoungturks.com
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-theyoungturks-stories.txt  -F -B https://theyoungturks.com  -o %CITY%-theyoungturks-urls.txt -O %CITY%-theyoungturks-urls-logfile.txt --spider
		
)

:HEREYESTART
rem filter out url links for %CITY% news sites
cat %CITY%-*-urls.txt  >  %CITY%-urls.txt
grep news                 %CITY%-urls.txt  > pick-%CITY%-stories-to-post.txt

rem --thebreakfastclub--
grep thebreakfastclub.com %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --drinkchamps--
grep drinkchamps.com     %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --stevenbartlett--
grep stevenbartlett.news %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --elliseverafter--
grep elliseverafter.com  %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --tmz--
rem grep tmz.com         %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
    grep tmz.com/2025    %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
	grep tmz.com/hip-hop %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
    grep tmz.com/deals   %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt


rem --theshaderoom--
grep theshaderoom.com    %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --hollywoodreporter--
grep hollywoodreporter.com %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --variety--
    grep variety.com        %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
rem grep variety.com/2025   %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt


rem --pagesix--
rem grep pagesix.com       %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
    grep pagesix.com/2025  %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt
    grep pagesix.com/style %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt


rem --people--
grep people.com   %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --etonline--
grep etonline.com %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --eonline--
grep eonline.com %CITY%-urls.txt >> pick-%CITY%-stories-to-post.txt

rem --complex--
grep complex.com/sports %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --xxlmag--
grep xxlmag.com %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --bet--
grep bet.com/shows %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --bossip-- 
grep bossip.com              %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt
rem grep bossip.com/3        %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt
rem grep bossip-categories   %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --85southshow--
grep 85southshow.com/new-blog/2025  %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --theyoungturks--
grep theyoungturks.com %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem get rid of duplicate url links
cat pick-%CITY%-stories-to-post.txt | sort /m 500 /unique > sorted-%CITY%-stories-to-post.txt

rem remove URL: tag and create list of links to post
if exist %CITY%-temp-urls.txt del %CITY%-temp-urls.txt
for /f "tokens=4" %%a in ('type sorted-%CITY%-stories-to-post.txt') do (
 echo %%a >> %CITY%-temp-urls.txt
)

rem sort and remove duplicates one last time
rem cat %CITY%-temp-urls.txt | sort /m 800 /unique > %CITY%-final-urls-list.txt


copy %CITY%-temp-urls.txt junk-%CITY%-temp-urls.txt
cat %CITY%-temp-urls.txt > remove-duplicates.txt
sort /m 800 /unique remove-duplicates.txt /O %CITY%-final-urls-list.txt
rem determine specifically which stories to post
%PTH%\unix\bin\fgrep -f %PTH%\fgrep-input.txt %CITY%-final-urls-list.txt >post-these-%CITY%-urls.txt

rem :START-HERE
rem post stories to facebook and twitter

echo REMOVE PREVIOUSLY POSTED STORIES

:HERE

rem gather all previously posted stories
if not exist backup\post-these-seed.txt echo previously-posted-stories > backup\post-these-seed.txt
rem cat backup/post-these-* | sort /m 500 /unique > previously-posted-%CITY%-stories.txt

cat backup/post-these-* > post-these.txt
sort /m 800 /unique post-these.txt /O previously-posted-%CITY%-stories.txt
rem remove stories that have already been posted
rem report any line in post-these-%CITY% urls.txt that isn't present in previously-posted-stories.txt
findstr /i /L /x /v  /g:previously-posted-%CITY%-stories.txt post-these-%CITY%-urls.txt > post-these-unique-%CITY%-urls.txt

rem --- BEGIN --- added Friday 01-17-20 reset twitter counter around midnight
		  set current-time=!time:~0,2!!time:~3,2!
          echo current-time= !current-time!
          echo reset-time  = !reset-time!
          rem reset counter if current-time is GE reset-time
          if !current-time! GEQ !reset-time! set /a numtwposted=0 & set /a numtwnposted=0	 
rem --- END --- added Thursday 01-17-20 reset twitter counter around midnight
 
copy post-these-detroit-urls.txt junk-post-these-detroit-urls.txt
copy post-these-unique-%CITY%-urls.txt junk-post-these-unique-%CITY%-urls.txt
copy previously-posted-%CITY%-stories.txt junk-previously-posted-%CITY%-stories.txt
ls -l post-these.txt 
ls -l previously-posted-%CITY%-stories.txt 
ls -l post-these-%CITY%-urls.txt
ls -l post-these-unique-%CITY%-urls.txt
rem check if any stories should be posted
set fsize="NOT-ZERO"
for %%a in ("post-these-unique-%CITY%-urls.txt") do if %%~za == 0  set fsize="ZERO"
rem echo %fsize%
if %fsize% == "ZERO" (
  echo No Stories To Post At This Time
  if exist email-twitter-links-to-kim.txt del email-twitter-links-to-kim.txt
  if exist mcd-stories-to-post.txt del mcd-stories-to-post.txt
  echo .  
  goto :BACKUP
 )
rem Found new stories to post ... but first change order of lines in the file
if exist post-these-unique-random-%CITY%-urls.txt del post-these-unique-random-%CITY%-urls.txt
for /f "delims=" %%q in (post-these-unique-%CITY%-urls.txt) do call set "$$%%random%%=%%q"
(for /f "tokens=1,* delims==" %%a in ('set $$') do echo(%%b)>post-these-unique-random-%CITY%-urls-temp.txt

rem ========================
rem remove addtl duplicated stories that have already been posted ... something is wrong with randomizer ... use this as a workaround
cat backup/post-these-* | sort /m 500 /unique > already-posted.txt
cat post-these-unique-random-%CITY%-urls-temp.txt > tobe-posted.txt
findstr /i /L /x /v  /g:already-posted.txt tobe-posted.txt > post-these-unique-random-%CITY%-urls.txt 
rem =======================

for /f %%C in ('find /V /C "" ^< post-these-unique-random-%CITY%-urls.txt') do set total-to-post=%%C
echo Found %total-to-post% new stories to post
echo .

if exist mcd-stories-to-post.txt del mcd-stories-to-post.txt
echo START POSTING STORIES
date /T & time /T

echo off
echo .
echo .
setlocal
setlocal enabledelayedexpansion

set "tmeout=%1"
if "%tmeout%" == "" (
    echo set default timeout to 120 seconds
    set /a tmeout=120
)
echo timeout = %tmeout% seconds

rem loop through post post-these-unique-random-podwire-urls.txt and post to FB page

echo it is time to start posting podwire stories
echo .
echo .

for /f "tokens=* delims=" %%g in ('type post-these-unique-random-podwire-urls.txt') do (

     set podStory=%%g
     rem echo podStory=!podStory!

     set fsize="NOT-ZERO"
     rem echo fsize=!fsize!

     rem check if story should be skipped
     echo !podStory:~0,70! | findstr "bossip.com\/wp-content"  > skip-podStory.txt
	 echo !podStory:~0,70! | findstr "bossip-interviews"      >> skip-podStory.txt
     rem ls -ltr skip-podStory.txt
     echo .
     rem type  skip-podStory.txt


     for %%t in ("skip-podStory.txt") do (if %%~zt == 0 set fsize="ZERO")
     rem echo fsize=!fsize!
     if !fsize! == "NOT-ZERO" (
	    echo DO NOT POST THIS STORY - !podStory!
     )ELSE (
        echo Posting podwire-story  - !podStory!
        curl -X POST --ssl-no-revoke https://maker.ifttt.com/trigger/post-podwire-to-facebook/with/key/%iftttKey%?value1=!podStory!

        echo .
        echo .
        echo wait %tmeout% seconds before posting next story
        timeout /t %tmeout%
        echo .
        echo .	 	 
	 )
)

:BACKUP
rem save backup file of posted stories
rem Mon 12/16/2019 vs 12/16/2019
rem 18:44:13.78    vs 18441378
set dte=%date:~4,2%-%date:~7,2%-%date:~10,4%
set tme=%time:~1,1%%time:~3,2%%time:~6,2%%time:~9,2%
rem 
set bkup=backup\post-these-unique-%CITY%-urls-%dte%-%tme%.txt
echo saved-backup-of-posted-stories-in -- %bkup%
echo .
rem copy posted-these-unique-%CITY%-urls.txt post-these-unique-%CITY%-urls.txt 
echo reverse contents of file post-these-unique-%CITY%-urls.txt
reverse /I post-these-unique-%CITY%-urls.txt > reverse-pt-unique-urls-out.txt
copy post-these-unique-%CITY%-urls.txt %bkup%

echo wait 30 minutes before starting search for new podwire stories
timeout /t 1800

echo Go find new PODWIRE Stories to post
goto :LOOPBACK


