What's on my mind

Group By Date in mongodb

I am using mongodb for tracking my website. I am saving date and time with ISODate , "time" : ISODate("2014-05-18T13:23:04.227Z") .

So, I wrote like that.

    "$project": {
        "y": {
            "$year": "$time"
        "m": {
            "$month": "$time"
        "d": {
            "$dayOfMonth": "$time"
    "$group": {
        "_id": {
            "year": "$y",
            "month": "$m",
            "day": "$d"
        count: {
            "$sum": 1
    $sort: {
        "_id.year": 1,
        "_id.month": 1,
        "": 1

First , need to separate the year , month and date. After that , make a group and then sort it.

File Sorting in Python

I want to get sorted file array with python.

I have a array like following

  • Testing1.txt
  • Testing2.txt
  • Testing3.txt
  • Testing10.txt
  • Testing11.txt
  • Testing20.txt
  • Testing30.txt

When I use subDir = os.listdir(dirname) , it didn’t sort.

It will return like following order

  • Testing1.txt
  • Testin10.txt
  • Testin11.txt
  • Testing 2.txt
  • Testing 20.txt
  • Testing 3.txt
  • Testing 30.txt

We need to use sorted function to sort and we need to tell between Testing and .txt is a integer value.

Here is my code

[gist id=”3848050”]

Worpdress to Tumblr

If you are using wordpress , you can export easily to Tumblr.

First , download the wordpress export file. Tools > Export in wordpress dashboard.


You will receive the xml file after downloading.

You need to install python to use wordpress to tumblr script. If you are using Linux or Mac, python already support in OS and no need to install.

Download the script from wp2tumblr.

After unzip, you will see file. Open the terminal and go to the directory of

[gist id=”3616374”]
Tumblr only allow 100 posts per day. If you have more than 100 posts , you can start this script again and change the -s . So, don’t forget about the latest export number. If you forget , you need to start from 0 again at next day.