TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Making our pageview data easily accessible

29 pointsby devhxincover 9 years ago

2 comments

flashmanover 9 years ago
&gt; <a href="http:&#x2F;&#x2F;top.hatnote.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;top.hatnote.com&#x2F;</a><p>Wow, it&#x27;s like a window into the zeitgeist.
dansoover 9 years ago
edit: Added the use of `date` to automatically return last 120 days of data, and crudely label the axes<p>edit: Here&#x27;s a gist <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;dannguyen&#x2F;f415b1797f686f995f8e" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;dannguyen&#x2F;f415b1797f686f995f8e</a><p>I thought there&#x27;s a Bash one-liner in there somewhere to read the API and convert it to a Google Static chart...but I haven&#x27;t had my full cup of coffee this morning. Also, my Bash-fu is weak, so here it is as a partially completed function...I&#x27;m sure someone here can turn it into a one-liner:<p>Given a user argument, such as &quot;Star_Wars&quot; [0], the JSON response is parsed with the jq tool [1], then wrangled into a series of comma-delimited values to be passed into Google Static Charts API [2]:<p>Resulting URL which is a timeseries of the past 120 days of daily pageviews for &quot;Star_Wars&quot;:<p><a href="https:&#x2F;&#x2F;chart.googleapis.com&#x2F;chart?chs=800x200&amp;cht=bvg&amp;chd=t:26867,21185,19318,18070,18024,20756,22056,18436,18098,17767,18672,21258,22884,24471,24350,19195,18220,18934,26076,27259,29547,27867,23664,19716,19332,19375,22766,25316,20725,19062,18836,18509,19057,21748,23147,18438,18824,17608,18556,19966,19937,22061,18896,18428,16753,14423,16903,29012,24012,17570,15676,15587,16551,19074,30278,36592,23440,19306,18325,18281,19491,28537,33151,41537,185853,111159,72979,61927,68754,57846,46054,38470,77358,104545,33733,41420,45332,37476,32674,34710,37770,43845,58388,59431,47990,44572,41607,39417,47977,46063,52561,40330,36673,35941,38812,44684,49243,58960,58053,50050,52144,61630,71900,72059,75722,64551,65993,63971,63492,70945,84578,98991,93108,86095,84668,87699,111377,142213,175058,202539&amp;chds=0,202539&amp;chbh=5,0,1&amp;chxt=x,y&amp;chxp=0,0&amp;chxl=0:|2015-08-17|2015-12-15|1:||101269|202539&amp;chtt=Last+120+days+of+pageviews+for+Wikipedia+page+on+Star_Wars" rel="nofollow">https:&#x2F;&#x2F;chart.googleapis.com&#x2F;chart?chs=800x200&amp;cht=bvg&amp;chd=t...</a><p>Here&#x27;s the bash function<p><pre><code> function chart_wpgviews(){ # first argument is article name # eh, too lazy to look up string comparison, so hardcoding the start and end date vals, # since it seems to be locked at a max of 4 months anyway...and hard-coding en.wikipedia PAGENAME=&quot;$1&quot; PROJECT=&quot;en.wikipedia&quot; ENDTIME=$(date +%s) STARTTIME=$(date --date=&quot;@$(($ENDTIME-120*24*60*60))&quot; +%s) # 120 days ago ENDDATE=$(date --date=&quot;@$ENDTIME&quot; +%Y-%m-%d) STARTDATE=$(date --date=&quot;@$STARTTIME&quot; +%Y-%m-%d) RESPONSE=$(curl -s https:&#x2F;&#x2F;wikimedia.org&#x2F;api&#x2F;rest_v1&#x2F;metrics&#x2F;pageviews&#x2F;per-article&#x2F;$PROJECT&#x2F;all-access&#x2F;user&#x2F;$PAGENAME&#x2F;daily&#x2F;$(tr -d &#x27;-&#x27; &lt;&lt;&lt; $STARTDATE)&#x2F;$(tr -d &#x27;-&#x27; &lt;&lt;&lt; $ENDDATE)) VALS=$(jq &#x27;.items[] | .views&#x27; &lt;&lt;&lt; $RESPONSE | tr &#x27;\n&#x27; &#x27;,&#x27;) MAXVAL=$(jq &#x27;.items[] | .views&#x27; &lt;&lt;&lt; $RESPONSE | sort -rn | head -n1) echo &quot;https:&#x2F;&#x2F;chart.googleapis.com&#x2F;chart?chs=800x200&amp;cht=bvg&amp;chd=t:${VALS%?}&amp;chds=0,$MAXVAL&amp;chbh=5,0,1&amp;chxt=x,y&amp;chxp=0,0&amp;chxl=0:|$STARTDATE|$ENDDATE|1:||$((MAXVAL&#x2F;2))|$MAXVAL&amp;chtt=Last+120+days+of+pageviews+for+Wikipedia+page+on+$PAGENAME&quot; } </code></pre> [0] <a href="https:&#x2F;&#x2F;wikimedia.org&#x2F;api&#x2F;rest_v1&#x2F;metrics&#x2F;pageviews&#x2F;per-article&#x2F;en.wikipedia&#x2F;all-access&#x2F;user&#x2F;Star_Wars&#x2F;daily&#x2F;20150101&#x2F;20151215" rel="nofollow">https:&#x2F;&#x2F;wikimedia.org&#x2F;api&#x2F;rest_v1&#x2F;metrics&#x2F;pageviews&#x2F;per-arti...</a><p>[1] <a href="https:&#x2F;&#x2F;stedolan.github.io&#x2F;jq&#x2F;" rel="nofollow">https:&#x2F;&#x2F;stedolan.github.io&#x2F;jq&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;chart&#x2F;image&#x2F;docs&#x2F;data_formats" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;chart&#x2F;image&#x2F;docs&#x2F;data_formats</a>