User:Lidia.Pereira/PNMII/WB/PCM

From XPUB & Lens-Based wiki

Procrastinatometer.png

Disclaimer: For now this is a local script, seeing that it works with the sqlite database which stores my browsing history. In the future I'll try developing a browser plug-in (using Grease Monkey, perhaps) that does the same without depending on some local file.

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sqlite3
import time

date = time.strftime("%x")
f = open("dates.txt","w")
m = open("dates.txt")
lines = m.readlines()

places = sqlite3.connect("/Users/lidiapereira/Library/Application Support/Firefox/Profiles/w3om15u2.default/places.sqlite")
database = places.cursor()

database.execute('''SELECT url FROM moz_places''')

if lines:
     for line in lines:
         if data not in line:
             for data in database:
                 database.execute('''DELETE FROM moz_places WHERE url=?''',(data))


url_list = ["https://www.youtube.com","https://www.facebook.com","http://www.reddit.com","http://vodly.to","http://www.lastfm.com"]

def getCount():
    i = 0
    for data in database:
        data = str(data)
        for url in url_list:
            if url in data:
                i = i + 1
    return i

count = getCount()

print "Content-Type: text/html"
print 
print """
    <!DOCTYPE html>
    <html>
    <head>
    <title>Procrastinatometer</title>
    <style>
        html{
        background: url('/procrastinatometer.png') no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        }
        img{
        min-height: 100%;
        min-width: 1024px;
        width: 100%;
        height: ;
        position: fixed;
        top: 1.3%;
        left: 0;
        }
    </style>
    </head>
    """
if count < 13:
    print """
    <body>
    <img src='/procrastimeter%s.png'/> """ % count
else:
    print """
    <body>
    <img src ='/count_dracula.gif'/> 
    """
    f.write(date+"\n")
    f.close()
print """
    </body>
    </html> """


Procrastinatometer2.png