This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Convert seconds to human readable interval back and forth.""" | |
from collections import OrderedDict | |
import re | |
interval_dict = OrderedDict([("Y", 365*86400), # 1 year | |
("M", 30*86400), # 1 month | |
("W", 7*86400), # 1 week | |
("D", 86400), # 1 day | |
("h", 3600), # 1 hour | |
("m", 60), # 1 minute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sh | |
import logging | |
logging.basicConfig(level=logging.INFO, format="%(asctime)s;%(name)s;%(levelname)s;%(message)s") | |
from bakthat.helper import BakHelper | |
# Arguments for mongodump/restore command, leave empty if you want to backup your local mongo | |
# if you use authentication {"u": "user", "p": "password"} | |
MONGODUMP_PARAMS = {"u": "user", | |
"p": "password", | |
"oplog": True} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def _interval_string_to_seconds(interval_string): | |
"""Convert internal string like 1M, 1Y3M, 3W to seconds""" | |
interval_exc = "Bad interval format for {0}".format(interval_string) | |
interval_dict = {"s": 1, "m": 60, "h": 3600, "D": 86400, | |
"W": 7*86400, "M": 30*86400, "Y": 365*86400} | |
interval_regex = re.compile("^(?P<num>[0-9]+)(?P<ext>[smhDWMY])") | |
seconds = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
from __future__ import unicode_literals | |
import requests | |
from requests_oauthlib import OAuth1 | |
from urlparse import parse_qs | |
REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token" | |
AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize?oauth_token=" | |
ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import os | |
def get_conf(): | |
config_file = os.path.dirname(__file__) + "./config.yml" | |
if os.path.isfile(config_file): | |
with open(config_file, "r") as f: | |
return yaml.load(f) | |
return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
from datetime import date | |
def add_months(sourcedate,months): | |
month = sourcedate.month - 1 + months | |
year = sourcedate.year + month / 12 | |
month = month % 12 + 1 | |
day = min(sourcedate.day,calendar.monthrange(year,month)[1]) | |
return date(year,month,day) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imp | |
def load_class(full_class_string): | |
""" | |
Dynamically load a class from a string | |
>>> klass = load_class("module.submodule.ClassName") | |
>>> klass2 = load_class("myfile.Class2") | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var convert_bytes = function(bytes, force_unit) { | |
var return_val = ""; | |
$.each(['bytes','KB','MB','GB'], function(index, unit) { | |
if (force_unit == unit) { | |
new_size = Math.round(bytes*100)/100; | |
return [new_size, unit]; | |
} | |
if (bytes < 1024.0 && force_unit != "TB") { | |
return_val = [Math.round(bytes*100)/100, unit]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import tornado.escape | |
import tornado.ioloop | |
import tornado.websocket | |
import os.path | |
import uuid | |
#class MainHandler(tornado.web.RequestHandler): | |
# def get(self): | |
# self.render("index.html", messages=ChatSocketHandler.cache) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"date": "Jul-2011", "value": 9}, {"date": "Aug-2011", "value": 12}, {"date": "Sep-2011", "value": 12}, {"date": "Oct-2011", "value": 4}, {"date": "Nov-2011", "value": 5}, {"date": "Dec-2011", "value": 1}, {"date": "Jan-2012", "value": 11}, {"date": "Feb-2012", "value": 7}, {"date": "Mar-2012", "value": 7}, {"date": "Apr-2012", "value": 5}, {"date": "May-2012", "value": 7}, {"date": "Jun-2012", "value": 4}, {"date": "Jul-2012", "value": 6}, {"date": "Aug-2012", "value": 1}, {"date": "Sep-2012", "value": 7}, {"date": "Oct-2012", "value": 6}, {"date": "Nov-2012", "value": 6}] |