forked from rho_n/hpr_generator
		
	Merge pull request 'fix3_next_available_episode' (#176) from fix3_next_available_episode into main
Reviewed-on: rho_n/hpr_generator#176
This commit is contained in:
		@@ -30,13 +30,22 @@
 | 
				
			|||||||
    </header>
 | 
					    </header>
 | 
				
			||||||
	<!--% days_till_next_episode = 0 %-->
 | 
						<!--% days_till_next_episode = 0 %-->
 | 
				
			||||||
	<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
 | 
						<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
 | 
				
			||||||
	<!--% FOREACH next_available_episode_result IN DBI.query(query_next_available_episode) %-->
 | 
					 | 
				
			||||||
	<!--% days_till_next_episode = next_available_episode_result.delta_days %-->
 | 
					 | 
				
			||||||
	<!--% END %-->
 | 
					 | 
				
			||||||
	<!--% USE date %-->
 | 
						<!--% USE date %-->
 | 
				
			||||||
	<!--% calc = date.calc %-->
 | 
						<!--% calc = date.calc %-->
 | 
				
			||||||
 | 
						<!--% episodes = DBI.query("SELECT id, date FROM eps WHERE date >= date('now') ORDER BY id").get_all() %-->
 | 
				
			||||||
 | 
						<!--% ind = episodes.0.id %-->
 | 
				
			||||||
 | 
						<!--% FOREACH ep IN episodes %-->
 | 
				
			||||||
 | 
						<!--%     LAST IF ep.id != ind %-->
 | 
				
			||||||
 | 
						<!--%     last_date = ep.date.split('-') %-->
 | 
				
			||||||
 | 
						<!--%     ind = ind+1 %-->
 | 
				
			||||||
 | 
						<!--% END %-->
 | 
				
			||||||
 | 
						<!--% offset = (calc.Day_of_Week(last_date.0,last_date.1,last_date.2) == 5 ? 3 : 1) %-->
 | 
				
			||||||
 | 
						<!--% slot_date = calc.Add_Delta_Days(last_date.0,last_date.1,last_date.2,offset) %-->
 | 
				
			||||||
 | 
						<!--% now = calc.Today() %-->
 | 
				
			||||||
 | 
						<!--% days_till_next_episode = calc.Delta_Days(now.0,now.1,now.2,slot_date.0,slot_date.1,slot_date.2) %-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	<!--% delta = date.calc.N_Delta_YMD(2005,9,19, date.format(date.now, '%Y'),date.format(date.now, '%m'),date.format(date.now, '%d')) %-->
 | 
						<!--% delta = date.calc.N_Delta_YMD(2005,9,19, date.format(date.now, '%Y'),date.format(date.now, '%m'),date.format(date.now, '%d')) %-->
 | 
				
			||||||
	<p>We started producing shows as <a href="<!--% absolute_path(baseurl) %-->eps/index.html#twat_episodes"><em>Today with a Techie</em></a> on 2005-09-19, <!--% delta.0 %--> years, <!--% delta.1 %--> months, <!--% delta.2 %--> days ago. our shows are produced by <a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">listeners</a> like you and can be on any <a href="<!--% absolute_path(baseurl) %-->eps/index.html">topic</a> that <strong>"are of interest to <a href="https://en.wikipedia.org/wiki/hacker_(hobbyist)">hackers</a>"</strong>. If you listen to HPR then please consider contributing one show a year. if you <a href="<!--% absolute_url(baseurl) %-->about.html#so_you_want_to_record_a_podcast">record</a> your show now it could be <a href="<!--% hub_baseurl %-->calendar.php">released</a> in <strong><!--% days_till_next_episode %--></strong> days.</p>
 | 
						<p>We started producing shows as <a href="<!--% absolute_path(baseurl) %-->eps/index.html#twat_episodes"><em>Today with a Techie</em></a> on 2005-09-19, <!--% delta.0 %--> years, <!--% delta.1 %--> months, <!--% delta.2 %--> days ago. Our shows are produced by <a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">listeners</a> like you and can be on any <a href="<!--% absolute_path(baseurl) %-->eps/index.html">topics</a> that <strong>"are of interest to <a href="https://en.wikipedia.org/wiki/hacker_(hobbyist)">hackers</a>"</strong>. If you listen to HPR then please consider contributing one show a year. If you <a href="<!--% absolute_url(baseurl) %-->about.html#so_you_want_to_record_a_podcast">record</a> your show now it could be <a href="<!--% hub_baseurl %-->calendar.php">released</a> in <strong><!--% days_till_next_episode %--></strong> days.</p>
 | 
				
			||||||
  </article>
 | 
					  </article>
 | 
				
			||||||
  <!--% display_call_for_shows() %-->
 | 
					  <!--% display_call_for_shows() %-->
 | 
				
			||||||
  <hr>
 | 
					  <hr>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,33 +1,3 @@
 | 
				
			|||||||
<!--% query_next_available_episode = '
 | 
					 | 
				
			||||||
    WITH RECURSIVE
 | 
					 | 
				
			||||||
    min_id AS (
 | 
					 | 
				
			||||||
	SELECT max(id) AS start_id FROM eps WHERE date <= NOW()
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    max_id AS (
 | 
					 | 
				
			||||||
	SELECT max(id) AS end_id FROM eps
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    cnt(x) AS (
 | 
					 | 
				
			||||||
	SELECT start_id from min_id
 | 
					 | 
				
			||||||
	UNION ALL
 | 
					 | 
				
			||||||
	SELECT x+1 FROM cnt
 | 
					 | 
				
			||||||
	WHERE x+1 <= (SELECT end_id FROM max_id)
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    first_empty AS (
 | 
					 | 
				
			||||||
	SELECT
 | 
					 | 
				
			||||||
	    cnt.x AS id
 | 
					 | 
				
			||||||
	FROM cnt
 | 
					 | 
				
			||||||
	LEFT JOIN eps e ON cnt.x = e.id
 | 
					 | 
				
			||||||
	WHERE e.id IS NULL
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    SELECT
 | 
					 | 
				
			||||||
	fe.id as next_id,
 | 
					 | 
				
			||||||
	(SELECT DATE(ADDDATE(e2.date,1)) from eps e2 where e2.id = fe.id-1) as next_date,
 | 
					 | 
				
			||||||
	DATEDIFF((SELECT ADDDATE(e3.date,1) from eps e3 where e3.id = fe.id-1),now()) AS delta_days
 | 
					 | 
				
			||||||
    FROM first_empty AS fe
 | 
					 | 
				
			||||||
    LEFT JOIN eps e1 ON fe.id = e1.id
 | 
					 | 
				
			||||||
    LIMIT 1
 | 
					 | 
				
			||||||
'
 | 
					 | 
				
			||||||
%-->
 | 
					 | 
				
			||||||
<!--% query_latest_episodes = '
 | 
					<!--% query_latest_episodes = '
 | 
				
			||||||
	WITH comment_tallies AS (
 | 
						WITH comment_tallies AS (
 | 
				
			||||||
		SELECT
 | 
							SELECT
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,33 +1,3 @@
 | 
				
			|||||||
<!--% query_next_available_episode = '
 | 
					 | 
				
			||||||
    WITH RECURSIVE
 | 
					 | 
				
			||||||
    min_id AS (
 | 
					 | 
				
			||||||
	SELECT max(id) AS start_id FROM eps WHERE date <= date(\'now\')
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    max_id AS (
 | 
					 | 
				
			||||||
	SELECT max(id) AS end_id FROM eps
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    cnt(x) AS (
 | 
					 | 
				
			||||||
	SELECT start_id from min_id
 | 
					 | 
				
			||||||
	UNION ALL
 | 
					 | 
				
			||||||
	SELECT x+1 FROM cnt
 | 
					 | 
				
			||||||
	WHERE x+1 <= (SELECT end_id FROM max_id)
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    first_empty AS (
 | 
					 | 
				
			||||||
	SELECT
 | 
					 | 
				
			||||||
	    cnt.x AS id
 | 
					 | 
				
			||||||
	FROM cnt
 | 
					 | 
				
			||||||
	LEFT JOIN eps e ON cnt.x = e.id
 | 
					 | 
				
			||||||
	WHERE e.id IS NULL
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    SELECT
 | 
					 | 
				
			||||||
	fe.id as next_id,
 | 
					 | 
				
			||||||
	(SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1) as next_date,
 | 
					 | 
				
			||||||
	printf(\'%i\',abs(julianday((SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1)) - julianday(\'now\') + 1)) AS delta_days
 | 
					 | 
				
			||||||
    FROM first_empty AS fe
 | 
					 | 
				
			||||||
    LEFT JOIN eps e ON fe.id = e.id
 | 
					 | 
				
			||||||
    LIMIT 1
 | 
					 | 
				
			||||||
'
 | 
					 | 
				
			||||||
%-->
 | 
					 | 
				
			||||||
<!--% query_latest_episodes = '
 | 
					<!--% query_latest_episodes = '
 | 
				
			||||||
	WITH comment_tallies AS (
 | 
						WITH comment_tallies AS (
 | 
				
			||||||
		SELECT
 | 
							SELECT
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user