Skip to content

Instantly share code, notes, and snippets.

@livibetter
Last active March 9, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save livibetter/2011993 to your computer and use it in GitHub Desktop.
Save livibetter/2011993 to your computer and use it in GitHub Desktop.
Scripts for Blogger posting charts

Scripts for Blogger posting charts

These scripts require a Blogger XML Export file, you can download your blog's export file at Settings » Other » Blog Tools » Export blog.

b.py

Usage:

./b.py blog-MM-DD-YYYY.xml [post|comment]

It gives you an output like:

$ ./b.py blog-05-10-2013.xml post
2008-09  18 ############
2008-10  25 #################
2008-11  57 ########################################
[snip]
2013-03  21 ##############
2013-04   7 ####
2013-05   1

Total: 1140 posts

You can read more about this script in my blog post.

b2.py

This script extracts published times from export file and converts them into Unix timestamp, it's for feeding other charting scripts.

bash-history-punchcard is a Python script.

Example commands and output image:

git clone https://gist.github.com/2011993.git b.py
git clone https://github.com/askedrelic/bash-history-punchcard.git bhp

cd b.py
./b2.py blog-05-10-2013.xml post > /tmp/posts.ts

cd ../bhp
git checkout 8a0a28959eb6bca8b55f0c5272b298aca10a18c4
./bashpunchard.py -c 696969,696969,696969,696969,696969,71bc78,ff91a4 -2 -i /tmp/posts.ts

Posts

The chart is display in local timezone. If the blog's timezone, say in PDT or PST, is different than local's, then

TZ=America/Los_Angeles ./bashpunchard.py -c 696969,696969,696969,696969,696969,71bc78,ff91a4 -2 -i /tmp/posts.ts

It should show in the blog's timezone.

You can read more about this script in Blogger posting punchcard.

punchcard.awk is a AWK script and generates punchcard chart in ASCII.

Example commands and output image:

git clone https://gist.github.com/2011993.git b.py
git clone https://gist.github.com/5733726.git punchcard.awk

cd b.py
./b2.py blog-05-10-2013.xml post | ../punchcard.awk/punchcard.awk
    +------------------------------------------------------------------------+
Mon | .  .  0  .  O  o  .  O  o  o  O  O  0  O  o  0  .  o  o  O  o  O  O  . |
Tue | .  O  O  .  o  .  O  O  o     O  O  o  .  .  .  .     .  o  .  .  0  o |
Wed | o  .  .     o  o  0  .  o  O  .  0  .  o  o  .  .  o  o  O  O  .  O  o |
Thu | .  o  .  .  .  o  o  o  o  .  o  .  O  .  o  O  o  .  O  O  .  o  o  o |
Fri | o  .  .  .  O  O  o  o  .  0  .  o  .  0  o  o  o  o  .  o  0  0  0    |
Sat | o  .  .  .  .  0  o  o  O  O  o  o  O  .  o  .  o  o  O  o  O  .  .  o |
Sun | o  .  o  .  .  o  o  O  O  O  .  o  o  .  .  .  .  .  O  o     .  o  . |
    +------------------------------------------------------------------------+
      0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

The chart is display in local timezone. If the blog's timezone, say in PDT or PST, is different than local's, then

./b2.py blog-05-10-2013.xml post | TZ=America/Los_Angeles ../punchcard.awk/punchcard.awk

It should show in the blog's timezone.

Related stuff

#!/usr/bin/env python
# ./b.py export.xml [<post|comment> [$(tput cols)]]
# Blog: https://yjlv.blogspot.com/2011/01/plotting-posting-and-commenting.html
# Gist: https://gist.github.com/livibetter/2011993
from pyquery import PyQuery as pq
import sys
kind = 'post' if len(sys.argv) < 3 else sys.argv[2]
width = (78 if len(sys.argv) < 4 else int(sys.argv[3])) - 12
with open(sys.argv[1]) as f:
b = pq(f.read().replace('feed xmlns=', 'feed xmlblahblahblah='), parser='xml')
entries = b('entry')
m_count = {}
for idx in range(len(entries)):
if entries.eq(idx)('category[scheme$=kind]').eq(0).attr('term').split('#')[1] != kind:
continue
month = entries.eq(idx)('published').text()[:7]
if month not in m_count:
m_count[month] = 0
m_count[month] += 1
m_count_keys = m_count.keys()
m_min = min(m_count_keys).split('-')
m_max = max(m_count_keys).split('-')
min_year, min_month = int(m_min[0]), int(m_min[1])
max_year, max_month = int(m_max[0]), int(m_max[1])
del m_count_keys, m_min, m_max
m_count_values = m_count.values()
max_count, min_count = max(m_count_values), min(m_count_values)
total_count = sum(m_count_values)
del m_count_values
for year in range(min_year, max_year+1):
for month in range(1, 12+1):
if year == min_year and month < min_month:
continue
if year == max_year and month > max_month:
break
key = '%d-%02d' % (year, month)
count = m_count[key] if key in m_count else 0
print '%s %3d %s' % (key, count, '#'*(width*count/max_count))
print
print 'Total: %4d %ss' % (total_count, kind)
#!/usr/bin/env python
# ./b2.py export.xml [<post|comment>
# Blog: https://yjlv.blogspot.com/2013/06/blogger-posting-punchcard.html
# Gist: https://gist.github.com/livibetter/2011993
from datetime import datetime, timedelta, tzinfo
from dateutil.parser import parse as dtp
from pyquery import PyQuery as pq
import sys
from lxml.cssselect import CSSSelector
# from http://docs.python.org/2/library/datetime.html#datetime.tzinfo.fromutc
ZERO = timedelta(0)
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO
uepoch = datetime.fromtimestamp(0, tz=UTC())
sel = CSSSelector('app|control app|draft', namespaces={'app': 'http://purl.org/atom/app#'})
kind = 'post' if len(sys.argv) < 3 else sys.argv[2]
with open(sys.argv[1]) as f:
b = pq(f.read().replace('feed xmlns=', 'feed xmlblahblahblah='), parser='xml')
entries = b('entry')
for idx in range(len(entries)):
entry = entries.eq(idx)
if entry('category[scheme$=kind]').eq(0).attr('term').split('#')[1] != kind:
continue
app_draft = sel(entry[0])
if app_draft and app_draft[0].text == 'yes':
continue
print int((dtp(entries.eq(idx)('published').text()) - uepoch).total_seconds())
@livibetter
Copy link
Author

livibetter commented Mar 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment