Added date field extract.

This commit is contained in:
Christian P. MOMON 2019-04-13 03:52:23 +02:00 committed by Christian P. MOMON
parent 0feb10ba0f
commit d383c03258
1 changed files with 35 additions and 22 deletions

View File

@ -19,7 +19,7 @@
# Configuration.
login="april-cc"
tmpPrefix="/tmp/ccfmstat-"
tmpPrefix="/tmp/ccfmstat"
# ############################################
help()
@ -54,19 +54,18 @@ getInfoFromId()
local title="$2"
local cookieFile="$3"
#<p class="episode-stat-data total-downloads">Total listens: <b>109</b></p><p class="episode-stat-data total-listeners">Total listeners: <b>92</b></p><p class="episode-stat-data sources">Listening sources:</p><ul class="sources-list"><li class="itunes">iTunes: <b>7</b></li><li class="overcast">Overcast: <b>1</b></li><li class="direct">Direct download: <b>9</b></li><li class="new_window">Played in new window: <b>6</b></li><li class="player">Audio player: <b>23</b></li><li class="podcast_addict">Podcast Addict: <b>44</b></li><li class="playerfm">Player FM: <b>44</b></li><li class="unknown">Other: <b>63</b></li></ul><p><a href="https://cause-commune.fm/wp-admin/edit.php?post_type=podcast&page=podcast_stats&filter=episode&episode=10001">See more detail &raquo;</a><p></div>
# Get web page with info about one audio record.
local pageUrl="https://cause-commune.fm/wp-admin/post.php?post=$id&action=edit"
local pageFile="$tmpPrefix-pageid$id"
curl -s -b "$cookieFile" "$pageUrl" | grep "Total listens: " > "$pageFile"
local pageFile="${tmpPrefix}-pageid$id"
curl -s -b "$cookieFile" "$pageUrl" > "$pageFile"
line=$(<"$pageFile")
# Extract file infos.
local pageInfoFile="${tmpPrefix}-pageinfoid$id"
grep "Total listens: " "$pageFile" > "$pageInfoFile"
line=$(<"$pageInfoFile")
#echo "TRACE $line\n"
if [ -f "$pageFile" ]; then
rm -f "$pageFile"
fi
#<p class="episode-stat-data total-downloads">Total listens: <b>109</b></p><p class="episode-stat-data total-listeners">Total listeners: <b>92</b></p><p class="episode-stat-data sources">Listening sources:</p><ul class="sources-list"><li class="itunes">iTunes: <b>7</b></li><li class="overcast">Overcast: <b>1</b></li><li class="direct">Direct download: <b>9</b></li><li class="new_window">Played in new window: <b>6</b></li><li class="player">Audio player: <b>23</b></li><li class="podcast_addict">Podcast Addict: <b>44</b></li><li class="playerfm">Player FM: <b>44</b></li><li class="unknown">Other: <b>63</b></li></ul><p><a href="https://cause-commune.fm/wp-admin/edit.php?post_type=podcast&page=podcast_stats&filter=episode&episode=10001">See more detail &raquo;</a><p></div>
local totalListens=$(extractValue "$line" "Total listens")
local totalListeners=$(extractValue "$line" "Total listeners")
local iTunes=$(extractValue "$line" "iTunes")
@ -79,7 +78,22 @@ getInfoFromId()
local playerFM=$(extractValue "$line" "Player FM")
local other=$(extractValue "$line" "Other")
echo -e "$id\t$totalListens\t$totalListeners\t$iTunes\t$pocketCasts\t$overcast\t$directDownload\t$playedInNewWindow\t$audioPlayer\t$podcastAddict\t$playerFM\t$other\t$title"
# Extract record date.
local pageDateFile="${tmpPrefix}-pagedateid$id"
grep "<input name=\"date_recorded\"" "$pageFile" > "$pageDateFile"
line=$(<"$pageDateFile")
#echo "TRACE $line\n"
#<input name="date_recorded" id="date_recorded" type="hidden" value="19-03-2019">
local recordedDate
if [[ $line =~ value=\"(.+)\" ]]; then
recordedDate=${BASH_REMATCH[1]}
else
recordedDate=
fi
echo -e "$id\t$totalListens\t$totalListeners\t$iTunes\t$pocketCasts\t$overcast\t$directDownload\t$playedInNewWindow\t$audioPlayer\t$podcastAddict\t$playerFM\t$other\t$recordedDate\t$title"
}
# ############################################
@ -90,19 +104,19 @@ run()
# Connect.
local loginUrl="https://cause-commune.fm/wp-login.php"
local redirect="https%3A%2F%2Fcause-commune.fm%2Fwp-admin%2F"
local cookieFile="$tmpPrefix-cookies.txt"
local cookieFile="${tmpPrefix}-cookies.txt"
curl -s -c "$cookieFile" -d "log=$login&pwd=$pass&rememberme=forever&wp-submit=Se%20connecter&redirect_to=$redirect&testcookie=1" "$loginUrl" > /dev/null
# Get page "Les miens" data.
pageUrl="https://cause-commune.fm/wp-admin/edit.php?post_type=podcast&author=5"
idsFile="$tmpPrefix-listmiens"
idsFile="${tmpPrefix}-listmiens"
curl -s -b "$cookieFile" "$pageUrl" | grep row-title > "$idsFile"
# <strong><a class="row-title" href="https://cause-commune.fm/wp-admin/post.php?post=10518&amp;action=edit" aria-label="« Wikipédia &#8211; chronique « Partager est bon » sur écoles et logiciels libres » (Modifier)">Wikipédia &#8211; chronique « Partager est bon » sur écoles et logiciels libres</a></strong>
echo -e "id\ttotalListens\ttotalListeners\tiTunes\tpocketcasts\tovercast\tdirectDownload\tplayedInNewWindow\taudioPlayer\tpodcastAddict\tplayerFM\tother\ttitle"
echo -e "id\ttotalListens\ttotalListeners\tiTunes\tpocketcasts\tovercast\tdirectDownload\tplayedInNewWindow\taudioPlayer\tpodcastAddict\tplayerFM\tother\trecordedDate\ttitle"
while read line; do
#echo $line
@ -115,14 +129,6 @@ run()
getInfoFromId "$id" "$title" "$cookieFile"
done < "$idsFile"
if [ -f "$cookieFile" ]; then
rm -f "$cookieFile"
fi
if [ -f "$idsFile" ]; then
rm -f "$idsFile"
fi
}
# ###########################################
@ -138,4 +144,11 @@ else
pass="${pass//&/%26}"
run "$pass"
# Clean temporary files.
# Clean.
if [ -n "${tmpPrefix}" ]; then
ls "${tmpPrefix}-"*
rm -f "${tmpPrefix}-"*
fi
fi