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
    goto :HEREYESTART


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     --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
   %PTH%\wget.exe https://complex.com     --tries=2 --waitretry=2 --connect-timeout=5 --read-timeout=5 -O %CITY%-complex-stories.txt -o %CITY%-complex-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/entertainment
   %PTH%\wget.exe https://bet.com/entertainment    --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     --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  -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
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-complex-stories.txt  -F -B https://complex.com  -o %CITY%-complex-urls.txt -O %CITY%-complex-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/entertainment
	%PTH%\wget --tries=1 --read-timeout=5 -nv -i %CITY%-bet-stories.txt  -F -B https://bet.com/entertainment  -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  -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%-suntimes-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --xxlmag--
grep xxlmag.com %CITY%-suntimes-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --bet--
grep bet.com/entertainment %CITY%-suntimes-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     %CITY%-urls.txt   >> pick-%CITY%-stories-to-post.txt

rem --theyoungturks--
grep theyoungturks.com %CITY%-suntimes-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

rem set url=https://site.com/pass-me-to-url-below-as-value1-and-loop-to-post-more
curl -X POST --ssl-no-revoke https://maker.ifttt.com/trigger/post-podwire-to-facebook/with/key/%iftttKey%?value1=
:BACKUP
echo Go Find Stories to Post